aboutsummaryrefslogtreecommitdiffstats
path: root/uaSwitch.js
blob: 4f2f39cc75790934f765c9d089aa3d7d7834f990 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// 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.modules.commands.addUserCommand(['ua'], 'Switch User Agent', function(arg, special){
		arg = arg.string;
		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);
	}, {
        bang: true,
		completer: function(filter, special)
			[0, getItems().map(function(n) [n.label, n.label])]
	});
})();
9;label'); var commandline = document.getElementById('liberator-commandline'); iconPanel.setAttribute('id','statusbar-twitter-timeline-icon'); iconPanel.style.width = "16px"; iconPanel.style.height = "16px"; statusPanel.setAttribute('id','statusbar-twitter-timeline-status'); statusPanel.setAttribute('class','plain'); hbox.appendChild(iconPanel); hbox.appendChild(statusPanel); hbox.setAttribute('id','statusbar-twitter-timeline'); commandline.style.overflow = "hidden"; commandline.insertBefore(hbox,document.getElementById('liberator-commandline-command')); document.getElementById('liberator-commandline-command').style.textAlign = "right"; document.getElementById('liberator-commandline-command').addEventListener("focus",function(e){ hbox.hidden = true; document.getElementById('liberator-commandline-command').style.textAlign = "left"; },true); document.getElementById('liberator-commandline-command').addEventListener("blur",function(e){ hbox.hidden = false; document.getElementById('liberator-commandline-command').style.textAlign = "right"; },true); checkTimeline(); updateTimeline(); setInterval(function() checkTimeline(Date.now() - checkTime - 3),checkTime); setInterval(updateTimeline,updateTime); function favoriteStatus(id){ var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function(){ if(xhr.readyState == 4 && xhr.status != 200) liberator.echoerr("Twitter Viewer: faild to favorite"); }; xhr.open("GET","http://twitter.com/favourings/create/" + id,true,username,password); xhr.send(null); } function checkTimeline(since){ var req = "http://twitter.com/statuses/friends_timeline.json"; if(typeof since == "number") since = new Date(since); if(since){ req += "?since=" + encodeURIComponent(since.toUTCString()); } var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function(){ if(xhr.readyState != 4) return; if(xhr.status != 200){ liberator.echoerr("Twitter Viewer: failed"); } var response = window.eval(xhr.responseText); liberator.plugins.statuses = statuses = statuses.concat(response.filter(function(r) !statuses.some(function(status) status.id == r.id))); }; //xhr.setRequestHeader("X-Twitter-Client","Vimperator"); //xhr.setRequestHeader("X-Twitter-Client-Version",""); //xhr.setRequestHeader("X-Twitter-Client-URL",""); //xhr.setRequestHeader("If-Modified-Since",""); xhr.open("GET",req,true,username,password); xhr.send(null); } function updateTimeline(){ if(statuses.length > 0 && !hbox.hidden){ lastestStatus = statuses.shift(); statusPanel.value = lastestStatus.user.screen_name + " : " + lastestStatus.text; statusPanel.setAttribute('tooltiptext',lastestStatus.user.screen_name + " : " + lastestStatus.text); iconPanel.setAttribute('src',lastestStatus.user.profile_image_url); iconPanel.setAttribute('tooltiptext',lastestStatus.user.screen_name); } } liberator.modules.mappings.add([liberator.modules.modes.NORMAL],[",r"], "Reply to current user", function (){ liberator.modules.commandline.open(":","twitter @" + lastestStatus.user.screen_name + " ",liberator.modules.modes.EX); }); liberator.modules.mappings.add([liberator.modules.modes.NORMAL],[",f"], "Favorite to current user", function (){ favoriteStatus(lastestStatus.id); }); })(); // vim: fdm=marker sw=4 ts=4 et: