WME Fix UI

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

当前为 2016-06-03 提交的版本,查看 最新版本

  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. // @exclude https://www.waze.com/user/editor/*
  9. // @supportURL https://www.waze.com/forum/viewtopic.php?f=819&t=191178
  10. // @version 0.3
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. // Thanks to (in no particular order) Bellhouse, Twister-UK, Timbones, Dave2084, Rickzabel
  15.  
  16. (function()
  17. {
  18. // global variables
  19. var wmefu_version = "0.3";
  20. var applyCount = 0;
  21. var wmefuinit = false;
  22. var shrinkBlackBarActive = false;
  23. var compressSegmentTabActive = false;
  24.  
  25. function initialiseFixUI() {
  26. if (wmefuinit) {
  27. return;
  28. }
  29.  
  30. // go round again if map container isn't there yet
  31. if(!window.Waze.map)
  32. {
  33. window.console.log("WME FixUI: waiting for WME...");
  34. setTimeout(initialiseFixUI, 1000);
  35. return;
  36. }
  37.  
  38. //create styles that will be used later
  39.  
  40. // create tab contents
  41. var addon = document.createElement('section');
  42. addon.id = "wmefu-addon";
  43. var section = document.createElement('p');
  44. section.style.paddingTop = "0px";
  45. section.id = "fuContent";
  46. section.innerHTML = '<b>UI Fixes</b><br>';
  47. section.innerHTML += '<input type="checkbox" id="_cbMoveZoomBar" /> ' +
  48. '<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>';
  49. section.innerHTML += '<input type="checkbox" id="_cbHideUserInfo" /> ' +
  50. '<span title="Because we can earn points quicker without a massive chunk of space wasted on telling us how many we earnt up to yesterday">Hide user info in the side panel</span><br>';
  51. section.innerHTML += '<input type="checkbox" id="_cbShrinkBlackBar" /> ' +
  52. '<span title="Because we can\'t afford to waste screen space on stuff we didn\'t ask for and don\'t want">Shrink the black bar above the map</span><br>';
  53. section.innerHTML += '<input type="checkbox" id="_cbCompressSegmentTab" /> ' +
  54. '<span title="Because I\'m sick of having to scroll the side panel because of oversized fonts and wasted space">Compress the contents of the side panel</span><br>';
  55. section.innerHTML += '<br>';
  56. section.innerHTML += '<b><a href="https://greasyfork.org/en/scripts/20077-wme-fix-ui" target="_blank"><u>'
  57. + 'WME Fix UI</u></a></b> &nbsp; v' + wmefu_version;
  58.  
  59. addon.appendChild(section);
  60.  
  61. // insert the content as a tab
  62. var userTabs = getId('user-info');
  63. var navTabs = getElementsByClassName('nav-tabs', userTabs)[0];
  64. var tabContent = getElementsByClassName('tab-content', userTabs)[0];
  65.  
  66. if (typeof navTabs === "undefined") {
  67. console.log("WMEFU: not logged in - will initialise later");
  68. Waze.loginManager.on("login", initialiseFixUI);
  69. return;
  70. }
  71. newtab = document.createElement('li');
  72. newtab.innerHTML = '<a href="#sidepanel-FixUI" data-toggle="tab">FU</a>';
  73. navTabs.appendChild(newtab);
  74.  
  75. addon.id = "sidepanel-FixUI";
  76. addon.className = "tab-pane";
  77. tabContent.appendChild(addon);
  78.  
  79.  
  80. // setup event handlers for user actions:
  81. getId('_cbMoveZoomBar').onclick = moveZoomBar;
  82. getId('_cbShrinkBlackBar').onclick = shrinkBlackBar;
  83. getId('_cbHideUserInfo').onclick = hideUserInfo;
  84. getId('_cbCompressSegmentTab').onclick = compressSegmentTab;
  85.  
  86. // restore saved settings
  87. if (localStorage.WMEFixUI) {
  88. console.log("WMEFU: loading options");
  89. options = JSON.parse(localStorage.WMEFixUI);
  90.  
  91. getId('_cbMoveZoomBar').checked = options[1];
  92. getId('_cbShrinkBlackBar').checked = options[2];
  93. getId('_cbHideUserInfo').checked = options[3];
  94. getId('_cbCompressSegmentTab').checked = options[4];
  95. } else {
  96. getId('_cbMoveZoomBar').checked = true;
  97. getId('_cbShrinkBlackBar').checked = true;
  98. getId('_cbHideUserInfo').checked = true;
  99. getId('_cbCompressSegmentTab').checked = true;
  100. }
  101.  
  102. if (W.loginManager.user.userName == 'iainhouse') {
  103. // Adds an extra checkbox so I can test segment panel changes easily
  104. var brand = getId('brand');
  105. extraCBSection = document.createElement('p');
  106. extraCBSection.innerHTML = '<input type="checkbox" id="_cbextraCBSection" />';
  107. brand.appendChild(extraCBSection);
  108. getId('_cbextraCBSection').onclick = FALSEcompressSegmentTab;
  109. _cbextraCBSection.checked = _cbCompressSegmentTab.checked;
  110. }
  111.  
  112. // overload the WME exit function
  113. saveOptions = function() {
  114. if (localStorage) {
  115. console.log("WMEFU: saving options");
  116. var options = [];
  117.  
  118. // preserve previous options which may get lost after logout
  119. if (localStorage.WMEFixUI)
  120. options = JSON.parse(localStorage.WMEFixUI);
  121.  
  122. options[1] = getId('_cbMoveZoomBar').checked;
  123. options[2] = getId('_cbShrinkBlackBar').checked;
  124. options[3] = getId('_cbHideUserInfo').checked;
  125. options[4] = getId('_cbCompressSegmentTab').checked;
  126.  
  127. localStorage.WMEFixUI = JSON.stringify(options);
  128. }
  129. };
  130. window.addEventListener("beforeunload", saveOptions, false);
  131.  
  132. // apply the settings
  133. setTimeout(applyAllSettings, 2000);
  134. wmefuinit = true;
  135. window.console.log("WMEFU: Initialised");
  136. }
  137.  
  138. function applyAllSettings() {
  139. applyCount += 1;
  140. if (applyCount < 5) {
  141. setTimeout(applyAllSettings, 2000);
  142. }
  143. moveZoomBar();
  144. shrinkBlackBar();
  145. hideUserInfo();
  146. compressSegmentTab();
  147. }
  148.  
  149. function moveZoomBar() {
  150. var WMETBZLI = getId('WMETB_ZoomLevelIndicator');
  151. var reportPanel = getId('panel-container');
  152. if (_cbMoveZoomBar.checked) {
  153. $(".olControlPanZoomBar").css({'left':10,'width':30,'right':""});
  154. if (reportPanel) {
  155. reportPanel.style.left = "70px";
  156. reportPanel.style.position = "absolute";
  157. }
  158. if (WMETBZLI) {
  159. WMETBZLI.style.left = "50px";
  160. WMETBZLI.style.right = "";
  161. }
  162. } else {
  163. $(".olControlPanZoomBar").css({'left':"",'width':30,'right':10});
  164. if (reportPanel) {
  165. reportPanel.style.left = "";
  166. reportPanel.style.position = "";
  167. }
  168. if (WMETBZLI) {
  169. WMETBZLI.style.left = "";
  170. WMETBZLI.style.right = "50px";
  171. }
  172. }
  173. }
  174.  
  175. function hideUserInfo() {
  176. var PSButton = getId('WMEPS_UIButton');
  177. var userbox = getId('user-box');
  178. // WME Panel Swap button - move it up off the tabs if user info is hidden
  179. if (_cbHideUserInfo.checked) {
  180. userbox.style.padding = '0px';
  181. $(".user-profile").css({'display':'none'});
  182. if (PSButton) PSButton.style.top = '-20px';
  183. } else {
  184. userbox.style.padding = '20px';
  185. $(".user-profile").css({'display':'block'});
  186. if (PSButton) PSButton.style.top = '10px';
  187. }
  188. }
  189.  
  190. function shrinkBlackBar() {
  191. var wm = getId('WazeMap');
  192. if (_cbShrinkBlackBar.checked) {
  193. $(".topbar").css({'height':'20px','line-height':'20px','padding':'0 10px'});
  194. $(".topbar .location-info").css({'font-size':'12px'});
  195. if (!shrinkBlackBarActive) wm.style.height = (wm.offsetHeight + 10) + 'px';
  196. } else {
  197. $(".topbar").css({'height':'30px','line-height':'30px','padding':'0 10px'});
  198. $(".topbar .location-info").css({'font-size':'15px'});
  199. if (shrinkBlackBarActive) wm.style.height = (wm.offsetHeight - 10) + 'px';
  200. }
  201. shrinkBlackBarActive = _cbShrinkBlackBar.checked;
  202. }
  203.  
  204. function FALSEcompressSegmentTab() {
  205. _cbCompressSegmentTab.checked = _cbextraCBSection.checked;
  206. compressSegmentTab();
  207. }
  208.  
  209. function compressSegmentTab() {
  210. var ep=getId('edit-panel')
  211. if (_cbCompressSegmentTab.checked) {
  212. if (!compressSegmentTabActive) {
  213. // shrink address
  214. addGlobalStyle('.primary-street { font-size: 13px; line-height: 15px; }');
  215. addGlobalStyle('.address-edit { margin-bottom: 5px !important; }');
  216. //shrink tabs
  217. addGlobalStyle('.nav > li > a { padding: 4px !important; }');
  218. //reduce some vertical margins
  219. addGlobalStyle('.contents { padding-top: 0px !important; }');
  220. addGlobalStyle('.form-group { margin-bottom: 2px !important; line-height: 1; font-size: 11px; }');
  221. addGlobalStyle('.selection { margin-bottom: 5px !important; }');
  222. addGlobalStyle('.side-panel-section { margin-bottom: 5px !important; }');
  223. addGlobalStyle('.side-panel-section::after { margin-top: 5px !important; margin-bottom: 2px !important; }');
  224. addGlobalStyle('.control-label { margin-bottom: 1px !important; }');
  225. //shrink dropdown controls
  226. addGlobalStyle('.form-control { height: 22px !important; padding: 0px 12px !important; font-size: 11px; }');
  227. //shrink button controls
  228. addGlobalStyle('.action-button { font-size: 11px; height: 22px; padding: 0px 12px; margin-bottom: 2px !important; }');
  229. }
  230. } else {
  231. if (compressSegmentTabActive) {
  232. //enlarge address
  233. addGlobalStyle('.primary-street { font-size: 18px; line-height: 24px; }');
  234. addGlobalStyle('.address-edit { margin-bottom: 20px !important; }');
  235. //enlarge tabs
  236. addGlobalStyle('.nav > li > a { padding: 5px 15px !important; }');
  237. //restore vertical margins
  238. addGlobalStyle('.contents { padding-top: 20px !important; }');
  239. addGlobalStyle('.form-group { margin-bottom: 10px !important; line-height: 1.43; font-size: 13px; }');
  240. addGlobalStyle('.selection { margin-bottom: 20px !important; }');
  241. addGlobalStyle('.side-panel-section { margin-bottom: 21px !important; }');
  242. addGlobalStyle('.side-panel-section::after { margin-top: 21px !important; margin-bottom: 21px !important; }');
  243. addGlobalStyle('.control-label { margin-bottom: 5px !important; }');
  244. //enlarge dropdown controls
  245. addGlobalStyle('.form-control { height: 32px !important; padding: 6px 12px !important; font-size: 13px; }');
  246. //enlarge button controls
  247. addGlobalStyle('.action-button { font-size: 13px; height: 32px; padding: 6px 12px; margin-bottom: 10px !important; }');
  248. }
  249. }
  250. compressSegmentTabActive = _cbCompressSegmentTab.checked
  251. }
  252.  
  253.  
  254. //Helper functions
  255.  
  256. function addGlobalStyle(css) {
  257. var head, style;
  258. head = document.getElementsByTagName('head')[0];
  259. if (!head) {
  260. return;
  261. }
  262. style = document.createElement('style');
  263. style.type = 'text/css';
  264. style.innerHTML = css;
  265. head.appendChild(style);
  266. }
  267.  
  268. function getElementsByClassName(classname, node) {
  269. if(!node) node = document.getElementsByTagName("body")[0];
  270. var a = [];
  271. var re = new RegExp('\\b' + classname + '\\b');
  272. var els = node.getElementsByTagName("*");
  273. for (var i=0,j=els.length; i<j; i++)
  274. if (re.test(els[i].className)) a.push(els[i]);
  275. return a;
  276. }
  277.  
  278. function getId(node) {
  279. return document.getElementById(node);
  280. }
  281.  
  282. // Start it running
  283. setTimeout(initialiseFixUI, 1000);
  284.  
  285. })();