root/lang/javascript/vimperator-plugins/branches/2.0/commandBookmarklet.js

Revision 27364, 2.7 kB (checked in by suVene, 21 months ago)

add updateURL for pluginManager.js

Line 
1/**
2 * bookmarklet wo command ni suru plugin
3 *
4 * @author halt feits <halt.feits@gmail.com>
5 * @version 0.6.3
6 */
7
8let PLUGIN_INFO =
9<VimperatorPlugin>
10<name>{NAME}</name>
11<description>convert bookmarklets to commands</description>
12<description lang="ja">ブックマークレットをコマンドにする</description>
13<author mail="halt.feits@gmail.com">halt feits</author>
14<version>0.6.3</version>
15<minVersion>2.0pre</minVersion>
16<maxVersion>2.0pre</maxVersion>
17<updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/commandBookmarklet.js</updateURL>
18<detail><![CDATA[
19== SYNOPSIS ==
20This plugin automatically converts bookmarklets to valid commands for Vimperator.
21
22== COMMAND ==
23Nothing built-in command, but each bookmarklets convert to commands that start with "bml".
24
25== EXAMPLE ==
26"Hatena-Bookmark" -> bmlhatena-bookmark
27
28== GLOBAL VARIABLES ==
29command_bookmarklet_prefix:
30This variable determines the prefix of a command name.
31
32== KNOWN ISSUES ==
33When title has non-ASCII characters, it converts to unaccountable command.
34You should rewrite title of bookmarklet to ASCII characters, to escape this issue.
35
36]]></detail>
37<detail lang="ja"><![CDATA[
38== SYNOPSIS ==
39このプラグインはブックマークレットを Vimperator で実行可能なコマンドに自動的に変換します。
40
41== COMMAND ==
42固有のコマンドはありませんが、それぞれのブックマークレットは "bml" ではじまるコマンドに変換されます。
43
44== EXAMPLE ==
45"Hatena-Bookmark" -> bmlhatena-bookmark
46
47== GLOBAL VARIABLES ==
48command_bookmarklet_prefix:
49コマンドの先頭に付加される文字列を規定します。
50デフォルトは "bml"
51
52== KNOWN ISSUES ==
53タイトルに ASCII 文字以外が含まれている場合、わけのわからないコマンドになります。
54この問題を避けるためにブックマークレットのタイトルを ASCII 文字のみに書き換えることをおすすめします。
55
56]]></detail>
57</VimperatorPlugin>;
58
59( function () {
60
61let prefix = liberator.globalVariables.command_bookmarklet_prefix;
62if (prefix === undefined)
63  prefix = 'bml';
64
65let items = bookmarks.get('javascript:');
66if (!items.length) {
67    liberator.echoerr('No bookmarks set');
68    return;
69}
70
71items.forEach(function (item) {
72    commands.addUserCommand(
73        [toValidCommandName(item.title)],
74        'bookmarklet : ' + item.title,
75        function () { liberator.open(item.url); },
76        { shortHelp: 'Bookmarklet' },
77        false
78    );
79});
80
81function toValidCommandName(str) {
82    str = prefix + escape(str.replace(/ +/g, '').toLowerCase()).replace(/[^a-zA-Z]+/g,'');
83    return str.substr(0, str.length > 50 ? 50 : str.length);
84}
85
86} )();
87// vim:sw=2 ts=2 et:
Note: See TracBrowser for help on using the browser.