aboutsummaryrefslogtreecommitdiffstats
path: root/options-migrate-user-pref.js
blob: 3c919f291c91b3bd3791be188bf5c42485dd08ec (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
var PLUGIN_INFO =
<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>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/options-migrate-user-pref.js</updateURL>
<author mail="hotchpotch@gmail.com" 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('pref').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);
            }

            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'] || []);
})();