Changeset 33215
- Timestamp:
- 05/10/09 18:38:08 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/vimperator-plugins/trunk/commandBookmarklet.js
r27364 r33215 3 3 * 4 4 * @author halt feits <halt.feits@gmail.com> 5 * @version 0.6. 35 * @version 0.6.4 6 6 */ 7 7 … … 12 12 <description lang="ja">ブックマークレットをコマンドにする</description> 13 13 <author mail="halt.feits@gmail.com">halt feits</author> 14 <version>0.6. 3</version>14 <version>0.6.4</version> 15 15 <minVersion>2.0pre</minVersion> 16 <maxVersion>2. 0pre</maxVersion>16 <maxVersion>2.1pre</maxVersion> 17 17 <updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/commandBookmarklet.js</updateURL> 18 18 <detail><![CDATA[ 19 19 == SYNOPSIS == 20 This plugin automatically converts bookmarklets to valid commands for Vimperator.20 This plugin automatically converts bookmarklets to valid commands for Vimperator. 21 21 22 22 == COMMAND == 23 Nothing built-in command, but each bookmarklets convert to commands that start with "bml".23 Nothing built-in command, but each bookmarklets convert to commands that start with "bml". 24 24 25 25 == EXAMPLE == 26 "Hatena-Bookmark" -> bmlhatena-bookmark26 "Hatena-Bookmark" -> bmlhatena-bookmark 27 27 28 28 == GLOBAL VARIABLES == 29 command_bookmarklet_prefix: 30 This variable determines the prefix of a command name. 29 command_bookmarklet_prefix: 30 This variable determines the prefix of a command name. 31 command_bookmarklet_use_sandbox: 32 When this variable is 1, execute the script of bookmarklets in Sandbox. 33 If you use NoScript addon, probably you should enable this option. 31 34 32 35 == 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.36 When title has non-ASCII characters, it converts to unaccountable command. 37 You should rewrite title of bookmarklet to ASCII characters, to escape this issue. 35 38 36 39 ]]></detail> 37 40 <detail lang="ja"><![CDATA[ 38 41 == SYNOPSIS == 39 このプラグインはブックマークレットを Vimperator で実行可能なコマンドに自動的に変換します。42 このプラグインはブックマークレットを Vimperator で実行可能なコマンドに自動的に変換します。 40 43 41 44 == COMMAND == 42 固有のコマンドはありませんが、それぞれのブックマークレットは "bml" ではじまるコマンドに変換されます。45 固有のコマンドはありませんが、それぞれのブックマークレットは "bml" ではじまるコマンドに変換されます。 43 46 44 47 == EXAMPLE == 45 "Hatena-Bookmark" -> bmlhatena-bookmark48 "Hatena-Bookmark" -> bmlhatena-bookmark 46 49 47 50 == GLOBAL VARIABLES == 48 command_bookmarklet_prefix: 49 コマンドの先頭に付加される文字列を規定します。 50 デフォルトは "bml" 51 command_bookmarklet_prefix: 52 コマンドの先頭に付加される文字列を規定します。 53 デフォルトは "bml" 54 command_bookmarklet_use_sandbox: 55 1 の時、ブックマークレットのスクリプトを sandbox で実行します。 56 NoScript アドオンをつかっている場合は、このオプションを有効にする必要があるでしょう。 51 57 52 58 == KNOWN ISSUES == 53 タイトルに ASCII 文字以外が含まれている場合、わけのわからないコマンドになります。54 この問題を避けるためにブックマークレットのタイトルを ASCII 文字のみに書き換えることをおすすめします。59 タイトルに ASCII 文字以外が含まれている場合、わけのわからないコマンドになります。 60 この問題を避けるためにブックマークレットのタイトルを ASCII 文字のみに書き換えることをおすすめします。 55 61 56 62 ]]></detail> … … 65 71 let items = bookmarks.get('javascript:'); 66 72 if (!items.length) { 67 liberator.echoerr('No bookmarks set');68 return;73 liberator.echoerr('No bookmarks set'); 74 return; 69 75 } 70 76 71 77 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 false78 );78 commands.addUserCommand( 79 [toValidCommandName(item.title)], 80 'bookmarklet : ' + item.title, 81 function () evalScript(item.url), 82 { shortHelp: 'Bookmarklet' }, 83 false 84 ); 79 85 }); 80 86 87 function stringToBoolean(str, defaultValue) { 88 return !str ? defaultValue 89 : str.toLowerCase() === 'false' ? false 90 : /^\d+$/.test(str) ? parseInt(str) 91 : true; 92 } 93 94 function evalInSandbox (str) { 95 let sandbox = new Components.utils.Sandbox(buffer.URL); 96 sandbox.__proto__ = content.window.wrappedJSObject; 97 return Components.utils.evalInSandbox(str, sandbox); 98 } 99 100 function evalScript (url) { 101 if (stringToBoolean(liberator.globalVariables.command_bookmarklet_use_sandbox, false)) { 102 evalInSandbox(url.replace(/^\s*javascript:/i, '')); 103 } else { 104 liberator.open(url); 105 } 106 } 107 81 108 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);109 str = prefix + escape(str.replace(/ +/g, '').toLowerCase()).replace(/[^a-zA-Z]+/g,''); 110 return str.substr(0, str.length > 50 ? 50 : str.length); 84 111 } 85 112
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)