Waze Editor Profile Enhancements

Pulls the correct forum post count - changed to red to signify the value as pulled from the forum by the script & more!

  1. // ==UserScript==
  2. // @name Waze Editor Profile Enhancements
  3. // @namespace http://tampermonkey.net/
  4. // @version 2022.12.11
  5. // @description Pulls the correct forum post count - changed to red to signify the value as pulled from the forum by the script & more!
  6. // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAUCAYAAACXtf2DAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAZdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuMjHxIGmVAAADQklEQVRIS92VS0wTQRjHq+IrvmKiB8VEbxK9aIweNMZEEi/Gkxq6u4UCKjEEiQajMRobE7DdbrvS8DCF3Z3ty8oqiGAw4KMKxKpBxUcEORTF+EZFRQjPz5llbVqo0nj0n/wzO535ft/szDdbXbwyAUylrWgNxUk5NCsdpTm0h7LLGw446mZqUyYXAEwxmUwJWleVgXPPoTnZTrHoG2WRvutZsRc/DzJWuZ/h0A+c7Attk7MURZmmhcTWbjzBYJE2ptnlRO0nnRGhWZRV7KdYqQ8b/mgr+omTfsxwKIu10IliWGElZS7fkckK80gyhpU249XhwBjAGNaz0ihpIxcYFtkaxipso1hxS5bFuYCyoSQ8+UckIG5bURfj8MzX0GOizaULDZy0dZ/DtUXPCksZKzqO93ooJmAS06w4jAshW0OPibGULUvLlxNzCtHNPLGqAVcLPsjYgHisZ9Frk6LM0PA6XUaBuJiy+RaRM8gu9ifjrVL389+NRkibyVbPUxNkFytzqQJnEklAm+V1EwPI4bkgnXerbaxxYjKWccYDeAfUBZISVxPg2p/KFJRtZk5L62nOuxzX+/D4YOKq4BPwNz4E4VoQztY1gaP2FhTV3obSq00gNATVsZr7zwCf4eAhRZmtwolIFenNwtosp3M6qeUosBWpbTUO7OzuCftMTQBaQm/C/aevPwBXeR2a20KQWejt1NAThV9vUyrnGiTQdN4FB8svwoMI0G9X3n0Cz998Cvc73n+GiuZWQDfuDRh5t0/DRWt/sT+VgK897hhpf9sdBYzHra/egpF39abx8moNGa1UTu464antf/EuGh6KeB7v0Kevatvc9lLdSgzfpeEmyhQIJODXK9nr8H0vrw8O+W4/gL0OL16VG843PYoCN7Z3QnbJeVwpMhxz1YwY7a6fBhtiNNTfZbBJG402TxFe0fApfx3w1QFcetKoyXulJ0+41JdfUf8Nl+PQYbEKyuvvqCtneLRdC49f+GPXkuu8AEekSwTSg/sp+H8gFyejKYvYmFV0Dk56r5CxAYb3LNHCJhe5IAwnrqLMwk69RbxOYCk2KYVcSFLSRjNawbAoGd+Xyxge1FtQLvncaOH/lXS6Xw40MXnm6lDsAAAAAElFTkSuQmCC
  7. // @author JustinS83
  8. // @include https://www.waze.com/*user/editor*
  9. // @include https://beta.waze.com/*user/editor*
  10. // require https://code.jquery.com/ui/1.12.1/jquery-ui.js
  11. // @contributionURL https://github.com/WazeDev/Thank-The-Authors
  12. // @run-at document-start
  13. // ==/UserScript==
  14.  
  15. /* global W */
  16. /* global OL */
  17. /* global $ */
  18. /* global I18n */
  19. /* global _ */
  20. /* global WazeWrap */
  21. /* global require */
  22. /* global gon */
  23. /* eslint curly: ["warn", "multi-or-nest"] */
  24.  
  25. (function() {
  26. 'use strict';
  27.  
  28. var settings = {};
  29. var nawkts, rowwkts, ilwkts = [];
  30. var combinedNAWKT, combinedROWWKT, combinedILWKT= "";
  31. var naMA, rowMA, ilMA;
  32. const reducer = (accumulator, currentValue) => accumulator + currentValue;
  33.  
  34. loadSettings();
  35.  
  36. let lastEditEnv= gon.data.lastEditEnv;
  37.  
  38. function getApiUrlUserProfile(username, env) {
  39. let apiEnv = '';
  40. if (env != 'na')
  41. apiEnv = env + '-';
  42. return `https://${window.location.host}/${apiEnv}Descartes/app/UserProfile/Profile?username=${username}`;
  43. }
  44.  
  45. if (typeof settings.Environment != 'undefined'
  46. && settings.Environment != 'default'
  47. && settings.Environment != gon.data.lastEditEnv) {
  48. let apiUrl = getApiUrlUserProfile(gon.data.username, settings.Environment);
  49.  
  50. // synchronous XMLHttpRequest required as we need to pause execution to replace window.gon object
  51. // The deprication warning in console is expected.
  52. var request = new XMLHttpRequest();
  53. request.open('GET', apiUrl, false); // 'false' makes the request synchronous
  54. request.send(null);
  55.  
  56. if (request.status === 200)
  57. gon.data = JSON.parse(request.responseText);
  58. gon.data.lastEditEnv = settings.Environment;
  59. }
  60.  
  61.  
  62. function bootstrap(tries = 1) {
  63. if (typeof W !== 'undefined' && W.EditorProfile && $)
  64. init();
  65. else if (tries < 1000)
  66. setTimeout(function () {bootstrap(tries++);}, 200);
  67. }
  68.  
  69. bootstrap();
  70.  
  71. async function init(){
  72. $('body').append('<span id="ruler" style="visibility:hidden; white-space:nowrap;"></span>');
  73. //injectCSS();
  74. String.prototype.visualLength = function(){ //measures the visual length of a string so we can better center the area labels on the areas
  75. var ruler = $("#ruler");
  76. ruler[0].innerHTML = this;
  77. return ruler[0].offsetWidth;
  78. }
  79. $.get('https://www.waze.com/forum/memberlist.php?username=' + W.EditorProfile.data.username, function(forumResult){
  80. var re = 0;
  81. var matches = forumResult.match(/<a href=".*?"\s*?title="Search user’s posts">(\d+)<\/a>/);
  82. if(matches && matches.length > 0)
  83. re = matches[1];
  84. var WazeVal = $('.posts').parent().next()[0].innerHTML.trim();
  85. var userForumID = forumResult.match(/<a href="\.\/memberlist\.php\?mode=viewprofile&amp;u=(\d+)"/);
  86. if(userForumID != null){
  87. userForumID = userForumID[1];
  88. $('.posts').parent().css('position', 'relative');
  89.  
  90. if(WazeVal !== re.toString()){
  91. $('.posts').parent().next()[0].innerHTML = re;
  92. $('.posts').parent().next().css('color','red');
  93. $('.posts').parent().next().prop('title', 'Waze reported value: ' + WazeVal);
  94. }
  95.  
  96. $('.posts').parent().parent().wrap('<a href="https://www.waze.com/forum/search.php?author_id=' + userForumID + '&sr=posts" target="_blank"></a>');
  97.  
  98. $('#header > div > div.user-info > div > div.user-highlights').prepend('<a href="https://www.waze.com/forum/memberlist.php?mode=viewprofile&u=' + userForumID +'" target="_blank" style="margin-right:5px;" id="forumProfile" style="float: right;"><button class="s-modern-button s-modern" style="float: right;"><i class="fa fa-user"></i><span>Forum Profile</span></button></a>');
  99.  
  100. }
  101. });
  102.  
  103. var count = 0;
  104. W.EditorProfile.data.editingActivity.forEach(function(x) { if(x !== 0) count++; });
  105. $('#editing-activity > div > h3').append(" (" + count + " of last 91 days)");
  106.  
  107. await getManagedAreas();
  108. BuildManagedAreasWKTInterface();
  109. /************** Add Average & Total to Editing Activity ***********/
  110. AddEditingActivityAvgandTot();
  111. /************** Add Editor Stats Section **************/
  112. AddEditorStatsSection();
  113.  
  114. initEnvironmentChooser();
  115. }
  116.  
  117. function initEnvironmentChooser(){
  118. let highlight = document.createElement('div');
  119. highlight.className="highlight";
  120. let highlightTitle = document.createElement('div');
  121. highlightTitle.className="highlight-title";
  122. let highlightTitleIcon = document.createElement('div');
  123. //highlightTitleIcon.className="highlight-title-icon posts";
  124. highlightTitleIcon.setAttribute('style',getIconStyle());
  125. let highlightTitleText = document.createElement('div');
  126. highlightTitleText.className="highlight-title-text";
  127. let userStatsValue = document.createElement('div');
  128. userStatsValue.className="user-stats-value";
  129.  
  130. highlightTitle.appendChild(highlightTitleIcon);
  131. highlightTitle.appendChild(highlightTitleText);
  132. highlight.appendChild(highlightTitle);
  133. highlight.appendChild(userStatsValue);
  134.  
  135. highlightTitleText.innerHTML = 'Environments';
  136. userStatsValue.setAttribute('style','margin-top: -10px;font-size: 17px;');
  137.  
  138. let frag = document.createDocumentFragment(),
  139. select = document.createElement("select");
  140. select.id = 'environmentSelect';
  141. select.name = 'environmentSelect';
  142. select.setAttribute('style','position:relative;box-shadow: 0 0 2px #57889C;background: white;font-family: sans-serif;display: inherit;top: -11px;border: 0px;outline: 0px;color: #59899e;');
  143.  
  144. select.options.add( new Option("Last Edit (" + lastEditEnv.toUpperCase() + ")","default", true, true) );
  145. select.options.add( new Option("NA","na") );
  146. select.options.add( new Option("ROW","row") );
  147. select.options.add( new Option("IL","il") );
  148.  
  149. for (var i = 0; i < select.options.length; i++) {
  150. if (select.options[i].value == settings.Environment)
  151. select.options[i].selected = true;
  152. }
  153.  
  154. frag.appendChild(select);
  155. document.getElementsByClassName('user-stats')[0].prepend(highlight);
  156. userStatsValue.appendChild(frag);
  157.  
  158. document.querySelector('select[name="environmentSelect"]').onchange = envChanged;
  159. }
  160.  
  161. function getIconStyle() {
  162. let tempQuerySelector = document.querySelector('#edits-by-type .venue-icon');
  163. let tempComputedStyle = window.getComputedStyle(tempQuerySelector);
  164. let iconStyle =
  165. `background-image:${tempComputedStyle.getPropertyValue('background-image')};`
  166. + `background-size:${tempComputedStyle.getPropertyValue('background-size')};`
  167. + `background-position:${tempComputedStyle.getPropertyValue('background-position')};`
  168. + `width:${tempComputedStyle.getPropertyValue('width')};`
  169. + `height:${tempComputedStyle.getPropertyValue('height')};`
  170. + `transform: scale(0.5);`
  171. + `display: inline-block;`
  172. + `float: left;`
  173. + `position: relative;`
  174. + `top: -10px;`
  175. + `left: -9px;`
  176. + `margin-right: -18px;`
  177. + `filter: invert(10%) sepia(39%) saturate(405%) hue-rotate(152deg) brightness(99%) contrast(86%);`;
  178. return iconStyle;
  179. }
  180.  
  181. function AddLabelsToAreas(){
  182. if($('svg.leaflet-zoom-animated').length > 0){
  183. $('svg.leaflet-zoom-animated g > text').remove();
  184. var svg = $('svg.leaflet-zoom-animated')[0];
  185. var pt = svg.createSVGPoint(), svgP;
  186.  
  187. let displayedAreas = $('svg.leaflet-zoom-animated g');
  188.  
  189. for(let i=0;i<displayedAreas.length;i++){
  190. let windowPosition = $(displayedAreas[i])[0].getBoundingClientRect();
  191. pt.x = (windowPosition.left + windowPosition.right) / 2;
  192. pt.y = (windowPosition.top + windowPosition.bottom) / 2;
  193. svgP = pt.matrixTransform(svg.getScreenCTM().inverse());
  194.  
  195. if(svgP.x != 0 && svgP.y != 0){
  196. var newText = document.createElementNS("http://www.w3.org/2000/svg","text");
  197. newText.setAttributeNS(null,"x",svgP.x - (`Area ${i+1}`.visualLength() /2));
  198. newText.setAttributeNS(null,"y",svgP.y);
  199. newText.setAttributeNS(null, "fill", "red");
  200. newText.setAttributeNS(null,"font-size","12");
  201.  
  202. var textNode = document.createTextNode(`Area ${i+1}`);
  203. newText.appendChild(textNode);
  204. $(displayedAreas[i])[0].appendChild(newText);
  205. }
  206. }
  207. }
  208. }
  209.  
  210. function BuildManagedAreasWKTInterface(){
  211. if(naMA.managedAreas.length > 0 || rowMA.managedAreas.length > 0 || ilMA.managedAreas.length > 0){
  212. $('#header > div > div.user-info > div > div.user-highlights > div.user-stats').before('<a href="#" title="View editor\'s managed areas in WKT format"><button class="s-modern-button s-modern" id="userMA" style="float: right;"><i class="fa fa-map-o" aria-hidden="true"></i></button></a>');
  213.  
  214. /****** MO to update labels when panning/zooming the map ************/
  215. var observer = new MutationObserver(function(mutations) {
  216. mutations.forEach(function(mutation) {
  217. if ($(mutation.target).hasClass('leaflet-map-pane') && (mutation.attributeName === "class" || mutation.attributeName === "style")){
  218. if(mutation.attributeName === "class" && mutation.target.classList.length == 1) //zoom has ended, we can redraw our labels
  219. setTimeout(AddLabelsToAreas, 200);
  220. else if(mutation.attributeName === "style") //panning the map
  221. setTimeout(AddLabelsToAreas, 200);
  222. }
  223. });
  224. });
  225. observer.observe(document.getElementsByClassName('component-map-view')[0], { childList: true, subtree: true, attributes:true });
  226.  
  227. AddLabelsToAreas();
  228.  
  229. $('#userMA').click(function(){
  230. if($('#wpeWKT').css('visibility') === 'visible')
  231. $('#wpeWKT').css({'visibility': 'hidden'});
  232. else
  233. $('#wpeWKT').css({'visibility': 'visible'});
  234. });
  235.  
  236. var result = buildWKTArray(naMA);
  237. nawkts = result.wktArr;
  238. combinedNAWKT = result.combinedWKT;
  239.  
  240. result = buildWKTArray(rowMA);
  241. rowwkts = result.wktArr;
  242. combinedROWWKT = result.combinedWKT;
  243.  
  244. result = buildWKTArray(ilMA);
  245. ilwkts = result.wktArr;
  246. combinedILWKT = result.combinedWKT;
  247.  
  248. var $section = $("<div>", {style:"padding:8px 16px"});
  249. $section.html([
  250. '<div id="wpeWKT" style="padding:8px 16px; position:fixed; border-radius:10px; box-shadow:5px 5px 10px 4px Silver; top:25%; left:40%; background-color:white; visibility:hidden;">', //Main div
  251. '<div style="float:right; cursor:pointer;" id="wpeClose"><i class="fa fa-window-close" aria-hidden="true"></i></div>',
  252. '<ul class="nav nav-tabs">',
  253. `${naMA.managedAreas.length > 0 ? '<li class="active"><a data-toggle="pill" href="#naAreas">NA</a></li>' : ''}`,
  254. `${rowMA.managedAreas.length > 0 ? '<li><a data-toggle="pill" href="#rowAreas">ROW</a></li>' : ''}`,
  255. `${ilMA.managedAreas.length > 0 ? '<li><a data-toggle="pill" href="#ilAreas">IL</a></li>' : ''}`,
  256. '</ul>',
  257. '<div class="tab-content">',
  258. '<div id="naAreas" class="tab-pane fade in active">',
  259. '<div id="wpenaAreas" style="float:left; max-height:350px; overflow:auto;"><h3 style="float:left; left:50%;">Editor Areas</h3><br>' + buildAreaList(nawkts,"na") + '</div>',
  260. '<div id="wpenaPolygons" style="float:left; padding-left:15px;"><h3 style="position:relative; float:left; left:40%;">Area WKT</h3><br><textarea rows="7" cols="55" id="wpenaAreaWKT" style="height:auto;"></textarea></div>',
  261. '</div>',//naAreas
  262. '<div id="rowAreas" class="tab-pane fade">',
  263. '<div id="wperowAreas" style="float:left; max-height:350px; overflow:auto;"><h3 style="float:left; left:50%;">Editor Areas</h3><br>' + buildAreaList(rowwkts, "row") + '</div>',
  264. '<div id="wperowPolygons" style="float:left; padding-left:15px;"><h3 style="position:relative; float:left; left:40%;">Area WKT</h3><br><textarea rows="7" cols="55" id="wperowAreaWKT" style="height:auto;"></textarea></div>',
  265. '</div>',//rowAreas
  266. '<div id="ilAreas" class="tab-pane fade">',
  267. '<div id="wpeilAreas" style="float:left; max-height:350px; overflow:auto;"><h3 style="float:left; left:50%;">Editor Areas</h3><br>' + buildAreaList(ilwkts, "il") + '</div>',
  268. '<div id="wpeilPolygons" style="float:left; padding-left:15px;"><h3 style="position:relative; float:left; left:40%;">Area WKT</h3><br><textarea rows="7" cols="55" id="wpeilAreaWKT" style="height:auto;"></textarea></div>',
  269. '</div>',//ilAreas
  270. '<div id="wpeFooter" style="clear:both; margin-top:10px;">View the areas by entering the WKT at <a href="http://map.wazedev.com" target="_blank">http://map.wazedev.com</a></div>',
  271. '</div>', //tab-content
  272. '</div>' //end main div
  273. ].join(' '));
  274.  
  275. $('body').append($section.html());
  276.  
  277. $('[id^="wpenaAreaButton"]').click(function(){
  278. let index = parseInt($(this)[0].id.replace("wpenaAreaButton", ""));
  279. $('#wpenaAreaWKT').text(nawkts[index]);
  280. $('#wpenaPolygons > h3').text(`Area ${index+1} WKT`);
  281. });
  282.  
  283. $('[id^="wperowAreaButton"]').click(function(){
  284. let index = parseInt($(this)[0].id.replace("wperowAreaButton", ""));
  285. $('#wperowAreaWKT').text(rowwkts[index]);
  286. $('#wperowPolygons > h3').text(`Area ${index+1} WKT`);
  287. });
  288.  
  289. $('[id^="wpeilAreaButton"]').click(function(){
  290. let index = parseInt($(this)[0].id.replace("wpeilAreaButton", ""));
  291. $('#wpeilAreaWKT').text(ilwkts[index]);
  292. $('#wpeilPolygons > h3').text(`Area ${index+1} WKT`);
  293. });
  294.  
  295. $('#wpenaCombinedAreaButton').click(function(){
  296. $('#wpenaAreaWKT').text(combinedNAWKT);
  297. $('#wpenaPolygons > h3').text(`Combined Area WKT`);
  298. });
  299.  
  300. $('#wperowCombinedAreaButton').click(function(){
  301. $('#wperowAreaWKT').text(combinedROWWKT);
  302. $('#wperowPolygons > h3').text(`Combined Area WKT`);
  303. });
  304.  
  305. $('#wpeilCombinedAreaButton').click(function(){
  306. $('#wpeilAreaWKT').text(combinedILWKT);
  307. $('#wpeilPolygons > h3').text(`Combined Area WKT`);
  308. });
  309.  
  310. $('#wpeClose').click(function(){
  311. if($('#wpeWKT').css('visibility') === 'visible')
  312. $('#wpeWKT').css({'visibility': 'hidden'});
  313. else
  314. $('#wpeWKT').css({'visibility': 'visible'});
  315. });
  316. }
  317. }
  318.  
  319. function AddEditorStatsSection(){
  320. let edits = W.EditorProfile.data.edits
  321. let editActivity = [].concat(W.EditorProfile.data.editingActivity);
  322. let rank = W.EditorProfile.data.rank+1;
  323. let count = 0;
  324. editActivity.forEach(function(x) {if(x !== 0) count++; });
  325. let editAverageDailyActive = Math.round(editActivity.reduce(reducer)/count);
  326. let editAverageDaily = Math.round(editActivity.reduce(reducer)/91);
  327.  
  328. var $editorProgress = $("<div>");
  329. $editorProgress.html([
  330. `<div id="collapsible" style="display:${settings.EditingStatsExpanded ? "block" : "none"};">`,
  331. '<div style="display:inline-block;"><div><h4>Average Edits per Day</h4></div><div>' + editAverageDaily + '</div></div>',
  332. '<div style="display:inline-block; margin-left:25px;"><div><h4>Average Edits per Day (active days only)</h4></div><div>' + editAverageDailyActive + '</div></div>',
  333. '<div class="editor-progress-list" style="display:flex; flex-flow:row wrap; justify-content:space-around;">',
  334. buildProgressItemsHTML(),
  335. '</div>'
  336. ].join(' '));
  337.  
  338. $('#editing-activity').append('<div id="editor-progress"><h3 id="collapseHeader" style="cursor:pointer;">Editing Stats</h3></div>');
  339. $('#editor-progress').append($editorProgress.html()+'</div>');
  340.  
  341. $('#collapseHeader').click(function(){
  342. $('#collapsible').toggle();
  343. settings.EditingStatsExpanded = ($('#collapsible').css("display") === "block");
  344. saveSettings();
  345. });
  346. }
  347.  
  348. function buildProgressItemsHTML(){
  349. var itemsArr = [];
  350. var $items = $("<div>");
  351. let editActivity = W.EditorProfile.data.editingActivity;
  352.  
  353. //loop over the 13 tracked weeks on the profile
  354. for(let i=0; i<13; i++){
  355. let header = "";
  356. let weekEditCount = 0;
  357. //let weekEditPct = 0;
  358. if(i==0){
  359. header = "Past 7 days";
  360. weekEditCount = editActivity.slice(-7).reduce(reducer);
  361. }
  362. else{
  363. header = `Past ${i*7+1} - ${(i+1)*7} days`;
  364. weekEditCount = editActivity.slice(-((i+1)*7),-i*7).reduce(reducer);
  365. }
  366. let weekDailyAvg = Math.round(weekEditCount/7*100)/100;
  367. itemsArr.push('<div style="margin-right:20px;">');
  368. itemsArr.push(`<h4>${header}</h4>`);
  369. itemsArr.push('<div class="editor-progress-item">');
  370. itemsArr.push(`<div class="editor-progress__name">Week\'s Edits</div><div class="editor-progress__count">${weekEditCount}</div>`); //, ${weekEditPct}%</div>`);
  371. itemsArr.push(`<div class="editor-progress__name">Average Edits/Day</div><div class="editor-progress__count">${weekDailyAvg}</div>`);
  372. itemsArr.push('</div></div>');
  373. }
  374. $items.html(itemsArr.join(' '));
  375. return $items.html();
  376. }
  377.  
  378. function AddEditingActivityAvgandTot(){
  379. $('.legend').append('<div class="day-initial">Avg</div> <div class="day-initial">Tot</div>');
  380. $('.editing-activity').css({"width":"1010px"}); //With adding the Avg and Tot rows we have to widen the div a little so it doesn't wrap one of the columns
  381.  
  382. let currWeekday = new Date().getDay();
  383. if(currWeekday === 0)
  384. currWeekday = 7;
  385. let localEditActivity = [].concat(W.EditorProfile.data.editingActivity);
  386. let weekEditsArr = localEditActivity.splice(-currWeekday);
  387. let weekEditsCount = weekEditsArr.reduce(reducer);
  388. var iteratorStart = 13;
  389. if(currWeekday === 7)
  390. iteratorStart = 12;
  391. $(`.weeks div:nth-child(${iteratorStart+1}) .week`).append(`<div class="day" style="font-size:10px; height:10px; text-align:center; margin-top:-5px;" title="Average edits per day for this week">${Math.round(weekEditsCount/currWeekday * 100) / 100}</div><div style="font-size:10px; height:10px; text-align:center;" title="Total edits for this week">${weekEditsCount}</div>`);
  392. for(let i=iteratorStart; i>0; i--){
  393. weekEditsArr = localEditActivity.splice(-7);
  394. weekEditsCount = weekEditsArr.splice(-7).reduce(reducer);
  395. let avg = Math.round(weekEditsCount/7 * 100) / 100;
  396. $(`.weeks div:nth-child(${i}) .week`).append(`<div class="day" style="font-size:10px; height:10px; text-align:center; margin-top:-5px;" title="Average edits per day for this week">${avg}</div><div style="font-size:10px; height:10px; text-align:center;" title="Total edits for this week">${weekEditsCount}</div>`);
  397. }
  398. }
  399.  
  400. function buildAreaList(wkts, server){
  401. let html = "";
  402. for(let i=0; i<wkts.length; i++){
  403. html +=`<button id="wpe${server}AreaButton${i}" class="s-button s-button--mercury " style="margin-bottom:5px;">Area ${i+1}</button><br>`;
  404. }
  405. if(wkts.length > 1)
  406. html +=`<button id="wpe${server}CombinedAreaButton" class="s-button s-button--mercury " style="margin-bottom:5px;">Combined</button><br>`;
  407. return html;
  408. }
  409.  
  410. function buildWKTArray(wktObj){
  411. let wkt = "";
  412. let combined = "";
  413. let wktArr = [];
  414. for(let i=0; i<wktObj.managedAreas.length; i++){
  415. if(i>0)
  416. combined += ",";
  417. wkt = "";
  418. combined += "(";
  419. for(let j=0; j<wktObj.managedAreas[i].coordinates.length; j++){
  420. if(j>0){
  421. wkt += ",";
  422. combined += ",";
  423. }
  424. combined += "(";
  425. wkt +="(";
  426. for(let k=0; k<wktObj.managedAreas[i].coordinates[j].length; k++){
  427. if(k > 0){
  428. wkt+=", ";
  429. combined += ",";
  430. }
  431. wkt += round(parseFloat(wktObj.managedAreas[i].coordinates[j][k][0])).toString() + " " + round(parseFloat(wktObj.managedAreas[i].coordinates[j][k][1])).toString();
  432. combined += round(parseFloat(wktObj.managedAreas[i].coordinates[j][k][0])).toString() + " " + round(parseFloat(wktObj.managedAreas[i].coordinates[j][k][1])).toString();
  433. }
  434. combined += ")";
  435. wkt += ")";
  436. }
  437. combined += ")";
  438. wkt = `POLYGON${wkt}`;
  439. wktArr.push(wkt);
  440. }
  441. if(wktObj.managedAreas.length > 1)
  442. combined = `MULTIPOLYGON(${combined})` ;
  443. else
  444. combined = `POLYGON${combined}`;
  445.  
  446. return {wktArr: wktArr, combinedWKT: combined};
  447. }
  448.  
  449. function round(val){
  450. return Math.round(val*1000000)/1000000;
  451. }
  452.  
  453. async function getManagedAreas(){
  454. naMA = await $.get(`https://www.waze.com/Descartes/app/UserProfile/Areas?userID=${W.EditorProfile.data.userID}`);
  455. rowMA = await $.get(`https://www.waze.com/row-Descartes/app/UserProfile/Areas?userID=${W.EditorProfile.data.userID}`);
  456. ilMA = await $.get(`https://www.waze.com/il-Descartes/app/UserProfile/Areas?userID=${W.EditorProfile.data.userID}`);
  457.  
  458. /*return await new W.EditorProfile.Models.ManagedAreas([],{
  459. lastEditEnv: 'na',
  460. userId: W.EditorProfile.data.userID
  461. }).fetch();*/
  462. }
  463.  
  464. function envChanged(e) {
  465. settings.Environment = e.target.value;
  466. saveSettings();
  467. location.reload();
  468. }
  469.  
  470. function injectCSS() {
  471. /*var css = [
  472. ].join(' ');
  473. $('<style type="text/css">' + css + '</style>').appendTo('head');*/
  474. }
  475.  
  476. function loadSettings() {
  477. var loadedSettings = JSON.parse(localStorage.getItem("WEPE_Settings"));
  478. var defaultSettings = {
  479. EditingStatsExpanded: true,
  480. Environment: 'default'
  481. };
  482. settings = loadedSettings ? loadedSettings : defaultSettings;
  483. for (var prop in defaultSettings) {
  484. if (!settings.hasOwnProperty(prop))
  485. settings[prop] = defaultSettings[prop];
  486. }
  487. }
  488.  
  489. function saveSettings() {
  490. if (localStorage) {
  491. var localsettings = {
  492. EditingStatsExpanded: settings.EditingStatsExpanded,
  493. Environment: settings.Environment
  494. };
  495.  
  496. localStorage.setItem("WEPE_Settings", JSON.stringify(localsettings));
  497. }
  498. }
  499. })();