WME Fix UI

Allows alterations to the WME UI to fix things screwed up or ignored by Waze

当前为 2016-05-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name WME Fix UI
  3. // @namespace https://greasyfork.org/en/users/46070
  4. // @description Allows alterations to the WME UI to fix things screwed up or ignored by Waze
  5. // @include https://www.waze.com/editor/*
  6. // @include https://www.waze.com/*/editor/*
  7. // @include https://editor-beta.waze.com/*
  8. // @version 0.2
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function()
  13. {
  14. // global variables
  15. var wmefu_version = "0.2";
  16. var applyCount = 0;
  17. var wmefuinit = false;
  18.  
  19. function initialiseFixUI() {
  20. if (wmefuinit) {
  21. return;
  22. }
  23.  
  24. // go round again if map container isn't there yet
  25. if(!window.Waze.map)
  26. {
  27. window.console.log("WME FixUI: waiting for WME...");
  28. setTimeout(initialiseFixUI, 1000);
  29. return;
  30. }
  31.  
  32. //create styles that will be used later
  33. addGlobalStyle('.olControlPanZoomBarFU { left: 10px; top: 9px; }');
  34.  
  35. // create tab contents
  36. var addon = document.createElement('section');
  37. addon.id = "wmefu-addon";
  38. var section = document.createElement('p');
  39. section.style.paddingTop = "0px";
  40. section.id = "fuContent";
  41. section.innerHTML = '<b>UI Fixes</b><br>';
  42. section.innerHTML += '<input type="checkbox" id="_cbMoveZoomBar" title="Move zoom bar" /> ' +
  43. '<span title="Because nobody likes a pointless UI change that breaks your workflow, imposed by idiots who rarely use the editor and don\'t listen to feedback">Move zoom bar to left</span><br>';
  44. section.innerHTML += '<br>';
  45. section.innerHTML += '<b><a href="https://greasyfork.org/en/scripts/20077-wme-fix-ui" target="_blank"><u>'
  46. + 'WME Fix UI</u></a></b> &nbsp; v' + wmefu_version;
  47.  
  48. addon.appendChild(section);
  49.  
  50. // insert the content as a tab
  51. var userTabs = getId('user-info');
  52. var navTabs = getElementsByClassName('nav-tabs', userTabs)[0];
  53. var tabContent = getElementsByClassName('tab-content', userTabs)[0];
  54.  
  55. if (typeof navTabs === "undefined") {
  56. console.log("WMEFU: not logged in - will initialise later");
  57. Waze.loginManager.on("login", initialiseFixUI);
  58. return;
  59. }
  60. newtab = document.createElement('li');
  61. newtab.innerHTML = '<a href="#sidepanel-FixUI" data-toggle="tab">FU</a>';
  62. navTabs.appendChild(newtab);
  63.  
  64. addon.id = "sidepanel-FixUI";
  65. addon.className = "tab-pane";
  66. tabContent.appendChild(addon);
  67.  
  68. // setup event handlers for user actions:
  69. getId('_cbMoveZoomBar').onclick = moveZoomBar;
  70.  
  71.  
  72. // restore saved settings
  73. if (localStorage.WMEFixUI) {
  74. console.log("WMEFU: loading options");
  75. options = JSON.parse(localStorage.WMEFixUI);
  76.  
  77. getId('_cbMoveZoomBar').checked = options[1];
  78. } else {
  79. getId('_cbMoveZoomBar').checked = true;
  80. }
  81.  
  82. // overload the WME exit function
  83. saveOptions = function() {
  84. if (localStorage) {
  85. console.log("WMEFU: saving options");
  86. var options = [];
  87.  
  88. // preserve previous options which may get lost after logout
  89. if (localStorage.WMEFixUI)
  90. options = JSON.parse(localStorage.WMEFixUI);
  91.  
  92. options[1] = getId('_cbMoveZoomBar').checked;
  93.  
  94. localStorage.WMEFixUI = JSON.stringify(options);
  95. }
  96. };
  97. window.addEventListener("beforeunload", saveOptions, false);
  98.  
  99. // apply the settings
  100. setTimeout(applyAllSettings, 2000);
  101. wmefuinit = true;
  102. window.console.log("WMEFU: Initialised");
  103. }
  104.  
  105. function applyAllSettings() {
  106. applyCount += 1;
  107. if (applyCount < 5) {
  108. setTimeout(applyAllSettings, 2000);
  109. }
  110. moveZoomBar();
  111. }
  112.  
  113. function moveZoomBar() {
  114. var wmap = getId('WazeMap');
  115. var WMETBZLI = getId('WMETB_ZoomLevelIndicator');
  116. var zoombar;
  117. var reportPanel = getId('panel-container');
  118. if (_cbMoveZoomBar.checked) {
  119. zoomBar = getElementsByClassName('olControlPanZoomBar', wmap)[0];
  120. if (zoomBar) zoomBar.className = zoomBar.className.replace( /(?:^|\s)olControlPanZoomBar(?!\S)/g , 'olControlPanZoomBarFU' );
  121. if (reportPanel) {
  122. reportPanel.style.left = "70px";
  123. reportPanel.style.position = "absolute";
  124. }
  125. if (WMETBZLI) {
  126. WMETBZLI.style.left = "50px";
  127. WMETBZLI.style.right = "";
  128. }
  129. } else {
  130. zoomBar = getElementsByClassName('olControlPanZoomBarFU', wmap)[0];
  131. if (zoomBar) zoomBar.className = zoomBar.className.replace( /(?:^|\s)olControlPanZoomBarFU(?!\S)/g , 'olControlPanZoomBar' );
  132. if (reportPanel) {
  133. reportPanel.style.left = "";
  134. reportPanel.style.position = "";
  135. }
  136. if (WMETBZLI) {
  137. WMETBZLI.style.left = "";
  138. WMETBZLI.style.right = "50px";
  139. }
  140. }
  141. }
  142.  
  143. //Helper functions
  144.  
  145. function addGlobalStyle(css) {
  146. var head, style;
  147. head = document.getElementsByTagName('head')[0];
  148. if (!head) {
  149. return;
  150. }
  151. style = document.createElement('style');
  152. style.type = 'text/css';
  153. style.innerHTML = css;
  154. head.appendChild(style);
  155. }
  156.  
  157. function getElementsByClassName(classname, node) {
  158. if(!node) node = document.getElementsByTagName("body")[0];
  159. var a = [];
  160. var re = new RegExp('\\b' + classname + '\\b');
  161. var els = node.getElementsByTagName("*");
  162. for (var i=0,j=els.length; i<j; i++)
  163. if (re.test(els[i].className)) a.push(els[i]);
  164. return a;
  165. }
  166.  
  167. function getId(node) {
  168. return document.getElementById(node);
  169. }
  170.  
  171. // Start it running
  172. setTimeout(initialiseFixUI, 1000);
  173.  
  174. })();