| 1 | /** |
|---|
| 2 | * bookmarklet wo command ni suru plugin |
|---|
| 3 | * |
|---|
| 4 | * @author halt feits <halt.feits@gmail.com> |
|---|
| 5 | * @version 0.6.3 |
|---|
| 6 | */ |
|---|
| 7 | |
|---|
| 8 | let 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 == |
|---|
| 20 | This plugin automatically converts bookmarklets to valid commands for Vimperator. |
|---|
| 21 | |
|---|
| 22 | == COMMAND == |
|---|
| 23 | Nothing 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 == |
|---|
| 29 | command_bookmarklet_prefix: |
|---|
| 30 | This variable determines the prefix of a command name. |
|---|
| 31 | |
|---|
| 32 | == KNOWN ISSUES == |
|---|
| 33 | When title has non-ASCII characters, it converts to unaccountable command. |
|---|
| 34 | You 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 == |
|---|
| 48 | command_bookmarklet_prefix: |
|---|
| 49 | コマンドの先頭に付加される文字列を規定します。 |
|---|
| 50 | デフォルトは "bml" |
|---|
| 51 | |
|---|
| 52 | == KNOWN ISSUES == |
|---|
| 53 | タイトルに ASCII 文字以外が含まれている場合、わけのわからないコマンドになります。 |
|---|
| 54 | この問題を避けるためにブックマークレットのタイトルを ASCII 文字のみに書き換えることをおすすめします。 |
|---|
| 55 | |
|---|
| 56 | ]]></detail> |
|---|
| 57 | </VimperatorPlugin>; |
|---|
| 58 | |
|---|
| 59 | ( function () { |
|---|
| 60 | |
|---|
| 61 | let prefix = liberator.globalVariables.command_bookmarklet_prefix; |
|---|
| 62 | if (prefix === undefined) |
|---|
| 63 | prefix = 'bml'; |
|---|
| 64 | |
|---|
| 65 | let items = bookmarks.get('javascript:'); |
|---|
| 66 | if (!items.length) { |
|---|
| 67 | liberator.echoerr('No bookmarks set'); |
|---|
| 68 | return; |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | items.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 | |
|---|
| 81 | function 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: |
|---|