diff options
author | anekos | 2008-10-06 22:43:44 +0000 |
---|---|---|
committer | anekos | 2008-10-06 22:43:44 +0000 |
commit | 8c257d69c31a8a6034a459ab19e8b8f19c0e066b (patch) | |
tree | af810a7a97a583308a2e58a4fe3d35e92c0eea2a | |
parent | d9a6874c67f49c10cbc4a5c4b4f7843c4dbcc994 (diff) | |
download | vimperator-plugins-8c257d69c31a8a6034a459ab19e8b8f19c0e066b.tar.bz2 |
・どこに開くかを指定できるようにした
・lopen の仕様をちょっと変更
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@20875 d0d07461-0603-4401-acd4-de1884942a52
-rw-r--r-- | lo.js | 51 |
1 files changed, 37 insertions, 14 deletions
@@ -3,22 +3,23 @@ // @description Open filtered link(s). // @description-ja リンクをフィルタリングして開く // @license Creative Commons 2.1 (Attribution + Share Alike) -// @version 1.0 +// @version 1.1 // ==/VimperatorPlugin== // // Usage: -// :fopen <REGEXP> [-i <INTERVAL_SEC>] +// :fo[pen][!] <REGEXP> [-i <INTERVAL_SEC>] // Open filtered links by regexp. +// When used "!", open links in foreground. // -// :lo[pen] URI +// :lo[pen][!] URI // Open URI // // Usage-ja: -// :fo[pen] <ミゲ文字列> [-i <INTERVAL_SEC>] -// :fo[pen] /<正規表現> [-i <INTERVAL_SEC>] +// :fo[pen][!] <ミゲ文字列> [-i <INTERVAL_SEC>] +// :fo[pen][!] /<正規表現> [-i <INTERVAL_SEC>] // ミゲ文字列か正規表現でフィルタされたリンクを開く // -// :lo[pen] URI +// :lo[pen][!] URI // URI を開く // // ちなみに Migemo はなくても動きます。 @@ -26,6 +27,9 @@ // // Variables: // let g:fopen_default_interval="<INTERVAL_SEC>" +// +// Notice: +// "--where" option's implementation has not been completed yet. (function () { try{ @@ -57,22 +61,34 @@ return [it for each (it in content.document.links) if (lmatch(re, it))]; } + function charToWhere (str, fail) { + const table = { + f: NEW_TAB, + t: NEW_TAB, + b: NEW_BACKGROUND_TAB, + c: CURRENT_TAB, + w: NEW_WINDOW, + }; + return (str && table[str.charAt(0).toLowerCase()]) || fail; + } + let foihandle; liberator.commands.addUserCommand( ['fo[pen]', 'filteropen'], 'Filtered open', - function (opts) { + function (opts, bang) { + let where = charToWhere(opts['-where'], bang ? NEW_TAB : NEW_BACKGROUND_TAB); let [i, links] = [1, filteredLinks(opts.arguments.join(''))]; if (!links.length) return; - open(links[0].href, NEW_BACKGROUND_TAB); + open(links[0].href, where); if (links.length <= 1) return; let interval = (opts['-interval'] || liberator.globalVariables.fopen_default_interval || 1) * 1000; foihandle = setInterval(function () { try { - open(links[i].href, NEW_BACKGROUND_TAB); + open(links[i].href, where); if ((++i) >= links.length) clearInterval(foihandle); } catch (e) { @@ -83,6 +99,7 @@ { options: [ [['-interval', '-i'], liberator.commands.OPTIONS_INT], + [['-where', '-w'], liberator.commands.OPTIONS_STRING], ], completer: function (word) { let links = filteredLinks(word); @@ -92,7 +109,7 @@ ); liberator.commands.addUserCommand( - ['stopfilteropen'], + ['stopfilteropen', 'stopfo[pen]'], 'Stop filtered open', function () { clearInterval(foihandle); @@ -100,24 +117,30 @@ ); let lolinks = []; + let looptions = [ [['-where', '-w'], liberator.commands.OPTIONS_STRING], ]; liberator.commands.addUserCommand( ['lo[pen]', 'linkopen'], 'Filtered open', - function (uri) { + function (opts, bang) { + let where = charToWhere(opts['-where'], bang ? NEW_TAB : CURRENT_TAB); + let uri = opts.arguments[0]; for each (let link in lolinks) { if (~link.href.indexOf(uri)) - return liberator.buffer.followLink(link); + return liberator.buffer.followLink(link, where); } if (lolinks[0]) { - liberator.buffer.followLink(lolinks[0]); + liberator.buffer.followLink(lolinks[0], where); } else { liberator.echoerr('lol') } }, { + options: looptions; completer: function (word) { - lolinks = filteredLinks(word); + let opts = liberator.parseArgs(word, looptions, "1", true); + log(opts); + lolinks = filteredLinks(word);//word.match(/\bhttp[^\s]+/)); return [0, [[it.href, it.textContent] for each (it in lolinks)]]; } } |