aboutsummaryrefslogtreecommitdiffstats
path: root/lo.js
diff options
context:
space:
mode:
Diffstat (limited to 'lo.js')
-rw-r--r--lo.js51
1 files changed, 37 insertions, 14 deletions
diff --git a/lo.js b/lo.js
index 0c382a8..b98513a 100644
--- a/lo.js
+++ b/lo.js
@@ -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)]];
}
}