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