From 892de5c3f42bd852a3b9e811090fc57d545b0e74 Mon Sep 17 00:00:00 2001 From: anekos Date: Sun, 10 May 2009 09:38:08 +0000 Subject: NoScript 対応(?) Sandbox で実行するオプション追加 インデント修正 git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@33215 d0d07461-0603-4401-acd4-de1884942a52 --- commandBookmarklet.js | 85 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 29 deletions(-) (limited to 'commandBookmarklet.js') diff --git a/commandBookmarklet.js b/commandBookmarklet.js index c89817e..cc22cea 100644 --- a/commandBookmarklet.js +++ b/commandBookmarklet.js @@ -2,7 +2,7 @@ * bookmarklet wo command ni suru plugin * * @author halt feits - * @version 0.6.3 + * @version 0.6.4 */ let PLUGIN_INFO = @@ -11,47 +11,53 @@ let PLUGIN_INFO = convert bookmarklets to commands ブックマークレットをコマンドにする halt feits -0.6.3 +0.6.4 2.0pre -2.0pre +2.1pre http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/commandBookmarklet.js bmlhatena-bookmark + "Hatena-Bookmark" -> bmlhatena-bookmark == GLOBAL VARIABLES == -command_bookmarklet_prefix: -This variable determines the prefix of a command name. + command_bookmarklet_prefix: + This variable determines the prefix of a command name. + command_bookmarklet_use_sandbox: + When this variable is 1, execute the script of bookmarklets in Sandbox. + If you use NoScript addon, probably you should enable this option. == KNOWN ISSUES == -When title has non-ASCII characters, it converts to unaccountable command. -You should rewrite title of bookmarklet to ASCII characters, to escape this issue. + When title has non-ASCII characters, it converts to unaccountable command. + You should rewrite title of bookmarklet to ASCII characters, to escape this issue. ]]> bmlhatena-bookmark + "Hatena-Bookmark" -> bmlhatena-bookmark == GLOBAL VARIABLES == -command_bookmarklet_prefix: -コマンドの先頭に付加される文字列を規定します。 -デフォルトは "bml" + command_bookmarklet_prefix: + コマンドの先頭に付加される文字列を規定します。 + デフォルトは "bml" + command_bookmarklet_use_sandbox: + 1 の時、ブックマークレットのスクリプトを sandbox で実行します。 + NoScript アドオンをつかっている場合は、このオプションを有効にする必要があるでしょう。 == KNOWN ISSUES == -タイトルに ASCII 文字以外が含まれている場合、わけのわからないコマンドになります。 -この問題を避けるためにブックマークレットのタイトルを ASCII 文字のみに書き換えることをおすすめします。 + タイトルに ASCII 文字以外が含まれている場合、わけのわからないコマンドになります。 + この問題を避けるためにブックマークレットのタイトルを ASCII 文字のみに書き換えることをおすすめします。 ]]> ; @@ -64,23 +70,44 @@ if (prefix === undefined) let items = bookmarks.get('javascript:'); if (!items.length) { - liberator.echoerr('No bookmarks set'); - return; + liberator.echoerr('No bookmarks set'); + return; } items.forEach(function (item) { - commands.addUserCommand( - [toValidCommandName(item.title)], - 'bookmarklet : ' + item.title, - function () { liberator.open(item.url); }, - { shortHelp: 'Bookmarklet' }, - false - ); + commands.addUserCommand( + [toValidCommandName(item.title)], + 'bookmarklet : ' + item.title, + function () evalScript(item.url), + { shortHelp: 'Bookmarklet' }, + false + ); }); +function stringToBoolean(str, defaultValue) { + return !str ? defaultValue + : str.toLowerCase() === 'false' ? false + : /^\d+$/.test(str) ? parseInt(str) + : true; +} + +function evalInSandbox (str) { + let sandbox = new Components.utils.Sandbox(buffer.URL); + sandbox.__proto__ = content.window.wrappedJSObject; + return Components.utils.evalInSandbox(str, sandbox); +} + +function evalScript (url) { + if (stringToBoolean(liberator.globalVariables.command_bookmarklet_use_sandbox, false)) { + evalInSandbox(url.replace(/^\s*javascript:/i, '')); + } else { + liberator.open(url); + } +} + function toValidCommandName(str) { - str = prefix + escape(str.replace(/ +/g, '').toLowerCase()).replace(/[^a-zA-Z]+/g,''); - return str.substr(0, str.length > 50 ? 50 : str.length); + str = prefix + escape(str.replace(/ +/g, '').toLowerCase()).replace(/[^a-zA-Z]+/g,''); + return str.substr(0, str.length > 50 ? 50 : str.length); } } )(); -- cgit v1.2.3