aboutsummaryrefslogtreecommitdiffstats
path: root/commandBookmarklet.js
blob: 359dec0ed10d3101e80fd97ad42ed04bd2f428cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/**
 * bookmarklet wo command ni suru plugin
 *
 * @author halt feits <halt.feits@gmail.com>
 * @version 0.6.2
 */

let PLUGIN_INFO = 
<VimperatorPlugin>
<name>{NAME}</name>
<description>convert bookmarklets to command</description>
<description lang="ja">ブックマークレットをコマンドにする</description>
<author mail="halt.feits@gmail.com">halt feits</author>
<version>0.6.2</version>
<minVersion>2.0pre</minVersion>
<maxVersion>2.0pre</maxVersion>
<detail><![CDATA[
== SYNOPSIS ==
This plugin automatically convert bookmarklets to valid command for vimperator.

== COMMAND ==
Nothing built-in command, but each bookmarklets convert to commands that start with "bml".

== EXAMPLE ==
"Hatena-Bookmark" -> bmlhatena-bookmark

== KNOWN BUGS ==
When title has non-ASCII characters, it convert to unaccountable command.
You should rewrite title of bookmarklet to ASCII characters, to escape this bug.

]]></detail>
<detail lang="ja"><![CDATA[
== SYNOPSIS ==
このプラグインはブックマークレットを vimpertor で実行可能なコマンドに自動的に変換します

== COMMAND ==
固有のコマンドはありませんがそれぞれのブックマークレットは "bml" ではじまるコマンドに変換されます

== EXAMPLE ==
"Hatena-Bookmark" -> bmlhatena-bookmark

== KNOWN BUGS ==
タイトルに ASCII 文字以外が含まれている場合わけのわからないコマンドになります
このバグを避けるためにブックマークレットのタイトルを ASCII 文字のみに書き換えることをおすすめします

]]></detail>
</VimperatorPlugin>;

( function () {

let items = bookmarks.get('javascript:');
if (!items.length) {
    liberator.echoerr('No bookmarks set');
    return;
}

for (let item in util.Array.iterator(items)) {
    commands.addUserCommand(
        [toValidCommandName(item.title)],
        'bookmarklet : ' + item.title,
        function () { liberator.open(item.url); },
        { shortHelp: 'Bookmarklet' },
        false
    );
}

function toValidCommandName(str) {
    str = 'bml' + escape(str.replace(/ +/g, '').toLowerCase()).replace(/[^a-zA-Z]/g,'');
    return str.substr(0, str.length > 50 ? 50 : str.length);
}

} )();
// vim:sw=2 ts=2 et: