diff options
author | retlet | 2008-11-05 06:04:44 +0000 |
---|---|---|
committer | retlet | 2008-11-05 06:04:44 +0000 |
commit | c4489d32e21b8548976fec780eff4df613697a53 (patch) | |
tree | 1ecf88b6f2d562dde2f06e4824d7916f83fe4d8c /uaSwitch.js | |
parent | 56cb882fc6f122c75608f8eb6142a607d3dc855f (diff) | |
download | vimperator-plugins-c4489d32e21b8548976fec780eff4df613697a53.tar.bz2 |
手元の環境で動いているものをtags/2.0pre_1016からコピー
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/branches/1.2@22751 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'uaSwitch.js')
-rw-r--r-- | uaSwitch.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/uaSwitch.js b/uaSwitch.js new file mode 100644 index 0000000..f759fd1 --- /dev/null +++ b/uaSwitch.js @@ -0,0 +1,37 @@ +// Vimperator plugin: uaSwitch
+// Maintainer: mattn <mattn.jp@gmail.com> - http://mattn.kaoriya.net
+// Require: User Agent Switcher - https://addons.mozilla.org/firefox/addon/59
+// Usage:
+// :ua MyUserAgent - set user agent named MyUserAgent.
+// :ua Default - reset user agent to default.
+// :ua! - open user agent switcher setting dialog.
+// :ua - show current user agent.
+
+(function() {
+ if (typeof useragentswitcher_reset != 'function') return;
+
+ // activate user agent siwtcher
+ useragentswitcher_displayUserAgentSwitcherMenu(document.getElementById('useragentswitcher-popup-menu'), 'menu');
+
+ // return user agent list
+ function getItems()
+ Array.map(document.getElementById('useragentswitcher-menu')
+ .getElementsByAttribute('type', 'radio'),
+ function(n) {
+ return {
+ label : n.getAttribute('label'),
+ oncommand : n.getAttribute('oncommand'),
+ checked : n.getAttribute('checked')
+ }
+ });
+
+ // register Vimperator command
+ liberator.commands.addUserCommand(['ua'], 'Switch User Agent', function(arg, special){
+ if (special) useragentswitcher_options();
+ else if (!arg) liberator.echo('UserAgent: ' + getItems().filter(function(n) n.checked)[0].label);
+ else window.eval(getItems().filter(function(n) n.label == arg)[0].oncommand);
+ }, {
+ completer: function(filter, special)
+ [0, getItems().map(function(n) [n.label, n.label])]
+ });
+})();
|