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