WME Fix UI

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

当前为 2016-11-21 提交的版本,查看 最新版本

  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://editor-beta.waze.com/*
  7. // @include https://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 1.5.3
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. // Thanks to (in no particular order)
  15. // Bellhouse, Twister-UK, Timbones, Dave2084, Rickzabel, Glodenox,
  16. // JJohnston84, SAR85, Cardyin
  17.  
  18. (function()
  19. {
  20. // global variables
  21. var wmefu_version = "1.5.3";
  22. var prefix = "WMEFU";
  23. var tabAttempts = 0;
  24. var wmeFUAddon;
  25. var debug = false;
  26. var wmeFUinitialising = true;
  27. var ASCBox;
  28. //Fix for date/time formats in WME released Oct/Nov 2016 - provided by Glodenox
  29. I18n.translations[I18n.currentLocale()].time = {};
  30. I18n.translations[I18n.currentLocale()].time.formats = {};
  31. I18n.translations[I18n.currentLocale()].time.formats.long = "%a %b %d %Y, %H:%M";
  32. I18n.translations[I18n.currentLocale()].date.formats = {};
  33. I18n.translations[I18n.currentLocale()].date.formats.long = "%a %b %d %Y, %H:%M";
  34. I18n.translations[I18n.currentLocale()].date.formats.default = "%a %b %d %Y";
  35.  
  36. function init1() {
  37. console.group(prefix + ": initialising...");
  38. console.time(prefix + ": initialisation time");
  39. logit("Starting init1","debug");
  40. // go round again if map container isn't there yet
  41. if(!window.Waze.map) {
  42. logit("waiting for WME...","warning");
  43. setTimeout(init1, 200);
  44. return;
  45. }
  46. // create tab content and store it
  47. wmeFUAddon = createAddon();
  48. // insert the content as a tab
  49. addMyTab(null,0);
  50. //pass control to init2
  51. init2();
  52. }
  53.  
  54. function init2() {
  55. logit("Starting init2","debug");
  56. //go round again if my tab isn't there yet
  57. if (!getId('sidepanel-FixUI')) {
  58. logit("Waiting for my tab to appear...","warning");
  59. setTimeout(init2, 200);
  60. return;
  61. }
  62. // setup event handlers for user actions:
  63. getId('_cbMoveZoomBar').onclick = moveZoomBar;
  64. getId('_cbShrinkTopBars').onclick = shrinkTopBars;
  65. getId('_cbHideUserInfo').onclick = hideUserInfo;
  66. getId('_cbCompressSegmentTab').onclick = compressSegmentTab;
  67. getId('_cbRestyleReports').onclick = restyleReports;
  68. getId('_cbDisableMapBlocker').onclick = disableMapBlocker;
  69. getId('_cbNarrowSidePanel').onclick = narrowSidePanel;
  70. getId('_cbHideAveSpeedControls').onclick = hideAveSpeedControls;
  71. getId('_cbAddZoomIndicator').onclick = addZoomIndicator;
  72. getId('_cbFixExternalProviders').onclick = fixExternalProviders;
  73.  
  74. // set event to recreate my tab when MTE mode is exited
  75. Waze.app.modeController.model.bind('change:mode', addMyTab);
  76. // events for Aerial Shifter
  77. Waze.map.events.register("zoomend", null, shiftAerials);
  78. Waze.map.events.register("moveend", null, shiftAerials);
  79. Waze.map.baseLayer.events.register("loadend", null, shiftAerials);
  80. getId("_inpASX").onchange = shiftAerials;
  81. getId("_inpASX").onwheel = shiftAerials;
  82. getId("_inpASY").onchange = shiftAerials;
  83. getId("_inpASY").onwheel = shiftAerials;
  84. getId("_inpASO").onchange = shiftAerials;
  85. getId("_inpASO").onwheel = shiftAerials;
  86. getId("_resetAS").onclick = function() {
  87. _inpASX.value = 0;
  88. _inpASY.value = 0;
  89. shiftAerials();
  90. };
  91. // set event to deal with ASC controls
  92. Waze.selectionManager.events.register("selectionchanged", null, hideAveSpeedControls);
  93.  
  94. // restore saved settings
  95. if (localStorage.WMEFixUI) {
  96. logit("loading options from local storage");
  97. options = JSON.parse(localStorage.WMEFixUI);
  98. getId('_cbMoveZoomBar').checked = options[1];
  99. getId('_cbShrinkTopBars').checked = options[2];
  100. getId('_cbHideUserInfo').checked = options[3];
  101. getId('_cbCompressSegmentTab').checked = options[4];
  102. getId('_cbRestyleReports').checked = options[5];
  103. getId('_cbDisableMapBlocker').checked = options[6];
  104. getId('_cbNarrowSidePanel').checked = options[7];
  105. getId('_cbHideAveSpeedControls').checked = options[8];
  106. getId('_cbAddZoomIndicator').checked = options[9];
  107. if (typeof(options[10]) === "undefined") {
  108. //define sensible values for AS if none are stored
  109. logit("setting new AS values","debug");
  110. options[10] = 0;
  111. options[11] = 0;
  112. options[12] = 100;
  113. }
  114. getId('_inpASX').value = options[10];
  115. getId('_inpASY').value = options[11];
  116. getId('_inpASO').value = options[12];
  117. getId('_cbFixExternalProviders').checked = options[13];
  118. } else {
  119. // default values for first installation
  120. logit("no options in local storage - setting defaults");
  121. getId('_cbMoveZoomBar').checked = true;
  122. getId('_cbShrinkTopBars').checked = true;
  123. getId('_cbHideUserInfo').checked = true;
  124. getId('_cbCompressSegmentTab').checked = true;
  125. getId('_cbRestyleReports').checked = true;
  126. getId('_cbDisableMapBlocker').checked = false;
  127. getId('_cbNarrowSidePanel').checked = false;
  128. getId('_cbHideAveSpeedControls').checked = false;
  129. getId('_cbAddZoomIndicator').checked = true;
  130. getId('_inpASX').value = 0;
  131. getId('_inpASY').value = 0;
  132. getId('_inpASO').value = 100;
  133. getId('_cbFixExternalProviders').checked = true;
  134. }
  135. // Adds an extra checkbox so I can test segment panel changes easily
  136. if (Waze.loginManager.user.userName == 'iainhouse') {
  137. logit("creating segment detail debug checkbox","info");
  138. var brand = getId('brand');
  139. extraCBSection = document.createElement('p');
  140. extraCBSection.innerHTML = '<input type="checkbox" id="_cbextraCBSection" />';
  141. brand.appendChild(extraCBSection);
  142. getId('_cbextraCBSection').onclick = FALSEcompressSegmentTab;
  143. _cbextraCBSection.checked = _cbCompressSegmentTab.checked;
  144. }
  145. // overload the WME exit function to save my settings
  146. saveOptions = function() {
  147. if (localStorage) {
  148. logit("saving options to local storage");
  149. var options = [];
  150. // preserve previous options which may get lost after logout
  151. if (localStorage.WMEFixUI) { options = JSON.parse(localStorage.WMEFixUI); }
  152. options[1] = getId('_cbMoveZoomBar').checked;
  153. options[2] = getId('_cbShrinkTopBars').checked;
  154. options[3] = getId('_cbHideUserInfo').checked;
  155. options[4] = getId('_cbCompressSegmentTab').checked;
  156. options[5] = getId('_cbRestyleReports').checked;
  157. options[6] = getId('_cbDisableMapBlocker').checked;
  158. options[7] = getId('_cbNarrowSidePanel').checked;
  159. options[8] = getId('_cbHideAveSpeedControls').checked;
  160. options[9] = getId('_cbAddZoomIndicator').checked;
  161. options[10] = getId('_inpASX').value;
  162. options[11] = getId('_inpASY').value;
  163. options[12] = getId('_inpASO').value;
  164. options[13] = getId('_cbFixExternalProviders').checked;
  165. localStorage.WMEFixUI = JSON.stringify(options);
  166. }
  167. };
  168. window.addEventListener("beforeunload", saveOptions, false);
  169.  
  170. // apply the settings
  171. shiftAerials();
  172. setTimeout(applyAllSettings, 2000);
  173. logit("Initialisation complete");
  174. console.timeEnd(prefix + ": initialisation time");
  175. console.groupEnd();
  176. }
  177.  
  178. function createAddon() {
  179. //create the contents of my side-panel tab
  180. var addon = document.createElement('section');
  181. var section = document.createElement('p');
  182. addon.id = "sidepanel-FixUI";
  183. section.style.paddingTop = "0px";
  184. section.id = "fuContent";
  185. section.innerHTML = '<b>UI Fixes</b><br>';
  186. section.innerHTML += '<input type="checkbox" id="_cbMoveZoomBar" /> ' +
  187. '<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 <sup>*</sup></span><br>';
  188. section.innerHTML += '<input type="checkbox" id="_cbAddZoomIndicator" /> ' +
  189. '<span title="Yes - I stole the idea from WME Toolbox. But mine is clearer and takes up no extra room ;)">Add zoom level indicator to zoom bar</span><br>';
  190. section.innerHTML += '<input type="checkbox" id="_cbHideUserInfo" /> ' +
  191. '<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>';
  192. section.innerHTML += '<input type="checkbox" id="_cbShrinkTopBars" /> ' +
  193. '<span title="Because we can\'t afford to waste screen space, particularly on stuff we didn\'t ask for and don\'t want, like the black bar">Shrink bars above the map</span><br>';
  194. section.innerHTML += '<input type="checkbox" id="_cbCompressSegmentTab" /> ' +
  195. '<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>';
  196. section.innerHTML += '<input type="checkbox" id="_cbRestyleReports" /> ' +
  197. '<span title="Another UI element configured for developers with massive screens instead of normal users">Change formatting for report panels (UR/MP)</span><br>';
  198. section.innerHTML += '<input type="checkbox" id="_cbDisableMapBlocker" /> ' +
  199. '<span title="As if the crappy interface wasn\'t making life hard enough, now they force us to wait for an arbitrary time after every save!">Disable map blocking during/after saving.</span><span title="Use at your own risk. We don\'t know why it\'s there. Maybe there\'s a good reason but Waze can\'t be arsed to tell us what it is." style="font-size: 16px; color: red;">&#9888</span><br>';
  200. section.innerHTML += '<input type="checkbox" id="_cbNarrowSidePanel" /> ' +
  201. '<span title="If you have a netbook, Waze isn\'t interested in your experience. You need every bit of map space you can get - so have a present from me!">Reduce width of the side panel</span><span title="This will definitely interfere with scripts that rely on a fixed width for their tab contents." style="font-size: 16px; color: red;">&#9888</span><br>';
  202. section.innerHTML += '<input type="checkbox" id="_cbHideAveSpeedControls" /> ' +
  203. '<span title="If you don\'t have these in your country, YOU\'RE LUCKY! But don\'t forget you\'ve disabled this - they\'ll be coming soon!">Hide average speed camera controls</span><br>';
  204. section.innerHTML += '<input type="checkbox" id="_cbFixExternalProviders" /> ' +
  205. '<span title="The External Providers interface is really poor - you can rarely see all the details in the box provided and the other elements are poorly arranged. This fixes all that.">Expand & improve External Provider details for places</span><br>';
  206. section.innerHTML += '<br>';
  207. var tbHackStr = '<sup>* If you have WME Toolbox installed, make sure the setting "Move zoom control to left" is ';
  208. if (document.body.dir != "rtl") {
  209. tbHackStr += 'OFF';
  210. } else {
  211. tbHackStr += 'ON';
  212. }
  213. tbHackStr += '.</sup><br>';
  214. section.innerHTML += tbHackStr;
  215. section.innerHTML += '<br>';
  216. section.innerHTML += '<b title="Shift aerial images layer to match GPS tracks and reduce image opacity">Aerial Shifter</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
  217. section.innerHTML += '<span class="fa fa-power-off" id="_resetAS" title="Clear X/Y offsets"></span><br>';
  218.  
  219. section.innerHTML += '<div style="display:inline-block"><input type="number" id="_inpASX" title="horizontal shift" max=100 min=-100 step=5 style="height:20px; width:47px;text-align:right;"/><b>m</b><span class="fa fa-arrow-right"></span></div>';
  220. section.innerHTML += '<div id="as2" style="display:inline-block;padding:0 5px;"><input type="number" id="_inpASY" title="vertical shift" max=100 min=-100 step=5 style="height:20px; width:47px;text-align:right;"/><b>m</b><span class="fa fa-arrow-up"></span></div>';
  221. section.innerHTML += '<div id="as3" style="display:inline-block"><input type="number" id="_inpASO" title="opacity" max=100 min=0 step=10 style="height:20px; width:44px;text-align:right;"/><b>%</b><span class="fa fa-adjust"></span></div>';
  222. section.innerHTML += '<br>';
  223. section.innerHTML += '<br>';
  224. section.innerHTML += '<b><a href="https://www.waze.com/forum/viewtopic.php?f=819&t=191178" title="Forum topic" target="_blank"><u>' +
  225. 'WME Fix UI</u></a></b> &nbsp; v' + wmefu_version;
  226. addon.appendChild(section);
  227. addon.className = "tab-pane";
  228. return addon;
  229. }
  230.  
  231. function addMyTab(model,modeID) {
  232. if (modeID === 0) {
  233. logit("entering default mode, so creating tab");
  234. tabAttempts = 0;
  235. tabsLooper();
  236. } else {
  237. logit("entering event mode, so not initialising");
  238. return;
  239. }
  240. }
  241.  
  242. function tabsLooper() {
  243. tabAttempts += 1;
  244. if (tabAttempts > 20) {
  245. // tried 20 times to create tab without luck
  246. logit("unable to create my tab after 20 attempts","error");
  247. return;
  248. }
  249. var userTabs = getId('user-info');
  250. var navTabs = getElementsByClassName('nav-tabs', userTabs)[0];
  251. if (typeof navTabs === "undefined") {
  252. //the basic tabs aren't there yet, so I can't add mine
  253. logit("waiting for NavTabs","warning");
  254. setTimeout(tabsLooper, 200);
  255. } else{
  256. var tabContent = getElementsByClassName('tab-content', userTabs)[0];
  257. newtab = document.createElement('li');
  258. newtab.innerHTML = '<a href="#sidepanel-FixUI" data-toggle="tab" title="Fix UI">FU</a>';
  259. navTabs.appendChild(newtab);
  260. tabContent.appendChild(wmeFUAddon);
  261. }
  262. }
  263.  
  264. function applyAllSettings() {
  265. var fname = arguments.callee.toString().match(/function ([^\(]+)/)[1];
  266. logit("function " + fname + " called", "debug");
  267. console.group(prefix + ": applying all settings");
  268. moveZoomBar();
  269. shrinkTopBars();
  270. hideUserInfo();
  271. compressSegmentTab();
  272. restyleReports();
  273. disableMapBlocker();
  274. narrowSidePanel();
  275. hideAveSpeedControls();
  276. fixExternalProviders();
  277. addZoomIndicator();
  278. console.groupEnd();
  279. wmeFUinitialising = false;
  280. }
  281.  
  282. function moveZoomBar() {
  283. var fname = arguments.callee.toString().match(/function ([^\(]+)/)[1];
  284. logit("function " + fname + " called", "debug");
  285. var reportPanel = getId('panel-container');
  286. reportPanel.style.position = "absolute";
  287. if (_cbMoveZoomBar.checked) {
  288. addGlobalStyle('.olControlPanZoomBar { left: 10px; width: 30px; right: inherit; }');
  289. addGlobalStyle('#WMETB_ZoomLevelIndicator { left: 43px !important; right: inherit !important; }');
  290. if (document.body.dir != "rtl") {
  291. addGlobalStyle('.panel { left: 40px; }');
  292. } else {
  293. addGlobalStyle('.panel { right: inherit; }');
  294. }
  295. } else {
  296. addGlobalStyle('.olControlPanZoomBar { left: inherit; width: 30px; right: 10px; }');
  297. addGlobalStyle('#WMETB_ZoomLevelIndicator { left: inherit !important; right: 43px !important; }');
  298. if (document.body.dir != "rtl") {
  299. addGlobalStyle('.panel { left: inherit; }');
  300. } else {
  301. addGlobalStyle('.panel { right: 40px; }');
  302. }
  303. }
  304. }
  305.  
  306. function hideUserInfo() {
  307. var fname = arguments.callee.toString().match(/function ([^\(]+)/)[1];
  308. logit("function " + fname + " called", "debug");
  309. var styles = "";
  310. // WME Panel Swap buttons - move them up if user info is hidden
  311. var PSButton1 = getId('WMEPS_UIButton');
  312. var PSButton2 = getId('WMEPS_EditButton');
  313. if (_cbHideUserInfo.checked) {
  314. styles += '#sidebar #user-info #user-box { padding: 0px; }';
  315. styles += '#sidebar #user-details .user-profile { display: none !important; }';
  316. if (PSButton1) { PSButton1.style.top = '-27px'; }
  317. if (PSButton2) { PSButton2.style.top = '-27px'; }
  318. // Keep My Layers toggle - move up if user info is hidden
  319. styles += '.kml-toggle-container { top: -25px; }';
  320. addStyle(prefix + fname,styles);
  321. } else {
  322. if (PSButton1) { PSButton1.style.top = '0px'; }
  323. if (PSButton2) { PSButton2.style.top = '0px'; }
  324. removeStyle(prefix + fname);
  325. }
  326. }
  327.  
  328. function shrinkTopBars() {
  329. var fname = arguments.callee.toString().match(/function ([^\(]+)/)[1];
  330. logit("function " + fname + " called", "debug");
  331. var styles = "";
  332. if (_cbShrinkTopBars.checked) {
  333. //shrink the blue tool bar
  334. styles += '.toolbar { height: 31px; }';
  335. styles += '#app-head { height: 31px; }';
  336. styles += '#search { padding-top: 1px; }';
  337. styles += '.toolbar .toolbar-button { padding: 2px 7px; }';
  338. styles += '.toolbar .toolbar-separator { height: 31px; }';
  339. styles += '#layer-switcher { height: 51px; }';
  340. styles += '.toolbar menu.dropdown-menu { top: 31px; }';
  341. styles += '#layer-switcher .dropdown-menu { top: 31px; }';
  342. //extra tweaks for Toolbox button & layers menu
  343. styles += '.WazeControlLayerSwitcherIcon { margin: 5px 2px 0 !important; }';
  344. styles += '#WazeControlLayerSwitcherIconContainer { height: 51px !important; }';
  345. styles += '#WazeControlLayerSwitcherIconContainerBeta { height: 51px !important; }';
  346. if (document.body.dir != "rtl") {
  347. styles += '.WazeControlLayerSwitcherToolbox { margin-left: -92px !important; }';
  348. } else {
  349. styles += '.WazeControlLayerSwitcherToolbox { margin-left: 112px !important; }';
  350. }
  351. styles += '#sidebar waze-links { height: 16px; }';
  352. //shrink the black bar
  353. // styles += '.topbar { height: 20px; line-height: 20px; }';
  354. // styles += '.topbar .location-info { font-size: 12px; }';
  355. styles += 'div#topbar-container { position: relative; }';
  356. styles += '.topbar { position: absolute; z-index: 1; background: transparent; height: 0; color: white; text-shadow: -1px -1px 0 #000, 1px -1px #000, -1px 1px #000, 1px 1px #000; line-height: 1.1; }';
  357. styles += '.topbar .location-info { font-size: 15px; font-weight: 900; }';
  358. styles += '.topbar .area-managers .title, .topbar .area-managers .main-list { font-size: 15px; font-weight: 900; }';
  359. // following line needed to move MTE menu over the WME Bookmarks pin control
  360. styles += '#mode-switcher .dropdown-menu { top: 30px; }';
  361. styles += '.olControlPanZoomBar { top: 32px; }';
  362. styles += '#panel-container .panel { top: 20px; }';
  363. addStyle(prefix + fname,styles);
  364. } else {
  365. removeStyle(prefix + fname);
  366. }
  367. window.dispatchEvent(new Event('resize'));
  368. }
  369.  
  370. function FALSEcompressSegmentTab() {
  371. _cbCompressSegmentTab.checked = _cbextraCBSection.checked;
  372. compressSegmentTab();
  373. }
  374.  
  375. function compressSegmentTab() {
  376. var fname = arguments.callee.toString().match(/function ([^\(]+)/)[1];
  377. logit("function " + fname + " called", "debug");
  378. var styles = "";
  379. var ep=getId('edit-panel');
  380. if (_cbCompressSegmentTab.checked) {
  381. // shrink address
  382. styles += '#edit-panel .primary-street { font-size: 14px; line-height: 15px; font-weight: 600; color: black; }';
  383. styles += '#edit-panel .address-edit-view .preview .address-edit-btn:not(.disabled) { background-color: #FFF9C4; }';
  384. styles += '#edit-panel .segment .address-edit-view, .edit-panel .segment .address-edit-view { margin-bottom: 5px; }';
  385. //shrink tabs
  386. styles += '#sidebar .nav-tabs>li {margin-top: 2px; }';
  387. styles += '#sidebar .nav-tabs li a { padding: 2px; }';
  388. styles += '#sidebar .nav-tabs { margin: 0 0 5px 0; padding-left: 4px; }';
  389. //reduce some vertical margins
  390. styles += '#edit-panel .contents { padding: 0 5px 0 5px; overflow: hidden; }';
  391. styles += '#edit-panel .form-group { margin-bottom: 2px; line-height: 1; font-size: 11px; }';
  392. styles += '#edit-panel .selection { margin-bottom: 5px; }';
  393. styles += '#sidebar .side-panel-section:not(:last-child) { margin-bottom: 2px; }';
  394. styles += '#sidebar .side-panel-section:not(:last-child)::after { margin-top: 5px; margin-bottom: 2px; }';
  395. styles += '#edit-panel .control-label { margin-bottom: 1px; }';
  396. styles += '#sidebar .controls-container { padding-top: 2px; }';
  397. styles += '#edit-panel .segment .speed-limit label { margin-bottom: 0px; }';
  398. styles += '#edit-panel .more-actions { padding-top: 2px; }';
  399. styles += '#edit-panel .segment .speed-limit .direction-label, #edit-panel .segment .speed-limit .unit-label { line-height: 2.1em; }';
  400. //shrink dropdown controls & buttons
  401. styles += '#edit-panel button, #edit-panel select, #edit-panel .form-control { font-size: 11px; height: auto; padding: 0px 4px; }';
  402. styles += '#edit-panel .more-actions button:not(:last-of-type) { margin-bottom: 2px; }';
  403. styles += '.edit-closure .input-group-addon { padding: 2px 8px; }';
  404. //fit road property checkboxes on one line for all three (if text length allows)
  405. styles += '#edit-panel .controls-container { display: inline-block; }';
  406. styles += '#edit-panel .controls-container label { font-size: 12px; line-height: 18px; padding-left: 22px; }';
  407. styles += '#edit-panel .select-entire-street { width: 49%; overflow: hidden; }';
  408. styles += '#edit-panel .edit-house-numbers { width: 49%; overflow: hidden; }';
  409. styles += '#edit-panel .action-button { color: black; }';
  410. styles += '#edit-panel .categories .select2-container { margin-bottom: -5px; }';
  411. //tweaks for Closures tab
  412. styles += '#edit-panel .segment .segment-details { margin-bottom: 4px; }';
  413. styles += '.closures-list .closure-item .section { padding: 2px; }';
  414. styles += '.col-xs-6 { line-height: 14px; }';
  415. styles += '.closures-list .direction { margin-bottom: 0px; }';
  416. styles += '.closures-list .closure-item:not(:last-child) { margin-bottom: 4px; }';
  417. //tweak required for Speedhelper script
  418. styles += 'div[id^="spd_"] { line-height: 1.43; }';
  419. addStyle(prefix + fname,styles);
  420. } else {
  421. removeStyle(prefix + fname);
  422. }
  423. }
  424.  
  425. function restyleReports() {
  426. var fname = arguments.callee.toString().match(/function ([^\(]+)/)[1];
  427. logit("function " + fname + " called", "debug");
  428. var styles = "";
  429. if (_cbRestyleReports.checked) {
  430. styles += '#panel-container .panel { font-size: 12px; line-height: 15px; }';
  431. styles += '#panel-container .problem-edit .header { padding: 5px; line-height: 15px; }';
  432. styles += '#panel-container .problem-edit .problem-data .title { line-height: 22px; }';
  433. styles += '#panel-container .problem-edit .section .title { padding: 0 5px; }';
  434. styles += '#panel-container .problem-edit .section .content { padding: 5px; }';
  435. styles += '#WMEFP-UR-ALLPM { top: -2px !important; }';
  436. styles += '#panel-container .problem-edit .conversation.section .comment .comment-content { padding: 0 5px; }';
  437. styles += '#panel-container .problem-edit .conversation.section .no-comments { padding: 0; }';
  438. styles += '#panel-container .problem-edit .conversation.section .new-comment-form { padding: 0; }';
  439. styles += '#panel-container .problem-edit .conversation.section .new-comment-form textarea { resize: vertical; height: 110px; margin-bottom: 5px; padding: 3px 5px; font-size: 12px; }';
  440. styles += '#panel-container .btn { height: 20px; padding: 0px 10px;}';
  441. styles += '#panel-container .problem-edit .actions .content { padding: 2px 5px;}';
  442. styles += '#panel-container .problem-edit .actions .controls-container label { margin-bottom: 0px; line-height: 22px }';
  443. styles += '#panel-container .problem-edit .actions .navigation { margin-top: 5px;}';
  444. styles += '#panel-container .problem-edit .actions .controls-container { display: inline-flex; flex-wrap: wrap; margin-left: -3px; }';
  445. addStyle(prefix + fname,styles);
  446. if (wmeFUinitialising) {
  447. setTimeout(draggablePanel, 5000);
  448. } else {
  449. draggablePanel();
  450. }
  451. } else {
  452. removeStyle(prefix + fname);
  453. if (jQuery.ui) {
  454. $("#panel-container").draggable("destroy");
  455. getId("panel-container").style = "";
  456. }
  457. }
  458. window.dispatchEvent(new Event('resize'));
  459. }
  460.  
  461. function draggablePanel() {
  462. if (jQuery.ui) {
  463. $("#panel-container").draggable({ handle: ".header" });
  464. }
  465. }
  466.  
  467. function disableMapBlocker() {
  468. var fname = arguments.callee.toString().match(/function ([^\(]+)/)[1];
  469. logit("function " + fname + " called", "debug");
  470. if (_cbDisableMapBlocker.checked) {
  471. addStyle(prefix + fname,'#popup-overlay { width: 0%; height: 0%; }');
  472. } else {
  473. removeStyle(prefix + fname);
  474. }
  475. }
  476.  
  477. function narrowSidePanel() {
  478. var fname = arguments.callee.toString().match(/function ([^\(]+)/)[1];
  479. logit("function " + fname + " called", "debug");
  480. var styles = "";
  481. if (_cbNarrowSidePanel.checked) {
  482. styles += '.row-fluid #sidebar { width: 250px; }';
  483. styles += '.col-fixed-330 { width: 250px; }';
  484. styles += '#sidebar waze-links { overflow: hidden; }';
  485. styles += '#sidebar waze-links li+li::before { padding: 0; }';
  486. styles += '#sidebar waze-links li { font-size: 10px; }';
  487. styles += '#edit-panel .add-alt-street-form th.city { min-width: inherit; }';
  488. styles += '#edit-panel .external-providers-view .select2-container { width: 100%; }';
  489. if (document.body.dir != "rtl") {
  490. styles += '.show-sidebar .row-fluid .fluid-fixed { margin-left: 250px; }';
  491. styles += '.col-offset-330 { padding-left: 250px; }';
  492. } else {
  493. styles += '.show-sidebar .row-fluid .fluid-fixed { margin-right: 250px; }';
  494. styles += '.col-offset-330 { padding-right: 250px; }';
  495. }
  496. styles += '.edit-closure .form { padding: 2px; }';
  497. styles += '.edit-closure .date-input-group { width: 56%; }';
  498. styles += '#editor-container #map.street-view-mode #street-view-container { width: 35%; }';
  499. styles += '#editor-container #map.street-view-mode #WazeMap { width: 65%; margin-right: 65%; }';
  500. addStyle(prefix + fname, styles);
  501. } else {
  502. removeStyle(prefix + fname);
  503. }
  504. window.dispatchEvent(new Event('resize'));
  505. }
  506.  
  507. function hideAveSpeedControls() {
  508. var fname = arguments.callee.toString().match(/function ([^\(]+)/)[1];
  509. logit("function " + fname + " called", "debug");
  510. removeStyle(prefix + fname);
  511. if (_cbHideAveSpeedControls.checked) {
  512. var ASCBox;
  513. if (getId('fwdSpeedCameraCheckbox')) {
  514. ASCBox = getId('fwdSpeedCameraCheckbox');
  515. }
  516. if (getId('revSpeedCameraCheckbox')) {
  517. ASCBox = getId('revSpeedCameraCheckbox');
  518. }
  519. if (ASCBox) {
  520. var formGroup = ASCBox.parentNode.parentNode.parentNode;
  521. var formGroupParent = formGroup.parentNode;
  522. var targetGroup = Array.prototype.indexOf.call(formGroupParent.children, formGroup) + 1;
  523. addStyle(prefix + fname, '#segment-edit-general > .side-panel-section.attributes-form > .form-group:nth-of-type(' + targetGroup + ') { display: none; }');
  524. }
  525. }
  526. }
  527.  
  528. function addZoomIndicator() {
  529. var fname = arguments.callee.toString().match(/function ([^\(]+)/)[1];
  530. logit("function " + fname + " called", "debug");
  531. var slider = getElementsByClassName('slider', getId('WazeMap'))[1];
  532. if (_cbAddZoomIndicator.checked) {
  533. addStyle(prefix + fname, '.slider { font-size: 15px; font-weight: 900; line-height: 1; height: 18px; margin-top: 23px; padding-top: 2px; text-align: center; }');
  534. Waze.map.events.register("zoomend", null, ZLI);
  535. ZLI();
  536. } else {
  537. removeStyle(prefix + fname);
  538. Waze.map.events.unregister("zoomend", null, ZLI);
  539. slider.innerText = "";
  540. slider.title = "";
  541. }
  542. }
  543.  
  544. function ZLI() {
  545. var slider = getElementsByClassName('slider', getId('WazeMap'))[1];
  546. slider.innerText = Waze.map.zoom;
  547. slider.title = "Zoom level indicator by WMEFU";
  548. switch (Waze.map.zoom) {
  549. case 0:
  550. case 1:
  551. slider.style.background = '#ef9a9a';
  552. slider.title += "\nCannot permalink any segments at this zoom level";
  553. break;
  554. case 2:
  555. case 3:
  556. slider.style.background = '#ffe082';
  557. slider.title += "\nCan only permalink primary or higher at this zoom level";
  558. break;
  559. default:
  560. slider.style.background = '#ffffff';
  561. slider.title += "\nCan permalink any segments at this zoom level";
  562. break;
  563. }
  564. }
  565.  
  566. function shiftAerials() {
  567. var fname = arguments.callee.toString().match(/function ([^\(]+)/)[1];
  568. logit("function " + fname + " called", "debug");
  569. // calculate meters/pixel for current map view
  570. var ipu = OpenLayers.INCHES_PER_UNIT;
  571. var metersPerPixel = Waze.map.getResolution() * ipu.m / ipu[Waze.map.getUnits()];
  572. // Apply the shift and opacity
  573. Waze.map.baseLayer.div.style.left = Math.round(getId("_inpASX").value / metersPerPixel) + 'px';
  574. Waze.map.baseLayer.div.style.top = Math.round(- getId("_inpASY").value / metersPerPixel) + 'px';
  575. Waze.map.baseLayer.div.style.opacity = getId("_inpASO").value/100;
  576. }
  577.  
  578. function fixExternalProviders () {
  579. var fname = arguments.callee.toString().match(/function ([^\(]+)/)[1];
  580. logit("function " + fname + " called", "debug");
  581. var styles = "";
  582. if (_cbFixExternalProviders.checked) {
  583. //enlarge external provider boxes
  584. styles += '#edit-panel .external-providers-view .select2-container { width: 90%; margin-bottom: 2px; }';
  585. styles += '.select2-container .select2-choice { height: inherit; line-height: 16px; }';
  586. styles += '.select2-container .select2-choice>.select2-chosen { white-space: normal; }';
  587. styles += '.placeId { padding-bottom: 5px; }';
  588. addStyle(prefix + fname,styles);
  589. } else {
  590. removeStyle(prefix + fname);
  591. }
  592. }
  593.  
  594. //Helper functions
  595.  
  596. function addGlobalStyle(css) {
  597. var head, style;
  598. head = document.getElementsByTagName('head')[0];
  599. if (!head) {
  600. return;
  601. }
  602. style = document.createElement('style');
  603. style.type = 'text/css';
  604. style.innerHTML = css;
  605. head.appendChild(style);
  606. }
  607.  
  608. function addStyle(ID, css) {
  609. var head, style;
  610. head = document.getElementsByTagName('head')[0];
  611. if (!head) {
  612. return;
  613. }
  614. style = document.createElement('style');
  615. style.type = 'text/css';
  616. style.innerHTML = css;
  617. style.id = ID;
  618. head.appendChild(style);
  619. }
  620.  
  621. function removeStyle(ID) {
  622. var style = document.getElementById(ID);
  623. if (style) { style.parentNode.removeChild(style); }
  624. }
  625.  
  626. function getElementsByClassName(classname, node) {
  627. if(!node) { node = document.getElementsByTagName("body")[0]; }
  628. var a = [];
  629. var re = new RegExp('\\b' + classname + '\\b');
  630. var els = node.getElementsByTagName("*");
  631. for (var i=0,j=els.length; i<j; i++) {
  632. if (re.test(els[i].className)) { a.push(els[i]); }
  633. }
  634. return a;
  635. }
  636.  
  637. function getId(node) {
  638. return document.getElementById(node);
  639. }
  640.  
  641. function logit(msg, typ) {
  642. if (!typ) {
  643. console.log(prefix + ": " + msg);
  644. } else {
  645. switch(typ) {
  646. case "error":
  647. console.error(prefix + ": " + msg);
  648. break;
  649. case "warning":
  650. console.warn(prefix + ": " + msg);
  651. break;
  652. case "info":
  653. console.info(prefix + ": " + msg);
  654. break;
  655. case "debug":
  656. if (debug) {
  657. console.debug(prefix + ": " + msg);
  658. }
  659. break;
  660. default:
  661. console.log(prefix + " unknown message type: " + msg);
  662. break;
  663. }
  664. }
  665. }
  666.  
  667. // Start it running
  668. setTimeout(init1, 200);
  669. })();