diff options
author | anekos | 2008-09-10 17:35:28 +0000 |
---|---|---|
committer | anekos | 2008-09-10 17:35:28 +0000 |
commit | 0f5935645b5729d0adf4138961843e1fd7811bed (patch) | |
tree | b951956e9c491cd0dda6edcacec5150a554962b3 /auto_detect_link.js | |
parent | 29059896232afabe1d3b1c0bac8f957f56c39fe7 (diff) | |
download | vimperator-plugins-0f5935645b5729d0adf4138961843e1fd7811bed.tar.bz2 |
AutoPagerizeのキャッシュを利用できるようにした。
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@19147 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'auto_detect_link.js')
-rw-r--r-- | auto_detect_link.js | 64 |
1 files changed, 61 insertions, 3 deletions
diff --git a/auto_detect_link.js b/auto_detect_link.js index 98e70e3..56934ca 100644 --- a/auto_detect_link.js +++ b/auto_detect_link.js @@ -2,7 +2,7 @@ // @name Auto Detect Link // @description-ja (次|前)っぽいページへのリンクを探してジャンプ // @license Creative Commons 2.1 (Attribution + Share Alike) -// @version 1.0.2 +// @version 1.1.0 // ==/VimperatorPlugin== // // Usage: @@ -33,6 +33,9 @@ // doc_a.html => doc_b.html // force: // (次|前)っぽいURIを捏造してそこに移動します。 +// useAutoPagerize: +// AutoPagerize のキャッシュを利用します。 +// (ただし、"次" へのリンクにしか使われません) // // example: // :js liberator.globalVariables.autoDetectLink = {nextPatterns: [/next/, /次/]} @@ -92,6 +95,7 @@ useBackHistory: false, //clickButton: true, force: false, + useAutoPagerize: true, } //////////////////////////////////////////////////////////////// @@ -119,6 +123,14 @@ return _gv; } + const APPREF = 'greasemonkey.scriptvals.http://swdyh.yu.to//AutoPagerize.cacheInfo'; + let ap_cache = eval(Application.prefs.getValue(APPREF, null)); + + for each (let cache in ap_cache) { + cache.info = cache.info.filter(function(i) { return ('url' in i) }) + cache.info.sort(function(a, b) { return (b.url.length - a.url.length) }) + } + //////////////////////////////////////////////////////////////// // functions @@ -147,7 +159,7 @@ // 開いたURIなどの表示 function displayOpened (link) { - let msg = 'open <' + link.text + '> ' + link.uri; + let msg = 'open: ' + link.type + ' <' + link.text + '> ' + link.uri; setTimeout(function () liberator.echo(msg), 1000); liberator.log(msg); } @@ -309,6 +321,37 @@ } + // 相対アドレスから絶対アドレスに変換するんじゃないの? + function toAbsPath (path) { + with (content.document.createElement('a')) + return (href = path) && href; + } + + // AutoPagerize のデータからマッチする物を取得 + function getAutopagerizeNext () { + if (!ap_cache) + return; + + let info = (function () { + let uri = buffer.URL; + for each (let cache in ap_cache) { + for each (let info in cache.info) { + if (uri.match(info.url)) + return info; + } + } + })(); + + if (!info) + return; + + let doc = content.document; + let result = doc.evaluate(info.nextLink, doc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); + if (result.singleNodeValue) + return result.singleNodeValue; + } + + //////////////////////////////////////////////////////////////// // main //////////////////////////////////////////////////////////////// @@ -318,6 +361,20 @@ try { setting = getCurrentSetting(setting); + // TODO + if (setting.useAutoPagerize) { + let apnext = getAutopagerizeNext(); + if (apnext) { + return { + type: 'aplink', + frame: content, + uri: apnext.href || apnext.action || apnext.value, + text: apnext.textContent, + element: apnext + }; + } + } + patterns = next ? setting.nextPatterns : setting.backPatterns; let uri = window.content.location.href; @@ -345,8 +402,9 @@ // force if (setting.force && succs.length) return { + type: 'force', uri: succs[0], - text: '!force!', + text: '-force-', frame: window.content, }; |