root/lang/javascript/vimperator-plugins/branches/2.1/options-migrate-user-pref.js

Revision 30710, 2.7 kB (checked in by anekos, 19 months ago)

末尾の空白の除去など

Line 
1var PLUGIN_INFO =
2<VimperatorPlugin>
3<name>{NAME}</name>
4<description>options migrate user_pref</description>
5<description lang="ja">:set foobarbaz で簡単に user_pref をセットできるプラグイン</description>
6<minVersion>2.0pre</minVersion>
7<maxVersion>2.0</maxVersion>
8<updateURL>http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/options-migrate-user-pref.js</updateURL>
9<author mail="hotchpotch@gmail.com" homepage="http://d.hatena.ne.jp/secondlife/">Yuichi Tateno</author>
10<license>MIT</license>
11<version>0.1</version>
12<detail><![CDATA[
13>||
14:set! javascript.enabled=true
15||<
16
17>||
18:set javascript
19:set nojavascript
20||<
21のようにマッピングするためのプラグインです。
22boolean/number を簡単にセットできるようになるため、よく user_pref を変更する場合などに便利です。
23
24
25>||
26js <<EOF
27liberator.globalVariables.options_migrate_user_pref =
28[
29    {
30        pref: 'javascript.enabled',
31        description: 'Using JavaScript',
32        command: ['javascript', 'js'],
33    },
34    {
35        pref: 'font.size.fixed.ja',
36        description: 'JA fixed font-size',
37        command: ['jaffont'],
38    }
39];
40EOF
41||<
42
43]]></detail>
44</VimperatorPlugin>;
45
46(function() {
47    let p = function(msg) {
48        Application.console.log(msg);
49    }
50
51    liberator.plugins.migrateUserPref = function(config) {
52        config.forEach(function(conf) {
53            let pref = conf.pref;
54            let type;
55            try
56            {
57                switch (services.get('pref').getPrefType(conf.pref))
58                {
59                case Ci.nsIPrefBranch.PREF_STRING:
60                    // XXX: string のとき、うまく user_pref に設定できていない?
61                    type = 'string';
62                    break;
63                case Ci.nsIPrefBranch.PREF_INT:
64                    type = 'number';
65                    break;
66                case Ci.nsIPrefBranch.PREF_BOOL:
67                    type = 'boolean';
68                    break;
69                default:
70                    return liberator.echoerr('migrate-user-pref: error pref: ' + pref);
71                }
72            }
73            catch (e)
74            {
75                return liberator.echoerr('migrate-user-pref: error pref: ' + pref + ' ' + e);
76            }
77
78            options.add(conf.command, conf.description, type,
79                (typeof conf.defaultValue == 'undefined' ? options.getPref(pref) : conf.defaultValue),
80                {
81                    setter: function(value) options.setPref(pref, value),
82                    getter: function() options.getPref(pref),
83                }
84            );
85        });
86    }
87
88    liberator.plugins.migrateUserPref(liberator.globalVariables['options_migrate_user_pref'] || []);
89})();
90
Note: See TracBrowser for help on using the browser.