From 3c573ea41f706c9bf4ea8bf18d6f5730349a46c2 Mon Sep 17 00:00:00 2001 From: secondlife Date: Tue, 17 Feb 2009 14:33:13 +0000 Subject: set nantora で簡単に user_pref を切り替えられるプラグイン git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@30199 d0d07461-0603-4401-acd4-de1884942a52 --- options-migrate-user-pref.js | 90 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 options-migrate-user-pref.js (limited to 'options-migrate-user-pref.js') 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 = + +{NAME} +options migrate user_pref +:set foobarbaz で簡単に user_pref をセットできるプラグイン +2.0 +2.0 +http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk/options-migrate-user-pref.js +Yuichi Tateno +MIT +0.1 +|| +:set! javascript.enabled=true +||< +を +>|| +:set javascript +:set nojavascript +||< +のようにマッピングするためのプラグインです。 +boolean/number を簡単にセットできるようになるため、よく user_pref を変更する場合などに便利です。 + +例 +>|| +js < +; + +(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'] || []); +})(); + -- cgit v1.2.3