WME Fix UI

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

目前為 2016-06-08 提交的版本,檢視 最新版本

  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.5
  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.5";
  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 += '<input type="checkbox" id="_cbRestyleReports" /> ' +
  56. '<span title="Another UI element configured for developers with massive screens instead of normal users">Change formatting for report panels (UR/MP)</span><br>';
  57. section.innerHTML += '<br>';
  58. section.innerHTML += '<b><a href="https://greasyfork.org/en/scripts/20077-wme-fix-ui" target="_blank"><u>' +
  59. 'WME Fix UI</u></a></b> &nbsp; v' + wmefu_version;
  60.  
  61. addon.appendChild(section);
  62.  
  63. // insert the content as a tab
  64. var userTabs = getId('user-info');
  65. var navTabs = getElementsByClassName('nav-tabs', userTabs)[0];
  66. var tabContent = getElementsByClassName('tab-content', userTabs)[0];
  67.  
  68. if (typeof navTabs === "undefined") {
  69. console.log("WMEFU: not logged in - will initialise later");
  70. Waze.loginManager.on("login", initialiseFixUI);
  71. return;
  72. }
  73. newtab = document.createElement('li');
  74. newtab.innerHTML = '<a href="#sidepanel-FixUI" data-toggle="tab" title="Fix UI">FU</a>';
  75. navTabs.appendChild(newtab);
  76.  
  77. addon.id = "sidepanel-FixUI";
  78. addon.className = "tab-pane";
  79. tabContent.appendChild(addon);
  80.  
  81.  
  82. // setup event handlers for user actions:
  83. getId('_cbMoveZoomBar').onclick = moveZoomBar;
  84. getId('_cbShrinkBlackBar').onclick = shrinkBlackBar;
  85. getId('_cbHideUserInfo').onclick = hideUserInfo;
  86. getId('_cbCompressSegmentTab').onclick = compressSegmentTab;
  87. getId('_cbRestyleReports').onclick = restyleReports;
  88.  
  89. // restore saved settings
  90. if (localStorage.WMEFixUI) {
  91. console.log("WMEFU: loading options");
  92. options = JSON.parse(localStorage.WMEFixUI);
  93.  
  94. getId('_cbMoveZoomBar').checked = options[1];
  95. getId('_cbShrinkBlackBar').checked = options[2];
  96. getId('_cbHideUserInfo').checked = options[3];
  97. getId('_cbCompressSegmentTab').checked = options[4];
  98. getId('_cbRestyleReports').checked = options[5];
  99. } else {
  100. getId('_cbMoveZoomBar').checked = true;
  101. getId('_cbShrinkBlackBar').checked = true;
  102. getId('_cbHideUserInfo').checked = true;
  103. getId('_cbCompressSegmentTab').checked = true;
  104. getId('_cbRestyleReports').checked = true;
  105. }
  106.  
  107. if (W.loginManager.user.userName == 'iainhouse') {
  108. // Adds an extra checkbox so I can test segment panel changes easily
  109. var brand = getId('brand');
  110. extraCBSection = document.createElement('p');
  111. extraCBSection.innerHTML = '<input type="checkbox" id="_cbextraCBSection" />';
  112. brand.appendChild(extraCBSection);
  113. getId('_cbextraCBSection').onclick = FALSEcompressSegmentTab;
  114. _cbextraCBSection.checked = _cbCompressSegmentTab.checked;
  115. }
  116.  
  117. // overload the WME exit function
  118. saveOptions = function() {
  119. if (localStorage) {
  120. console.log("WMEFU: saving options");
  121. var options = [];
  122.  
  123. // preserve previous options which may get lost after logout
  124. if (localStorage.WMEFixUI)
  125. options = JSON.parse(localStorage.WMEFixUI);
  126.  
  127. options[1] = getId('_cbMoveZoomBar').checked;
  128. options[2] = getId('_cbShrinkBlackBar').checked;
  129. options[3] = getId('_cbHideUserInfo').checked;
  130. options[4] = getId('_cbCompressSegmentTab').checked;
  131. options[5] = getId('_cbRestyleReports').checked;
  132.  
  133. localStorage.WMEFixUI = JSON.stringify(options);
  134. }
  135. };
  136. window.addEventListener("beforeunload", saveOptions, false);
  137.  
  138. // apply the settings
  139. setTimeout(applyAllSettings, 2000);
  140. wmefuinit = true;
  141. window.console.log("WMEFU: Initialised");
  142. }
  143.  
  144. function applyAllSettings() {
  145. applyCount += 1;
  146. if (applyCount < 5) {
  147. setTimeout(applyAllSettings, 2000);
  148. }
  149. moveZoomBar();
  150. shrinkBlackBar();
  151. hideUserInfo();
  152. compressSegmentTab();
  153. restyleReports();
  154. }
  155.  
  156. function moveZoomBar() {
  157. var WMETBZLI = getId('WMETB_ZoomLevelIndicator');
  158. var reportPanel = getId('panel-container');
  159. reportPanel.style.position = "absolute";
  160. if (_cbMoveZoomBar.checked) {
  161. $(".olControlPanZoomBar").css({'left':10,'width':30,'right':""});
  162. if (reportPanel) {
  163. if (document.body.dir == "rtl") {
  164. reportPanel.style.right = "inherit";
  165. } else {
  166. reportPanel.style.left = "40px";
  167. if (WMETBZLI) {
  168. if( WMETBZLI.style.display != "none" ) reportPanel.style.left = "70px";
  169. }
  170. }
  171. }
  172. if (WMETBZLI) {
  173. WMETBZLI.style.left = "50px";
  174. WMETBZLI.style.right = "inherit";
  175. }
  176. } else {
  177. $(".olControlPanZoomBar").css({'left':"",'width':30,'right':10});
  178. if (reportPanel) {
  179. if (document.body.dir == "rtl") {
  180. reportPanel.style.right = "40px";
  181. if (WMETBZLI) {
  182. if( WMETBZLI.style.display != "none" ) reportPanel.style.right = "70px";
  183. }
  184. } else {
  185. reportPanel.style.left = "inherit";
  186. }
  187. }
  188. if (WMETBZLI) {
  189. WMETBZLI.style.left = "inherit";
  190. WMETBZLI.style.right = "50px";
  191. }
  192. }
  193. }
  194.  
  195. function hideUserInfo() {
  196. var PSButton = getId('WMEPS_UIButton');
  197. var userbox = getId('user-box');
  198. // WME Panel Swap button - move it up off the tabs if user info is hidden
  199. if (_cbHideUserInfo.checked) {
  200. userbox.style.padding = '0px';
  201. $(".user-profile").css({'display':'none'});
  202. if (PSButton) PSButton.style.top = '-20px';
  203. } else {
  204. userbox.style.padding = '20px';
  205. $(".user-profile").css({'display':'block'});
  206. if (PSButton) PSButton.style.top = '10px';
  207. }
  208. }
  209.  
  210. function shrinkBlackBar() {
  211. var wm = getId('WazeMap');
  212. if (_cbShrinkBlackBar.checked) {
  213. $(".topbar").css({'height':'20px','line-height':'20px','padding':'0 10px'});
  214. $(".topbar .location-info").css({'font-size':'12px'});
  215. if (!shrinkBlackBarActive) wm.style.height = (wm.offsetHeight + 10) + 'px';
  216. } else {
  217. $(".topbar").css({'height':'30px','line-height':'30px','padding':'0 10px'});
  218. $(".topbar .location-info").css({'font-size':'15px'});
  219. if (shrinkBlackBarActive) wm.style.height = (wm.offsetHeight - 10) + 'px';
  220. }
  221. shrinkBlackBarActive = _cbShrinkBlackBar.checked;
  222. }
  223.  
  224. function FALSEcompressSegmentTab() {
  225. _cbCompressSegmentTab.checked = _cbextraCBSection.checked;
  226. compressSegmentTab();
  227. }
  228.  
  229. function compressSegmentTab() {
  230. var ep=getId('edit-panel');
  231. if (_cbCompressSegmentTab.checked) {
  232. if (!compressSegmentTabActive) {
  233. // shrink address
  234. addGlobalStyle('#edit-panel .primary-street { font-size: 13px; line-height: 15px; }');
  235. addGlobalStyle('#edit-panel .address-edit-view .preview .address-edit-btn:not(.disabled) { background-color: yellow; }');
  236. addGlobalStyle('#edit-panel .segment .address-edit-view, .edit-panel .segment .address-edit-view { margin-bottom: 5px; }');
  237. //shrink tabs
  238. addGlobalStyle('#sidebar .nav-tabs li a { padding: 4px; }');
  239. addGlobalStyle('#sidebar .nav-tabs { margin-bottom: 5px; }');
  240. //reduce some vertical margins
  241. addGlobalStyle('#edit-panel .contents { padding-top: 0px; }');
  242. addGlobalStyle('#edit-panel .form-group { margin-bottom: 2px; line-height: 1; font-size: 11px; }');
  243. addGlobalStyle('#edit-panel .selection { margin-bottom: 5px; }');
  244. addGlobalStyle('#sidebar .side-panel-section:not(:last-child) { margin-bottom: 2px; }');
  245. addGlobalStyle('#sidebar .side-panel-section:not(:last-child)::after { margin-top: 5px; margin-bottom: 2px; }');
  246. addGlobalStyle('#edit-panel .control-label { margin-bottom: 1px; }');
  247. addGlobalStyle('#sidebar .controls-container { padding-top: 2px; }');
  248. addGlobalStyle('#edit-panel .segment .speed-limit label { margin-bottom: 0px }');
  249. addGlobalStyle('#edit-panel .more-actions { padding-top: 2px }');
  250. addGlobalStyle('#edit-panel .segment .speed-limit .direction-label, #edit-panel .segment .speed-limit .unit-label { line-height: 2.1em }');
  251.  
  252. //shrink dropdown controls & buttons
  253. addGlobalStyle('#edit-panel button, #edit-panel select, #edit-panel .form-control { font-size: 11px; height: 22px; padding: 0px 12px; }');
  254. addGlobalStyle('#edit-panel .more-actions button:not(:last-of-type) { margin-bottom: 2px; }');
  255. //fit road property checkboxes on one line for all three (if text length allows)
  256. addGlobalStyle('#edit-panel .controls-container { display: inline-block; }');
  257. addGlobalStyle('#edit-panel .controls-container label { font-size: 12px; line-height: 18px; padding-left: 22px; }');
  258. }
  259. } else {
  260. if (compressSegmentTabActive) {
  261. //enlarge address
  262. addGlobalStyle('#edit-panel .primary-street { font-size: 18px; line-height: 24px; }');
  263. addGlobalStyle('#edit-panel .address-edit-view .preview .address-edit-btn:not(.disabled) { background-color: inherit; }');
  264. addGlobalStyle('#edit-panel .segment .address-edit-view, .edit-panel .segment .address-edit-view { margin-bottom: 20px; }');
  265. //enlarge tabs
  266. addGlobalStyle('#sidebar .nav-tabs li a { padding: 5px 15px; }');
  267. addGlobalStyle('#sidebar .nav-tabs { margin-bottom: 20px; }');
  268. //restore vertical margins
  269. addGlobalStyle('#edit-panel .contents { padding-top: 20px }');
  270. addGlobalStyle('#edit-panel .form-group { margin-bottom: 10px; line-height: 1.43; font-size: 13px; }');
  271. addGlobalStyle('#edit-panel .selection { margin-bottom: 20px; }');
  272. addGlobalStyle('#sidebar .side-panel-section:not(:last-child) { margin-bottom: 21px; }');
  273. addGlobalStyle('#sidebar .side-panel-section:not(:last-child)::after { margin-top: 21px; margin-bottom: 21px; }');
  274. addGlobalStyle('#edit-panel .control-label { margin-bottom: 5px; }');
  275. addGlobalStyle('#sidebar .controls-container { padding-top: 7px; }');
  276. addGlobalStyle('#edit-panel .segment .speed-limit label { margin-bottom: 5px }');
  277. addGlobalStyle('#edit-panel .more-actions { padding-top: 10px }');
  278. addGlobalStyle('#edit-panel .segment .speed-limit .direction-label, #edit-panel .segment .speed-limit .unit-label { line-height: 2.5em }');
  279. //enlarge dropdown controls & buttons
  280. addGlobalStyle('#edit-panel button, #edit-panel select, #edit-panel .form-control { font-size: 13px; height: 32px; padding: 6px 12px; }');
  281. addGlobalStyle('#edit-panel .more-actions button:not(:last-of-type) { margin-bottom: 100px; }');
  282. //restore road property checkboxes to one line per item
  283. addGlobalStyle('#edit-panel .controls-container { display: inherit; }');
  284. addGlobalStyle('#edit-panel .controls-container label { font-size: inherit; line-height: inherit; padding-left: 25px; }');
  285. }
  286. }
  287. //tweak required if Speedhelper script is installed
  288. addGlobalStyle('div[id^="spd_"] { line-height: 1.43 }');
  289. compressSegmentTabActive = _cbCompressSegmentTab.checked
  290. }
  291.  
  292. function restyleReports() {
  293. var WMEFP = getId('WMEFP-UR-ALLPM');
  294. if (_cbRestyleReports.checked) {
  295. //do stuff
  296. addGlobalStyle('#panel-container .panel { font-size: 12px; line=height: 1; }');
  297. addGlobalStyle('#panel-container .problem-edit .header { padding: 5px 10px; line-height: 15px; }');
  298. addGlobalStyle('#panel-container .problem-edit .problem-data .title { line-height: 22px; }');
  299. if (WMEFP) WMEFP.style.top = '-2px'; //tweak Fancy permalink button
  300. addGlobalStyle('#panel-container .problem-edit .conversation.section .new-comment-form { padding: 5px; }');
  301. addGlobalStyle('#panel-container .problem-edit .conversation.section .new-comment-form textarea { resize: vertical; height: 110px; margin-bottom: 5px; padding: 3px 5px; font-size: 12px; }');
  302. addGlobalStyle('#panel-container .btn { height: 20px; padding: 0px 10px;}');
  303. addGlobalStyle('#panel-container .problem-edit .actions .content { padding: 2px 5px;}');
  304. addGlobalStyle('#panel-container .problem-edit .actions .controls-container label { margin-bottom: 2px; }');
  305. } else {
  306. //undo stuff
  307. addGlobalStyle('#panel-container .panel { font-size: inherit; line=height: inherit; }');
  308. addGlobalStyle('#panel-container .problem-edit .header { padding: 10px 15px; line-height: 21px; }');
  309. addGlobalStyle('#panel-container .problem-edit .problem-data .title { line-height: 40px; }');
  310. if (WMEFP) WMEFP.style.top = '10px'; //un-tweak Fancy permalink button
  311. addGlobalStyle('#panel-container .problem-edit .conversation.section .new-comment-form { padding: 15px 15px 10px 15px; }');
  312. addGlobalStyle('#panel-container .problem-edit .conversation.section .new-comment-form textarea { resize: none; height: 70px; margin-bottom: 10px; padding: 6px 10px; font-size: 13px; }');
  313. addGlobalStyle('#panel-container .btn { height: inherit; padding: 6px 20px;}');
  314. addGlobalStyle('#panel-container .problem-edit .actions .content { padding: 15px;}');
  315. addGlobalStyle('#panel-container .problem-edit .actions .controls-container label { margin-bottom: 12px; }');
  316. }
  317. }
  318.  
  319. //Helper functions
  320.  
  321. function addGlobalStyle(css) {
  322. var head, style;
  323. head = document.getElementsByTagName('head')[0];
  324. if (!head) {
  325. return;
  326. }
  327. style = document.createElement('style');
  328. style.type = 'text/css';
  329. style.innerHTML = css;
  330. head.appendChild(style);
  331. }
  332.  
  333. function getElementsByClassName(classname, node) {
  334. if(!node) node = document.getElementsByTagName("body")[0];
  335. var a = [];
  336. var re = new RegExp('\\b' + classname + '\\b');
  337. var els = node.getElementsByTagName("*");
  338. for (var i=0,j=els.length; i<j; i++)
  339. if (re.test(els[i].className)) a.push(els[i]);
  340. return a;
  341. }
  342.  
  343. function getId(node) {
  344. return document.getElementById(node);
  345. }
  346.  
  347. // Start it running
  348. setTimeout(initialiseFixUI, 1000);
  349.  
  350. })();