/** * vimperator plugin * * proxy setting plugin (for vimperator-0.6pre) * * @author cho45 * @author halt feits * @version 0.6.1 */ (function() { const proxy_settings = [ { conf_name: 'disable', conf_usage: 'direct connection', setting: [ { label: 'type', param: 0 } ] }, { conf_name: 'polipo', conf_usage: 'use polipo cache proxy', setting: [ { label: 'type', param: 1 }, { label: 'http', param: 'localhost' }, { label: 'http_port', param: 8123 } ] } ]; liberator.commands.addUserCommand(["proxy"], 'proxy settings', function (args) { const prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService); var name = args; if (!name) { liberator.echo("Usage: proxy {setting name}"); } for (var i = 0; i < proxy_settings.length; i++) { var proxy_setting = proxy_settings[i]; if (proxy_setting.conf_name.toLowerCase() == name.toLowerCase()) { //delete setting ['http', 'ssl', 'ftp', 'gopher'].forEach( function (p) { prefs.setCharPref("network.proxy." + p, ''); prefs.setIntPref("network.proxy." + p + "_port", 0); } ); for (var j = 0; j < proxy_setting.setting.length; j++) { var conf = proxy_setting.setting[j]; liberator.options.setPref('network.proxy.' + conf.label, conf.param); } liberator.echo("set config:" + name); break; } } }, { completer: function (filter) { var completions = []; for (var i = 0; i < proxy_settings.length; i++) { var name = proxy_settings[i].conf_name; var usage = proxy_settings[i].conf_usage; var exp = new RegExp("^" + filter); if (exp.test(name)) { completions.push([name, usage]); } } return [0, completions]; } } ); })(); // vim: set sw=4 ts=4 et: mmandBookmarklet.js?h=google-plus-commando/poster&id=819e9895648eb342f2c9da90e01827fe8429c1af'>diffstats
path: root/commandBookmarklet.js
blob: 3375dce750c15cf947bc556ae0fa49c927aa087c (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/**
 * bookmarklet wo command ni suru plugin
 *
 * @author halt feits <halt.feits@gmail.com>
 * @version 0.6.4
 */

let PLUGIN_INFO =
<VimperatorPlugin>
<name>{NAME}</name>
<description>convert bookmarklets to commands</description>
<description lang="ja">ブックマークレットをコマンドにする</description>
<author mail="halt.feits@gmail.com">halt feits</author>
<version>0.6.6</version>
<minVersion>2.0pre</minVersion>
<maxVersion>2.1pre</maxVersion>
<updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/commandBookmarklet.js</updateURL>
<detail><![CDATA[
== SYNOPSIS ==
  This plugin automatically converts bookmarklets to valid commands for Vimperator.

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

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

== GLOBAL VARIABLES ==
  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.

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

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

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

== GLOBAL VARIABLES ==
  command_bookmarklet_prefix:
    コマンドの先頭に付加される文字列を規定します
    デフォルトは "bml"
  command_bookmarklet_use_sandbox:
    1 の時ブックマークレットのスクリプトを sandbox で実行します
    NoScript アドオンをつかっている場合はこのオプションを有効にする必要があるでしょう

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

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

( function () {

let prefix = liberator.globalVariables.command_bookmarklet_prefix;
if (prefix === undefined)
  prefix = 'bml';

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

items.forEach(function (item) {
  commands.addUserCommand(
    [toValidCommandName(item.title)],
    'bookmarklet : ' + item.title,
    function () evalScript(item.url),
    { shortHelp: 'Bookmarklet' },
    false
  );
});

function toBoolean (value, def) {
  switch (typeof value) {
    case 'undefined':
      return def;
    case 'number':
      return !!value;
    case 'string':
      return !/^(\d+|false)$/i.test(value) || parseInt(value);
    default:
      return !!value;
  }
}

function evalInSandbox (str) {
  let sandbox = new Components.utils.Sandbox("about:blank");
  sandbox.__proto__ = content.window.wrappedJSObject;
  return Components.utils.evalInSandbox(str, sandbox);
}

function evalScript (url) {
  if (toBoolean(liberator.globalVariables.command_bookmarklet_use_sandbox, false)) {
    evalInSandbox(decodeURIComponent(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);
}

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