WME Fix UI

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

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

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