var PLUGIN_INFO =
Auto Detect Link
Find (next|previous) link, and jump.
(次|前)っぽいページへのリンクを探してジャンプ
1.8.3
anekos
2.0pre
https://github.com/vimpr/vimperator-plugins/raw/master/auto_detect_link.js
Creative Commons Attribution-Share Alike 3.0 Unported
//
doc_03.html
- doc_a.html => doc_b.html
force:
(次|前)っぽいURIを捏造してそこに移動します。
useAutoPagerize:
AutoPagerize のキャッシュを利用します。
(ただし、"次" へのリンクにしか使われません)
=== example ===
>||
:js liberator.globalVariables.autoDetectLink = {nextPatterns: [/next/, /次/]}
||<
== Function ==
外部から呼び出せる関数が liberator.plugins.autoDetectLink に入っています。
=== detect(next, setting) ===
(次|前)へのリンクを検出する。
==== 引数 ====
next:
次のリンクを探すときは、true。
setting:
設定を一時的に上書きする。省略可。
==== 返値 ====
リンクのURIなど以下のプロパティを持つオブジェクト
uri:
アドレス。
text:
リンクテキストなど
frame:
リンクの存在するフレームの Window オブジェクト
element:
リンクの要素
=== autoDetectLink.go(next, setting) ===
(次|前)へのリンクに移動。
引数は detect と同じ。
=== example ===
履歴を使用しないで、前のリンクを探す。:
>||
liberator.plugins.autoDetectLink.detect(false, {useBackHistory: false});
||<
]]>
;
(function () {
liberator.log('auto_detect_link.js loading');
////////////////////////////////////////////////////////////////
// default setting
////////////////////////////////////////////////////////////////
let defaultSetting = {
nextPatterns: [
//[NnNn][EeEe][XxXx][TtTt]/,
/[Nn\uff2e\uff4e][Ee\uff25\uff45][Xx\uff38\uff58][Tt\uff34\uff54]/,
//[FfFf](?:[OoOo][RrRr])?[WwWw](?:[AaAa][RrRr])?[DdDd]/,
/[Ff\uff26\uff46](?:[Oo\uff2f\uff4f][Rr\uff32\uff52])?[Ww\uff37\uff57](?:[Aa\uff21\uff41][Rr\uff32\uff52])?[Dd\uff24\uff44]/,
//^\s*(?:次|つぎ)[への]/, /つづく|続/, /次|つぎ/, /進む/,
/^\s*(?:\u6b21|\u3064\u304e)[\u3078\u306e]/, /\u3064\u3065\u304f|\u7d9a/, /\u6b21|\u3064\u304e/, /\u9032\u3080/,
//^\s*>\s*$/, />+|≫/
/^\s*>\s*$/, />+|\u226b/
],
backPatterns: [
//[BbBb][AaAa][CcCc][KkKk]/, /[PpPp][RrRr][EeEe][VvVv]/,
/[Bb\uff22\uff42][Aa\uff21\uff41][Cc\uff23\uff43][Kk\uff2b\uff4b]/, /[Pp\uff30\uff50][Rr\uff32\uff52][Ee\uff25\uff45][Vv\uff36\uff56]/,
//^\s*前[への]/, /前/, /戻る/,
/^\s*\u524d[\u3078\u306e]/, /\u524d/, /\u623b\u308b/,
//^\s*<\s*$/, /<+|≪/
/^\s*<\s*$/, /<+|\u226a/
],
nextMappings: [']]'],
backMappings: ['[['],
useSuccPattern: true,
useNextHistory: false,
useBackHistory: false,
//clickButton: true,
force: false,
useAutoPagerize: true,
displayDelay: 500,
ignoreId: false
};
////////////////////////////////////////////////////////////////
// setting
////////////////////////////////////////////////////////////////
let _gv;
// 評価を遅延するために関数にしておく
function gv () {
if (_gv)
return _gv;
if (liberator.globalVariables) {
if (!liberator.globalVariables.autoDetectLink)
liberator.globalVariables.autoDetectLink = {};
_gv = liberator.globalVariables.autoDetectLink;
}
for (let key in defaultSetting) {
if (_gv[key] == undefined)
_gv[key] = defaultSetting[key];
}
return _gv;
}
const APPREF = 'greasemonkey.scriptvals.http://swdyh.yu.to//AutoPagerize.cacheInfo';
let ap_cache;
try {
ap_cache = eval(Application.prefs.getValue(APPREF, null));
for each (let cache in ap_cache) {
cache.info = cache.info.filter(function (i) 'url' in i);
cache.info.sort(function (a, b) b.url.length - a.url.length);
}
} catch (e) {
liberator.log('ap_cache evaluationg error. no autopagerize?: \n' + e);
}
////////////////////////////////////////////////////////////////
// functions
////////////////////////////////////////////////////////////////
// 空白を
function removeSpace (str)
str.replace(/^\s+|\s+$/g, '').replace(/\s+/g, ' ');
// Array#find
function find (ary, f) {
var func = (typeof f == 'function') ? f : function (v) v == f;
for (let i = 0, l = ary.length; i < l; i++) {
if (func(ary[i])) {
return ary[i];
}
}
return null;
}
// 要素をクリックする
function clickElement (elem)
buffer.followLink(elem, liberator.CURRENT_TAB);
// 開いたURIなどの表示
function displayOpened (link) {
var msg = 'open: ' + link.type + ' <' + removeSpace(link.text) + '> ' + link.uri;
setTimeout(function () liberator.echo(msg, commandline.FORCE_SINGLELINE), gv().displayDelay);
}
// リンクを開く
function open (link) {
if (link.element) {
clickElement(link.element);
} else if (link.uri) {
link.frame.location.href = link.uri;
}
displayOpened(link);
}
// 元の文字列、詰め込む文字、長さ
function padChar (s, c, n)
s.replace(new RegExp('^(.{0,'+(n-1)+'})$'), function (s) padChar(c+s, c, n));
// ID っぽい文字か考えてみる!
// 数字だけで長いのは ID っぽい!
// 西暦っぽいのは無視しない方が良いかも。
// 根拠はないが、1980-2029 の範囲で。
// 後方00 が含まれているパターンは、インクリメントしてもいい気がする
// 830000 => 830001
// XXX 根拠があやしぎる!
function likeID (s)
/^\d{6,}$/.test(s) && !/^(19[89]|20[012])\d/.test(s) && !/00\d\d$/.test(s);
// (次|前)の数字文字列リストを取得
function succNumber (n, next, ignoreId) {
if (ignoreId && likeID(n))
return [];
var m = (parseInt(n || 0, 10) + (next ? 1 : -1)).toString();
var result = [m];
if (m.length < n.length)
result.unshift(padChar(m.toString(), '0', n.length));
return result;
}
// (次|前)の文字列リストを取得
function succString (s, next) {
var result = [], d = next ? 1
var PLUGIN_INFO =
<VimperatorPlugin>
<name>UserAgentSwitcherLite</name>
<description>switch user agent</description>
<description lang='ja'>user agent 切り替え</description>
<version>0.1.1</version>
<author homepage='http://d.hatena.ne.jp/pekepekesamurai/'>pekepeke</author>
<updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/uaSwitchLite</updateURL>
<minVersion>2.0pre</minVersion>
<maxVersion>2.0pre</maxVersion>
<detail lang='ja'><![CDATA[
== Commands ==
:ua [uaname]:
User Agent を切り替えます。
:ua:
User Agent を表示します。
== .vimperatorrrc ==
>||
javascript <<EOM
liberator.globalVariables.useragent_list = [
{
description: 'Internet Explorer 7 (Windows Vista)',
useragent: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)',
appname: 'Microsoft Internet Explorer',
appversion: '4.0 (compatible; MSIE 7.0; Windows NT 6.0)',
platform: 'Win32',
}, {
description: 'Netscape 4.8 (Windows Vista)',
useragent: 'Mozilla/4.8 [en] (Windows NT 6.0; U)',
appname: 'Netscape',
appversion: '4.8 [en] (Windows NT 6.0; U)',
platform: 'Win32',
}, {
description: 'Google',
useragent: 'Googlebot/2.1 (+http://www.google.com/bot.html)',
}];
EOM
||<
]]></detail>
</VimperatorPlugin>;
liberator.plugins.UserAgentSwitcherLite = (function(){
const USER_AGENT = 'general.useragent.override';
const APP_NAME = 'general.appname.override';
const APP_VERSION = 'general.appversion.override';
const PLATFORM = 'general.platform.override';
const VENDOR = 'general.useragent.vendor';
const VENDOR_SUB = 'general.useragent.vendorSub';
const DEFAULT = 'Default';
var global = liberator.globalVariables;
global.useragent_list = global.useragent_list ? global.useragent_list : [
{
description: 'Internet Explorer 7 (Windows Vista)',
useragent: 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)',
appname: 'Microsoft Internet Explorer',
appversion: '4.0 (compatible; MSIE 7.0; Windows NT 6.0)',
platform: 'Win32',
vendor: '',
vendorSub: ''
}, {
description: 'Netscape 4.8 (Windows Vista)',
useragent: 'Mozilla/4.8 [en] (Windows NT 6.0; U)',
appname: 'Netscape',
appversion: '4.8 [en] (Windows NT 6.0; U)',
platform: 'Win32',
vendor: '',
vendorSub: ''
}, {
description: 'Opera 9.25 (Windows Vista)',
useragent: 'Opera/9.25 (Windows NT 6.0; U; en)',
appname: 'Opera',
appversion: '9.25 (Windows NT 6.0; U; en)',
platform: 'Win32',
}
];
var Class = function() function(){ this.initialize.apply(this, arguments); };
var UASwitcherLite = new Class();
UASwitcherLite.prototype = {
initialize: function(){
// init
this.completer = [];
this.switcher = {
__noSuchMethod__: function(arg) liberator.echoerr('cannot switch user agent "'+arg+'"'),
'': function(){
var ua = options.getPref(USER_AGENT);
liberator.echo('Current User Agent : ' + (ua ? ua : DEFAULT) );
}
};
var self = this;
// default values
this.completer.push([DEFAULT, '']);
this.switcher[DEFAULT] = function() self.switch();
// expand setting
global.useragent_list.forEach( function(item){
var desc = item.description;
var userAgent = item.useragent;
var appName = item.appname;
var appVersion = item.appversion;
var platform = item.platform;
var vendor = item.vendor;
var vendorSub = item.vendorSub;
self.completer.push([desc, userAgent]);
self.switcher[desc] = function() self.switch(appName, appVersion, platform, userAgent, vendor, vendorSub);
});
this.registerCommand();
},
switch: function(appName, appVersion, platform, userAgent, vendor, vendorSub){
if (!userAgent && !options.getPref(USER_AGENT)) return;
var setter = userAgent ? options.setPref : options.resetPref;
setter(APP_NAME, decodeURIComponent(appName || ''));
setter(APP_VERSION, decodeURIComponent(appVersion || ''));
setter(PLATFORM, decodeURIComponent(platform || ''));
setter(USER_AGENT, decodeURIComponent(userAgent || ''));
setter(VENDOR, decodeURIComponent(vendor || ''));
setter(VENDOR_SUB, decodeURIComponent(vendorSub || ''));
},
registerCommand: function(){
var self = this;
commands.addUserCommand(['ua'], 'Switch User Agent',
function(arg)
self.switcher[ (arg.string || arg+'').replace(/\\+/g,'') ](),
{
completer: function(context, args){
var filter = context.filter;
context.title = ['Description', 'User Agent'];
if (!filter) {
context.completions = self.completer;
return;
}
filter = filter.toLowerCase();
context.completions = self.completer.filter( function(el) el[0].toLowerCase().indexOf(filter) == 0 );
}
} );
}
};
return new UASwitcherLite();
})();