aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoranekos2008-11-23 00:35:01 +0000
committeranekos2008-11-23 00:35:01 +0000
commit00b1f584a13c4cae8b0b84b6e3ffc67f7b9d037b (patch)
tree0030344502fe3b267f13964659ad43160629ae9a
parentc9148677771aa64b1169866b9631a2b5946ca79e (diff)
downloadvimperator-plugins-00b1f584a13c4cae8b0b84b6e3ffc67f7b9d037b.tar.bz2
follow the new completer.
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@24676 d0d07461-0603-4401-acd4-de1884942a52
-rw-r--r--command_menu.js14
-rw-r--r--every.js36
-rw-r--r--fetchyoutube.js4
-rw-r--r--googlekanji.js16
-rw-r--r--lo.js59
-rw-r--r--multi_requester.js13
-rw-r--r--nico_related_videos.js11
-rw-r--r--readcatlater.js32
-rw-r--r--umihara.js11
9 files changed, 117 insertions, 79 deletions
diff --git a/command_menu.js b/command_menu.js
index 4cabb55..8f72850 100644
--- a/command_menu.js
+++ b/command_menu.js
@@ -146,21 +146,19 @@
commands.addUserCommand(
cmds,
name,
- function (args, _, num, extra) {
- // for HEAD (2)
- if (args.string != undefined)
- args = args.string;
- var res = _find(args.replace(/-\s*$/,''), true);
+ function (arg) {
+ var res = _find(arg.string.replace(/-\s*$/,''), true);
if (!(res && action(res)))
liberator.echoerr('menu not found');
},
{
- completer: function (args) {
+ completer: function (context, arg, bang) {
const gps = function (it) getPathString(it, equal(root), getElementName, isClickable);
const fp = function (it) [gps(it), it.tooltipText || ''];
- return [0, _find(args).map(fp)];
+ return [0, _find(context.filter).map(fp)];
}
- }
+ },
+ true
);
}
diff --git a/every.js b/every.js
index 411b125..05c5762 100644
--- a/every.js
+++ b/every.js
@@ -3,7 +3,7 @@
// @description to run a specified command every time at specified interval.
// @description-ja 指定のコマンドを指定の間隔で実行する。
// @license Creative Commons 2.1 (Attribution + Share Alike)
-// @version 1.0
+// @version 1.1
// @author anekos (anekos@snca.net)
// ==/VimperatorPlugin==
//
@@ -40,14 +40,19 @@
(function () {
- let ps = [];
+ let every = liberator.plugins.every;
+ if (every) {
+ kill('*');
+ } else {
+ liberator.plugins.every = every = {ps: []};
+ }
function run (command, interval) {
let fun = function () {
if (liberator.mode != liberator.modules.modes.COMMAND_LINE)
liberator.execute(command);
};
- ps.push({
+ every.ps.push({
handle: setInterval(fun, interval),
command: command
});
@@ -55,14 +60,14 @@
function kill (index) {
if (index == '*') {
- ps.forEach(function (process) clearInterval(process.handle));
- liberator.echo(ps.length + ' processes were killed!');
- ps = [];
+ every.ps.forEach(function (process) clearInterval(process.handle));
+ liberator.echo(every.ps.length + ' processes were killed!');
+ every.ps = [];
} else {
- let process = ps[index];
+ let process = every.ps[index];
if (process) {
clearInterval(process.handle);
- ps.splice(index, index);
+ every.ps.splice(index, index);
liberator.echo('process "' + process.command + '" was killed!');
} else {
liberator.echoerr('unknown process');
@@ -88,11 +93,16 @@
count: true,
bang: true,
argCount: '+',
- completer: function (str, bang) {
- return bang ? [0, [['*', 'kill em all']].concat(ps.map(function (p, i) ([i, p.command])))]
- : liberator.modules.completion.ex(str);
+ completer: function (context, arg, bang) {
+ if (bang) {
+ context.title = ['PID', 'every process'];
+ context.items = [['*', 'kill em all']].concat(every.ps.map(function (p, i) ([i.toString(), p.command])));
+ } else {
+ liberator.modules.completion.ex(context);
+ }
}
- }
+ },
+ true
);
@@ -113,7 +123,7 @@
{
count: true,
argCount: '+',
- completer: liberator.modules.completion.ex
+ completer: function (context) liberator.modules.completion.ex(context)
}
);
diff --git a/fetchyoutube.js b/fetchyoutube.js
index 5e1b699..9b5916e 100644
--- a/fetchyoutube.js
+++ b/fetchyoutube.js
@@ -4,7 +4,7 @@
// @license Creative Commons 2.1 (Attribution + Share Alike)
// @version 1.0
// @author anekos (anekos@snca.net)
-// @minVersion 1.2
+// @minVersion 2.0pre
// @maxVersion 2.0pre
// ==/VimperatorPlugin==
//
@@ -72,7 +72,7 @@
['fetchyoutube', 'fetchyt'],
'fecth YouTube HD video',
fetch,
- {argCount: '*', completer: function (arg) completion.file(arg)},
+ {argCount: '*', completer: function (context) completion.file(context)},
true
);
diff --git a/googlekanji.js b/googlekanji.js
index c5acc26..481c7d6 100644
--- a/googlekanji.js
+++ b/googlekanji.js
@@ -2,7 +2,7 @@
// @name Google-Kanji
// @description-ja グーグルを使って漢字を検索
// @license Creative Commons 2.1 (Attribution + Share Alike)
-// @version 1.0
+// @version 1.1
// ==/VimperatorPlugin==
//
// Usage:
@@ -21,9 +21,7 @@
var re = /[\u4e00-\u9fa0]+/g; // 一-龠
var ignore = /\u691c\u7d22|\u95a2\u9023/; // 検索|関連
var req = new XMLHttpRequest();
- liberator.log(word);
var word = encodeURIComponent(word);
- liberator.log(word);
req.open('GET', 'http://www.google.co.jp/search?hl=ja&q=' + word + '&lr=lang_ja', true);
var f = function () {
var cnt = {};
@@ -56,7 +54,9 @@
commands.addUserCommand(
['gkanji', 'googlekanji'],
'Google kanji',
- function (arg) getKanji(arg.string)
+ function (arg) getKanji(arg.string),
+ {},
+ true
);
function copyToClipboard (copytext) {
@@ -76,7 +76,13 @@
['gkcopy'],
'Google kanji',
copyToClipboard,
- { completer: function (args) [0, copycompl] }
+ {
+ completer: function (context) {
+ context.title = ['kanji', 'count'];
+ context.items = copycompl;
+ }
+ },
+ true
);
diff --git a/lo.js b/lo.js
index d25aa31..fb985bd 100644
--- a/lo.js
+++ b/lo.js
@@ -2,8 +2,10 @@
// @name Link Opener
// @description Open filtered link(s).
// @description-ja リンクをフィルタリングして開く
-// @license Creative Commons 2.1 (Attribution + Share Alike)
-// @version 1.2
+// @license Creative Commons Attribution-Share Alike 3.0 Unported
+// @version 1.3
+// @minVersion 2.0pre
+// @maxVersion 2.0pre
// ==/VimperatorPlugin==
//
// Usage:
@@ -27,9 +29,12 @@
//
// Variables:
// let g:fopen_default_interval="<INTERVAL_SEC>"
+//
+// License:
+// http://creativecommons.org/licenses/by-sa/3.0/
-(function () { try {
+(function () {
let migemo = window.XMigemoCore;
@@ -95,15 +100,17 @@
},
{
bang: true,
+ argCount: '1',
options: [
[['-interval', '-i'], commands.OPTION_INT],
[['-where', '-w'], commands.OPTION_STRING],
],
- completer: function (word) {
- let links = filteredLinks(word);
- return [0, [[it.href, it.textContent] for each (it in links)]];
+ completer: function (context, arg, bang) {
+ context.title = ['URL', 'Text Content'];
+ context.items = filteredLinks(context.filter).map(function (it) ([it.href, it.textContent]));
},
- }
+ },
+ true
);
commands.addUserCommand(
@@ -124,27 +131,37 @@
commands.addUserCommand(
['lo[pen]', 'linkopen'],
'Filtered open',
- function (opts, bang) {
- let where = charToWhere(opts['-where'], bang ? liberator.NEW_TAB : liberator.CURRENT_TAB);
- let arg = opts.arguments[0];
- let m = arg.match(/^\d+(?=,)/);
- if (m)
- buffer.followLink(lolinks[parseInt(m[0], 10)], where);
+ function (arg, bang) {
+ let where = charToWhere(arg['-where'], bang ? liberator.NEW_TAB : liberator.CURRENT_TAB);
+ let numUrl = arg.arguments[0];
+ let m = numUrl.match(/^(\d+),(.+)$/);
+ if (m) {
+ let link = lolinks[parseInt(m[1], 10)];
+ if (link)
+ buffer.followLink(link, where);
+ else
+ liberator.open(m[2], where);
+ } else {
+ liberator.open(numUrl, where);
+ }
},
{
+ argCount: '1',
options: looptions,
bang: true,
- completer: function (word) {
- if (!word || word.match(/\s|\d+,/))
- return [];
- lolinks = filteredLinks(word);
- return [0, [[i + ',' + lolinks[i].href, lolinks[i].textContent] for (i in lolinks || [])]];
+ completer: function (context) {
+ let last = context.contextList.slice(-1)[0];
+ lolinks = filteredLinks(last.filter);
+ context.title = ['URL', 'Text Content'];
+ context.advance(last.offset - last.caret);
+ context.items = lolinks.map(function (it, i) ([i + ',' + it.href, it.textContent]));
}
- }
+ },
+ true
);
}
-} catch (e) { liberator.log(e); }})();
+})();
-// vim:sw=2 ts=2 et:
+// vim:sw=2 ts=2 et si fdm=marker:
diff --git a/multi_requester.js b/multi_requester.js
index 51756f8..60b0f48 100644
--- a/multi_requester.js
+++ b/multi_requester.js
@@ -4,7 +4,7 @@
* @description request, and the result is displayed to the buffer.
* @description-ja リクエストの結果をバッファに出力する。
* @author suVene suvene@zeromemory.info
- * @version 0.2.2
+ * @version 0.2.3
* @minVersion 2.0pre
* @maxVersion 2.0pre
* ==/VimperatorPlugin==
@@ -162,13 +162,12 @@ var CommandRegister = {
cmdClass.description,
$U.bind(cmdClass, cmdClass.cmdAction),
{
- completer: cmdClass.cmdCompleter || function(filter, special) {
+ completer: cmdClass.cmdCompleter || function(context, arg, bang) {
var allSuggestions = siteinfo.map(function(s) [s.name, s.description]);
- if (!filter) return [0, allSuggestions];
- var suggestions = allSuggestions.filter(function(s) {
- return s[0].indexOf(filter) == 0;
- });
- return [0, suggestions];
+ context.title = ['Name', 'Descprition'];
+ context.items =
+ context.filter ? allSuggestions.filter(function(s) s[0].indexOf(context.filter) == 0)
+ : allSuggestions;
},
options: cmdClass.cmdOptions,
argCount: cmdClass.argCount || undefined,
diff --git a/nico_related_videos.js b/nico_related_videos.js
index d6a3eea..e0779af 100644
--- a/nico_related_videos.js
+++ b/nico_related_videos.js
@@ -94,17 +94,18 @@
},
{
bang: true,
- completer: function (args) {
- if (buffer.URL != last.url) {
+ completer: function (context, arg, bang) {
+ if ((buffer.URL != last.url) || !last.completions.length) {
last.completions = [];
getRelatedVideos().forEach(function (it) last.completions.push([it.url, it.title]));
getRelatedTags().forEach(function (it) last.completions.push([":" + it, "tag"]));
last.url = buffer.URL;
}
- return [0, last.completions.length ? completion.filter(last.completions, args)
- : [[nothing, nothing]]];
+ context.title = ['Keyword'];
+ context.items = completion.filter(last.completions, context.filter);
}
- }
+ },
+ true
);
})();
diff --git a/readcatlater.js b/readcatlater.js
index 97c545a..6c24b6a 100644
--- a/readcatlater.js
+++ b/readcatlater.js
@@ -2,7 +2,7 @@
// @name Read Cat Later
// @description-ja Read It Later 的な物
// @license Creative Commons 2.1 (Attribution + Share Alike)
-// @version 0.2
+// @version 1.0
// ==/VimperatorPlugin==
//
// Usage:
@@ -22,7 +22,7 @@
// Link:
// http://d.hatena.ne.jp/nokturnalmortum/20080918#1221729188
-(function () { try {
+(function () {
liberator.log('readcatlater.js loading');
// このプラグインでブックマークしたときに必ずつくタグ
@@ -194,12 +194,11 @@
return liberator.globalVariables.readcatlater_reverse ? result.reverse() : result;
} catch (e) { liberator.log(e); } }
- function completer (args) {
- var cs;
- try {
- cs = [ [it.URI, bookmarks.getItemTitle(it.id)] for each (it in RCL_Bookmarks(args)) if (it.id) ];
- return [0, cs]
- } catch (e) { liberator.log(e); }
+ function completer (context, arg, bang) {
+ context.title = ['URL', 'Title'];
+ context.items = RCL_Bookmarks(context.filter).
+ filter(function (it) it.id).
+ map(function (it) [it.URI, bookmarks.getItemTitle(it.id)]);
}
function removeItems (uri) {
@@ -235,31 +234,32 @@
commands.addUserCommand(
['readcatnow', 'rcn'],
'read cat now',
- function (uri, bang, num, extra) {
- // for HEAD
- if (uri.string != undefined)
- uri = uri.string;
+ function (arg, bang, num, extra) {
+ let uri = arg.string;
openURI(uri);
if (!bang && removeItems(uri))
liberator.echo('"' + uri + '" was removed.');
},
{
completer: completer
- }
+ },
+ true
);
commands.addUserCommand(
['deletecatnow', 'dcn'],
'delete cat now',
- function (uri, bang, num, extra) {
+ function (arg, bang, num, extra) {
+ let uri = arg.string;
if (removeItems(uri))
liberator.echo('"' + uri + '" was removed.');
},
{
completer: completer
- }
+ },
+ true
);
liberator.log('readcatlater.js loaded');
-} catch (e) { liberator.log(e); } })();
+})();
diff --git a/umihara.js b/umihara.js
index 637fb26..49a871b 100644
--- a/umihara.js
+++ b/umihara.js
@@ -93,11 +93,17 @@
let extra = {
argCount: '+',
bang: true,
- completer: function (arg) {
+ completer: function (context, arg, bang) {
+ let last = context.contextList.slice(-1)[0];
+ context.title = ['Country Code'];
+ context.advance(last.offset - last.caret);
+ context.items = completion.filter(cl, last.filter);
+ /*
if (!(arg = commands.parseArgs(arg, extra.options, extra.argCount)))
return [0, []];
let m = arg.string.match(/\s(\w+)$/);
return [(m ? m.index : arg.string.length) + 1, m ? completion.filter(cl, m[1]) : cl];
+ */
}
};
@@ -110,7 +116,8 @@
value = eval(value);
kawase(value, clipboard, from, to);
},
- extra
+ extra,
+ true
);
})();