aboutsummaryrefslogtreecommitdiffstats
path: root/uaSwitch.js
diff options
context:
space:
mode:
authormattn2008-07-24 11:03:58 +0000
committermattn2008-07-24 11:03:58 +0000
commiteb816b7513b5035a42e1af69127bc3865e3abc15 (patch)
tree4bd6073f3ff3b711217f9b336bcf11fba4b65c11 /uaSwitch.js
parenta1cd53c9e6337de58ae538d4d09a5d2fd2d7fb93 (diff)
downloadvimperator-plugins-eb816b7513b5035a42e1af69127bc3865e3abc15.tar.bz2
user agent switcherを操作出来るvimperator plugin「uaSwitch.js」追加
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@16207 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'uaSwitch.js')
-rw-r--r--uaSwitch.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/uaSwitch.js b/uaSwitch.js
new file mode 100644
index 0000000..53ce980
--- /dev/null
+++ b/uaSwitch.js
@@ -0,0 +1,43 @@
+// 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() {
+ return Array.map(
+ document.getElementById("useragentswitcher-menu")
+ .getElementsByAttribute("type", "radio"),
+ function(n) {
+ return {
+ label : n.getAttribute('label'),
+ oncommand : n.getAttribute('oncommand'),
+ checked : n.getAttribute('checked')
+ }
+ }
+ );
+ }
+
+ // regist 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) {return n.checked})[0].label);
+ else window.eval(getItems().filter(function(n) {return n.label == arg})[0].oncommand);
+ },{
+ completer: function(filter, special){
+ return [0, getItems().map(function(n) { return [n.label, n.label] })];
+ }
+ }
+ );
+})();