diff options
author | secondlife | 2009-02-17 14:33:13 +0000 |
---|---|---|
committer | secondlife | 2009-02-17 14:33:13 +0000 |
commit | 3c573ea41f706c9bf4ea8bf18d6f5730349a46c2 (patch) | |
tree | 74287f1647a774ad0d7c945ecab2fa04022e51c5 /options-migrate-user-pref.js | |
parent | f79cdf401787f670a5aa401a6ccdc8b9c2865dfb (diff) | |
download | vimperator-plugins-3c573ea41f706c9bf4ea8bf18d6f5730349a46c2.tar.bz2 |
set nantora で簡単に user_pref を切り替えられるプラグイン
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@30199 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'options-migrate-user-pref.js')
-rw-r--r-- | options-migrate-user-pref.js | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/options-migrate-user-pref.js b/options-migrate-user-pref.js new file mode 100644 index 0000000..7edcdaa --- /dev/null +++ b/options-migrate-user-pref.js @@ -0,0 +1,90 @@ +var PLUGIN_INFO = +<VimperatorPlugin> +<name>{NAME}</name> +<description>options migrate user_pref</description> +<description lang="ja">:set foobarbaz で簡単に user_pref をセットできるプラグイン</description> +<minVersion>2.0</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'] || []); +})(); + |