PageRenderTime 24ms CodeModel.GetById 12ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/CVox/res/raw/wikipedia.js

http://eyes-free.googlecode.com/
JavaScript | 94 lines | 65 code | 23 blank | 6 comment | 8 complexity | 7e78197fd488b549c641ee9ac2c497a4 MD5 | raw file
 1
 2// ==UserScript==
 3// @name          Optimize Wikipedia and view coordinates in Maps and Radar
 4// @description   Hide navigation bars to optimize for mobile screens and link coordinates from articles to Maps and Radar apps.
 5// @author        Jeffrey Sharkey
 6// @include       http://*wikipedia.org/wiki/*
 7// ==/UserScript==
 8
 9
10function hideByClass(tag, className) {
11	var items = document.body.getElementsByTagName(tag);
12	for(i in items) {
13		var item = items[i];
14		if(typeof item.className !== 'string') continue;
15		if(item.className.indexOf(className) != -1)
16			item.style.display = 'none';
17	}
18}
19
20function hideById(id) {
21	var target = document.getElementById(id);
22	target.style.display = 'none';
23}
24
25var content = document.getElementById('content');
26content.style.padding = '0px';
27content.style.margin = '0px';
28
29hideByClass('table','ambox');
30
31hideById('column-one');
32hideById('siteNotice');
33hideById('toc');
34
35
36
37
38
39function getElementByClass(parent, tag, className) {
40	var items = parent.getElementsByTagName(tag);
41	var answer = [];
42	for(i in items) {
43		var item = items[i];
44		if(typeof item.className !== 'string') continue;
45		if(item.className.indexOf(className) != -1)
46			answer.push(item);
47	}
48	return answer;
49}
50
51function createButton(title) {
52	var button = document.createElement('input');
53	button.type = 'button';
54	button.value = title;
55	button.style.background = '#cfc';
56	button.style.color = '#484';
57	button.style.border = '1px solid #484';
58	button.style.padding = '5px';
59	button.style.marginLeft = '10px';
60	return button;
61}
62
63
64var coords = document.getElementById('coordinates');
65var dec = getElementByClass(coords, 'span', 'geo-dec')[0];
66var lat = parseFloat(getElementByClass(dec, 'span', 'latitude')[0].textContent);
67var lon = parseFloat(getElementByClass(dec, 'span', 'longitude')[0].textContent);
68
69coords.appendChild(document.createElement('br'));
70
71var maps = createButton('View in Maps');
72maps.addEventListener('click', function(event) {
73	window.intentHelper.startActivity(JSON.stringify({
74		action:'ACTION_VIEW',
75		data:'geo:'+lat+','+lon+'?z=14'
76	}));
77}, false);
78coords.appendChild(maps);
79
80
81var radar = createButton('Find using Radar');
82radar.addEventListener('click', function(event) {
83	window.intentHelper.startActivity(JSON.stringify({
84		action:'com.google.android.radar.SHOW_RADAR',
85		category:['CATEGORY_DEFAULT'],
86		'latitude':lat,
87		'longitude':lon
88	}));
89}, false);
90coords.appendChild(radar);
91
92
93
94