-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathoptions-migrate-user-pref.js
91 lines (85 loc) · 2.81 KB
/
options-migrate-user-pref.js
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
var PLUGIN_INFO = xml`
<VimperatorPlugin>
<name>{NAME}</name>
<description>options migrate user_pref</description>
<description lang="ja">:set foobarbaz で簡単に user_pref をセットできるプラグイン</description>
<minVersion>2.0pre</minVersion>
<maxVersion>2.0</maxVersion>
<updateURL>https://github.com/vimpr/vimperator-plugins/raw/master/options-migrate-user-pref.js</updateURL>
<author mail="[email protected]" homepage="http://d.hatena.ne.jp/secondlife/">Yuichi Tateno</author>
<license>MIT</license>
<version>0.1</version>
<detail><![CDATA[
>||
:set! javascript.enabled=true
||<
を
>||
:set javascript
:set nojavascript
||<
のようにマッピングするためのプラグインです。
boolean/number を簡単にセットできるようになるため、よく user_pref を変更する場合などに便利です。
例
>||
js <<EOF
liberator.globalVariables.options_migrate_user_pref =
[
{
pref: 'javascript.enabled',
description: 'Using JavaScript',
command: ['javascript', 'js'],
},
{
pref: 'font.size.fixed.ja',
description: 'JA fixed font-size',
command: ['jaffont'],
}
];
EOF
||<
]]></detail>
</VimperatorPlugin>`;
(function() {
let p = function(msg) {
Application.console.log(msg);
}
liberator.plugins.migrateUserPref = function(config) {
config.forEach(function(conf) {
let pref = conf.pref;
let type;
try
{
switch (services.get('prefs').getPrefType(conf.pref))
{
case Ci.nsIPrefBranch.PREF_STRING:
// XXX: string のとき、うまく user_pref に設定できていない?
type = 'string';
break;
case Ci.nsIPrefBranch.PREF_INT:
type = 'number';
break;
case Ci.nsIPrefBranch.PREF_BOOL:
type = 'boolean';
break;
default:
return liberator.echoerr('migrate-user-pref: error pref: ' + pref);
}
}
catch (e)
{
return liberator.echoerr('migrate-user-pref: error pref: ' + pref + ' ' + e);
}
if (!options.get(conf.command[0])) {
options.add(conf.command, conf.description, type,
(typeof conf.defaultValue == 'undefined' ? options.getPref(pref) : conf.defaultValue),
{
setter: function(value) options.setPref(pref, value),
getter: function() options.getPref(pref),
}
);
}
});
}
liberator.plugins.migrateUserPref(liberator.globalVariables['options_migrate_user_pref'] || []);
})();