diff options
author | anekos | 2008-10-06 23:07:06 +0000 |
---|---|---|
committer | anekos | 2008-10-06 23:07:06 +0000 |
commit | 8bf630de4882e8ac26b008b0a5baed2601752558 (patch) | |
tree | 0efc73972b1bee0399680271511d9295348b1c1f /lo.js | |
parent | 9ee8a5766461d55ac5bf3aa26ebf6bf12896d9a3 (diff) | |
download | vimperator-plugins-8bf630de4882e8ac26b008b0a5baed2601752558.tar.bz2 |
修正
・どこに開くかを指定できるようにした
・lopen の仕様をちょっと変更
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@20878 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'lo.js')
-rw-r--r-- | lo.js | 171 |
1 files changed, 86 insertions, 85 deletions
@@ -7,19 +7,19 @@ // ==/VimperatorPlugin== // // Usage: -// :fo[pen][!] <REGEXP> [-i <INTERVAL_SEC>] +// :fo[pen][!] <REGEXP> [-i <INTERVAL_SEC>] [-w <WHERE>] // Open filtered links by regexp. // When used "!", open links in foreground. // -// :lo[pen][!] URI +// :lo[pen][!] URI [-w <WHERE>] // Open URI // // Usage-ja: -// :fo[pen][!] <ミゲ文字列> [-i <INTERVAL_SEC>] -// :fo[pen][!] /<正規表現> [-i <INTERVAL_SEC>] +// :fo[pen][!] <ミゲ文字列> [-i <INTERVAL_SEC>] [-w <WHERE>] +// :fo[pen][!] /<正規表現> [-i <INTERVAL_SEC>] [-w <WHERE>] // ミゲ文字列か正規表現でフィルタされたリンクを開く // -// :lo[pen][!] URI +// :lo[pen][!] URI [-w <WHERE>] // URI を開く // // ちなみに Migemo はなくても動きます。 @@ -27,9 +27,7 @@ // // Variables: // let g:fopen_default_interval="<INTERVAL_SEC>" -// -// Notice: -// "--where" option's implementation has not been completed yet. + (function () { try{ @@ -45,25 +43,23 @@ } function makeRegExp (str) { - if (!migemo) - return new RegExp(str, 'i'); - if (str.indexOf('/') == 0) - return new RegExp(str.slice(1), 'i'); - else - return migemo.getRegExp(str); + return migemo ? (str.indexOf('/') == 0) ? new RegExp(str.slice(1), 'i') + : migemo.getRegExp(str) + : new RegExp(str, 'i'); } function filteredLinks (word) { if (word.match(/^\s*$/)) - return []; // [it for each (it in content.document.links) if (it.href)]; + return []; let re = makeRegExp(word); - return [it for each (it in content.document.links) if (lmatch(re, it))]; + 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, + n: NEW_TAB, b: NEW_BACKGROUND_TAB, c: CURRENT_TAB, w: NEW_WINDOW, @@ -71,79 +67,84 @@ return (str && table[str.charAt(0).toLowerCase()]) || fail; } - let foihandle; - - liberator.commands.addUserCommand( - ['fo[pen]', 'filteropen'], - 'Filtered open', - 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, 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, where); - if ((++i) >= links.length) + const WHERE_COMPLETIONS = ['f', 't', 'n', 'b', 'c', 'w']; + + + let (foihandle) { + + liberator.commands.addUserCommand( + ['fo[pen]', 'filteropen'], + 'Filtered open', + 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, 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, where); + if ((++i) >= links.length) + clearInterval(foihandle); + } catch (e) { clearInterval(foihandle); - } catch (e) { - clearInterval(foihandle); - } - }, interval); - }, - { - options: [ - [['-interval', '-i'], liberator.commands.OPTIONS_INT], - [['-where', '-w'], liberator.commands.OPTIONS_STRING], - ], - completer: function (word) { - let links = filteredLinks(word); - return [0, [[it.href, it.textContent] for each (it in links)]]; + } + }, interval); + }, + { + bang: true, + options: [ + [['-interval', '-i'], liberator.commands.OPTION_INT], + [['-where', '-w'], liberator.commands.OPTION_STRING], + ], + completer: function (word) { + let links = filteredLinks(word); + return [0, [[it.href, it.textContent] for each (it in links)]]; + }, } - } - ); - - liberator.commands.addUserCommand( - ['stopfilteropen', 'stopfo[pen]'], - 'Stop filtered open', - function () { - clearInterval(foihandle); - } - ); - - let lolinks = []; - let looptions = [ [['-where', '-w'], liberator.commands.OPTIONS_STRING], ]; - - liberator.commands.addUserCommand( - ['lo[pen]', 'linkopen'], - 'Filtered open', - 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, where); - } - if (lolinks[0]) { - liberator.buffer.followLink(lolinks[0], where); - } else { - liberator.echoerr('lol'); + ); + + liberator.commands.addUserCommand( + ['stopfilteropen', 'stopfo[pen]'], + 'Stop filtered open', + function () { + clearInterval(foihandle); } - }, - { - options: looptions, - completer: function (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)]]; + ); + + } + + let ( + lolinks = [], + looptions = [ [['-where', '-w'], liberator.commands.OPTION_STRING, null, WHERE_COMPLETIONS] ] + ) { + + liberator.commands.addUserCommand( + ['lo[pen]', 'linkopen'], + 'Filtered open', + function (opts, bang) { + let where = charToWhere(opts['-where'], bang ? NEW_TAB : CURRENT_TAB); + let arg = opts.arguments[0]; + let m = arg.match(/^(\d+),/); + if (m) + liberator.buffer.followLink(lolinks[parseInt(m[1], 10)], where); + }, + { + options: looptions, + bang: true, + completer: function (word) { + if (!word || word.match(/\d+,|\s/)) + return []; + lolinks = filteredLinks(word); + return [0, [[i + ',' + lolinks[i].href, lolinks[i].textContent] for (i in lolinks || [])]]; + } } - } - ); + ); + + } }catch(e){log(e);}})(); |