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!

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

  1. // ==UserScript==
  2. // @name Waze Editor Profile Enhancements
  3. // @namespace http://tampermonkey.net/
  4. // @version 2022.08.06.01
  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 > a').prepend('<a href="https://www.waze.com/forum/memberlist.php?mode=viewprofile&u=' + userForumID +'" target="_blank" style="margin-right:5px;"><button class="message s-modern-button s-modern"><i class="fa fa-user"></i><span>Forum Profile</span></button></a>');
  99.  
  100. // Additional "Load more" at the top of the list
  101. $('#recent-edits > div > div > div > div.recent-edits-list > div > div.recent-edits-list-header').after('<div class="recent-edits-load-more"> <button class="s-button s-button--mercury "> Load More </button> </div>');
  102. var scrollarea = document.querySelector('#recent-edits .recent-edits-list .recent-edits-scrollable');
  103. scrollarea.style.height = '492px';
  104. }
  105. });
  106.  
  107. var count = 0;
  108. W.EditorProfile.data.editingActivity.forEach(function(x) { if(x !== 0) count++; });
  109. $('#editing-activity > div > h3').append(" (" + count + " of last 91 days)");
  110.  
  111. await getManagedAreas();
  112. BuildManagedAreasWKTInterface();
  113. /************** Add Average & Total to Editing Activity ***********/
  114. AddEditingActivityAvgandTot();
  115. /************** Add Editor Stats Section **************/
  116. AddEditorStatsSection();
  117.  
  118. initEnvironmentChooser();
  119. }
  120.  
  121. function initEnvironmentChooser(){
  122. let highlight = document.createElement('div');
  123. highlight.className="highlight";
  124. let highlightTitle = document.createElement('div');
  125. highlightTitle.className="highlight-title";
  126. let highlightTitleIcon = document.createElement('div');
  127. //highlightTitleIcon.className="highlight-title-icon posts";
  128. highlightTitleIcon.setAttribute('style',getIconStyle());
  129. let highlightTitleText = document.createElement('div');
  130. highlightTitleText.className="highlight-title-text";
  131. let userStatsValue = document.createElement('div');
  132. userStatsValue.className="user-stats-value";
  133.  
  134. highlightTitle.appendChild(highlightTitleIcon);
  135. highlightTitle.appendChild(highlightTitleText);
  136. highlight.appendChild(highlightTitle);
  137. highlight.appendChild(userStatsValue);
  138.  
  139. highlightTitleText.innerHTML = 'Environments';
  140. userStatsValue.setAttribute('style','margin-top: -10px;font-size: 17px;');
  141.  
  142. let frag = document.createDocumentFragment(),
  143. select = document.createElement("select");
  144. select.id = 'environmentSelect';
  145. select.name = 'environmentSelect';
  146. 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;');
  147.  
  148. select.options.add( new Option("Last Edit (" + lastEditEnv.toUpperCase() + ")","default", true, true) );
  149. select.options.add( new Option("NA","na") );
  150. select.options.add( new Option("ROW","row") );
  151. select.options.add( new Option("IL","il") );
  152.  
  153. for (var i = 0; i < select.options.length; i++) {
  154. if (select.options[i].value == settings.Environment)
  155. select.options[i].selected = true;
  156. }
  157.  
  158. frag.appendChild(select);
  159. document.getElementsByClassName('user-stats')[0].prepend(highlight);
  160. userStatsValue.appendChild(frag);
  161.  
  162. document.querySelector('select[name="environmentSelect"]').onchange = envChanged;
  163. }
  164.  
  165. function getIconStyle() {
  166. let tempQuerySelector = document.querySelector('#edits-by-type .venue-icon');
  167. let tempComputedStyle = window.getComputedStyle(tempQuerySelector);
  168. let iconStyle =
  169. `background-image:${tempComputedStyle.getPropertyValue('background-image')};`
  170. + `background-size:${tempComputedStyle.getPropertyValue('background-size')};`
  171. + `background-position:${tempComputedStyle.getPropertyValue('background-position')};`
  172. + `width:${tempComputedStyle.getPropertyValue('width')};`
  173. + `height:${tempComputedStyle.getPropertyValue('height')};`
  174. + `transform: scale(0.5);`
  175. + `display: inline-block;`
  176. + `float: left;`
  177. + `position: relative;`
  178. + `top: -10px;`
  179. + `left: -9px;`
  180. + `margin-right: -18px;`
  181. + `filter: invert(10%) sepia(39%) saturate(405%) hue-rotate(152deg) brightness(99%) contrast(86%);`;
  182. return iconStyle;
  183. }
  184.  
  185. function AddLabelsToAreas(){
  186. if($('svg.leaflet-zoom-animated').length > 0){
  187. $('svg.leaflet-zoom-animated g > text').remove();
  188. var svg = $('svg.leaflet-zoom-animated')[0];
  189. var pt = svg.createSVGPoint(), svgP;
  190.  
  191. let displayedAreas = $('svg.leaflet-zoom-animated g');
  192.  
  193. for(let i=0;i<displayedAreas.length;i++){
  194. let windowPosition = $(displayedAreas[i])[0].getBoundingClientRect();
  195. pt.x = (windowPosition.left + windowPosition.right) / 2;
  196. pt.y = (windowPosition.top + windowPosition.bottom) / 2;
  197. svgP = pt.matrixTransform(svg.getScreenCTM().inverse());
  198.  
  199. if(svgP.x != 0 && svgP.y != 0){
  200. var newText = document.createElementNS("http://www.w3.org/2000/svg","text");
  201. newText.setAttributeNS(null,"x",svgP.x - (`Area ${i+1}`.visualLength() /2));
  202. newText.setAttributeNS(null,"y",svgP.y);
  203. newText.setAttributeNS(null, "fill", "red");
  204. newText.setAttributeNS(null,"font-size","12");
  205.  
  206. var textNode = document.createTextNode(`Area ${i+1}`);
  207. newText.appendChild(textNode);
  208. $(displayedAreas[i])[0].appendChild(newText);
  209. }
  210. }
  211. }
  212. }
  213.  
  214. function BuildManagedAreasWKTInterface(){
  215. if(naMA.managedAreas.length > 0 || rowMA.managedAreas.length > 0 || ilMA.managedAreas.length > 0){
  216. $('#header > div > div.user-info > div > div.user-highlights > a').append('<a href="#" title="View editor\'s managed areas in WKT format"><button class="message s-modern-button s-modern" id="userMA"><i class="fa fa-map-o" aria-hidden="true"></i></button></a>');
  217.  
  218. /****** MO to update labels when panning/zooming the map ************/
  219. var observer = new MutationObserver(function(mutations) {
  220. mutations.forEach(function(mutation) {
  221. if ($(mutation.target).hasClass('leaflet-map-pane') && (mutation.attributeName === "class" || mutation.attributeName === "style")){
  222. if(mutation.attributeName === "class" && mutation.target.classList.length == 1) //zoom has ended, we can redraw our labels
  223. setTimeout(AddLabelsToAreas, 200);
  224. else if(mutation.attributeName === "style") //panning the map
  225. setTimeout(AddLabelsToAreas, 200);
  226. }
  227. });
  228. });
  229. observer.observe(document.getElementsByClassName('component-map-view')[0], { childList: true, subtree: true, attributes:true });
  230.  
  231. AddLabelsToAreas();
  232.  
  233. $('#userMA').click(function(){
  234. if($('#wpeWKT').css('visibility') === 'visible')
  235. $('#wpeWKT').css({'visibility': 'hidden'});
  236. else
  237. $('#wpeWKT').css({'visibility': 'visible'});
  238. });
  239.  
  240. var result = buildWKTArray(naMA);
  241. nawkts = result.wktArr;
  242. combinedNAWKT = result.combinedWKT;
  243.  
  244. result = buildWKTArray(rowMA);
  245. rowwkts = result.wktArr;
  246. combinedROWWKT = result.combinedWKT;
  247.  
  248. result = buildWKTArray(ilMA);
  249. ilwkts = result.wktArr;
  250. combinedILWKT = result.combinedWKT;
  251.  
  252. var $section = $("<div>", {style:"padding:8px 16px"});
  253. $section.html([
  254. '<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
  255. '<div style="float:right; cursor:pointer;" id="wpeClose"><i class="fa fa-window-close" aria-hidden="true"></i></div>',
  256. '<ul class="nav nav-tabs">',
  257. `${naMA.managedAreas.length > 0 ? '<li class="active"><a data-toggle="pill" href="#naAreas">NA</a></li>' : ''}`,
  258. `${rowMA.managedAreas.length > 0 ? '<li><a data-toggle="pill" href="#rowAreas">ROW</a></li>' : ''}`,
  259. `${ilMA.managedAreas.length > 0 ? '<li><a data-toggle="pill" href="#ilAreas">IL</a></li>' : ''}`,
  260. '</ul>',
  261. '<div class="tab-content">',
  262. '<div id="naAreas" class="tab-pane fade in active">',
  263. '<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>',
  264. '<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>',
  265. '</div>',//naAreas
  266. '<div id="rowAreas" class="tab-pane fade">',
  267. '<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>',
  268. '<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>',
  269. '</div>',//rowAreas
  270. '<div id="ilAreas" class="tab-pane fade">',
  271. '<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>',
  272. '<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>',
  273. '</div>',//ilAreas
  274. '<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>',
  275. '</div>', //tab-content
  276. '</div>' //end main div
  277. ].join(' '));
  278.  
  279. $('body').append($section.html());
  280.  
  281. $('[id^="wpenaAreaButton"]').click(function(){
  282. let index = parseInt($(this)[0].id.replace("wpenaAreaButton", ""));
  283. $('#wpenaAreaWKT').text(nawkts[index]);
  284. $('#wpenaPolygons > h3').text(`Area ${index+1} WKT`);
  285. });
  286.  
  287. $('[id^="wperowAreaButton"]').click(function(){
  288. let index = parseInt($(this)[0].id.replace("wperowAreaButton", ""));
  289. $('#wperowAreaWKT').text(rowwkts[index]);
  290. $('#wperowPolygons > h3').text(`Area ${index+1} WKT`);
  291. });
  292.  
  293. $('[id^="wpeilAreaButton"]').click(function(){
  294. let index = parseInt($(this)[0].id.replace("wpeilAreaButton", ""));
  295. $('#wpeilAreaWKT').text(ilwkts[index]);
  296. $('#wpeilPolygons > h3').text(`Area ${index+1} WKT`);
  297. });
  298.  
  299. $('#wpenaCombinedAreaButton').click(function(){
  300. $('#wpenaAreaWKT').text(combinedNAWKT);
  301. $('#wpenaPolygons > h3').text(`Combined Area WKT`);
  302. });
  303.  
  304. $('#wperowCombinedAreaButton').click(function(){
  305. $('#wperowAreaWKT').text(combinedROWWKT);
  306. $('#wperowPolygons > h3').text(`Combined Area WKT`);
  307. });
  308.  
  309. $('#wpeilCombinedAreaButton').click(function(){
  310. $('#wpeilAreaWKT').text(combinedILWKT);
  311. $('#wpeilPolygons > h3').text(`Combined Area WKT`);
  312. });
  313.  
  314. $('#wpeClose').click(function(){
  315. if($('#wpeWKT').css('visibility') === 'visible')
  316. $('#wpeWKT').css({'visibility': 'hidden'});
  317. else
  318. $('#wpeWKT').css({'visibility': 'visible'});
  319. });
  320. }
  321. }
  322.  
  323. function AddEditorStatsSection(){
  324. let edits = W.EditorProfile.data.edits
  325. let editActivity = [].concat(W.EditorProfile.data.editingActivity);
  326. let rank = W.EditorProfile.data.rank+1;
  327. let count = 0;
  328. editActivity.forEach(function(x) {if(x !== 0) count++; });
  329. let editAverageDailyActive = Math.round(editActivity.reduce(reducer)/count);
  330. let editAverageDaily = Math.round(editActivity.reduce(reducer)/91);
  331.  
  332. var $editorProgress = $("<div>");
  333. $editorProgress.html([
  334. `<div id="collapsible" style="display:${settings.EditingStatsExpanded ? "block" : "none"};">`,
  335. '<div style="display:inline-block;"><div><h4>Average Edits per Day</h4></div><div>' + editAverageDaily + '</div></div>',
  336. '<div style="display:inline-block; margin-left:25px;"><div><h4>Average Edits per Day (active days only)</h4></div><div>' + editAverageDailyActive + '</div></div>',
  337. '<div class="editor-progress-list" style="display:flex; flex-flow:row wrap; justify-content:space-around;">',
  338. buildProgressItemsHTML(),
  339. '</div>'
  340. ].join(' '));
  341.  
  342. $('#editing-activity').append('<div id="editor-progress"><h3 id="collapseHeader" style="cursor:pointer;">Editing Stats</h3></div>');
  343. $('#editor-progress').append($editorProgress.html()+'</div>');
  344.  
  345. $('#collapseHeader').click(function(){
  346. $('#collapsible').toggle();
  347. settings.EditingStatsExpanded = ($('#collapsible').css("display") === "block");
  348. saveSettings();
  349. });
  350. }
  351.  
  352. function buildProgressItemsHTML(){
  353. var itemsArr = [];
  354. var $items = $("<div>");
  355. let editActivity = W.EditorProfile.data.editingActivity;
  356.  
  357. //loop over the 13 tracked weeks on the profile
  358. for(let i=0; i<13; i++){
  359. let header = "";
  360. let weekEditCount = 0;
  361. //let weekEditPct = 0;
  362. if(i==0){
  363. header = "Past 7 days";
  364. weekEditCount = editActivity.slice(-7).reduce(reducer);
  365. }
  366. else{
  367. header = `Past ${i*7+1} - ${(i+1)*7} days`;
  368. weekEditCount = editActivity.slice(-((i+1)*7),-i*7).reduce(reducer);
  369. }
  370. let weekDailyAvg = Math.round(weekEditCount/7*100)/100;
  371. itemsArr.push('<div style="margin-right:20px;">');
  372. itemsArr.push(`<h4>${header}</h4>`);
  373. itemsArr.push('<div class="editor-progress-item">');
  374. itemsArr.push(`<div class="editor-progress__name">Week\'s Edits</div><div class="editor-progress__count">${weekEditCount}</div>`); //, ${weekEditPct}%</div>`);
  375. itemsArr.push(`<div class="editor-progress__name">Average Edits/Day</div><div class="editor-progress__count">${weekDailyAvg}</div>`);
  376. itemsArr.push('</div></div>');
  377. }
  378. $items.html(itemsArr.join(' '));
  379. return $items.html();
  380. }
  381.  
  382. function AddEditingActivityAvgandTot(){
  383. $('.legend').append('<div class="day-initial">Avg</div> <div class="day-initial">Tot</div>');
  384. $('.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
  385.  
  386. let currWeekday = new Date().getDay();
  387. if(currWeekday === 0)
  388. currWeekday = 7;
  389. let localEditActivity = [].concat(W.EditorProfile.data.editingActivity);
  390. let weekEditsArr = localEditActivity.splice(-currWeekday);
  391. let weekEditsCount = weekEditsArr.reduce(reducer);
  392. var iteratorStart = 13;
  393. if(currWeekday === 7)
  394. iteratorStart = 12;
  395. $(`.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>`);
  396. for(let i=iteratorStart; i>0; i--){
  397. weekEditsArr = localEditActivity.splice(-7);
  398. weekEditsCount = weekEditsArr.splice(-7).reduce(reducer);
  399. let avg = Math.round(weekEditsCount/7 * 100) / 100;
  400. $(`.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>`);
  401. }
  402. }
  403.  
  404. function buildAreaList(wkts, server){
  405. let html = "";
  406. for(let i=0; i<wkts.length; i++){
  407. html +=`<button id="wpe${server}AreaButton${i}" class="s-button s-button--mercury " style="margin-bottom:5px;">Area ${i+1}</button><br>`;
  408. }
  409. if(wkts.length > 1)
  410. html +=`<button id="wpe${server}CombinedAreaButton" class="s-button s-button--mercury " style="margin-bottom:5px;">Combined</button><br>`;
  411. return html;
  412. }
  413.  
  414. function buildWKTArray(wktObj){
  415. let wkt = "";
  416. let combined = "";
  417. let wktArr = [];
  418. for(let i=0; i<wktObj.managedAreas.length; i++){
  419. if(i>0)
  420. combined += ",";
  421. wkt = "";
  422. combined += "(";
  423. for(let j=0; j<wktObj.managedAreas[i].coordinates.length; j++){
  424. if(j>0){
  425. wkt += ",";
  426. combined += ",";
  427. }
  428. combined += "(";
  429. wkt +="(";
  430. for(let k=0; k<wktObj.managedAreas[i].coordinates[j].length; k++){
  431. if(k > 0){
  432. wkt+=", ";
  433. combined += ",";
  434. }
  435. wkt += round(parseFloat(wktObj.managedAreas[i].coordinates[j][k][0])).toString() + " " + round(parseFloat(wktObj.managedAreas[i].coordinates[j][k][1])).toString();
  436. combined += round(parseFloat(wktObj.managedAreas[i].coordinates[j][k][0])).toString() + " " + round(parseFloat(wktObj.managedAreas[i].coordinates[j][k][1])).toString();
  437. }
  438. combined += ")";
  439. wkt += ")";
  440. }
  441. combined += ")";
  442. wkt = `POLYGON${wkt}`;
  443. wktArr.push(wkt);
  444. }
  445. if(wktObj.managedAreas.length > 1)
  446. combined = `MULTIPOLYGON(${combined})` ;
  447. else
  448. combined = `POLYGON${combined}`;
  449.  
  450. return {wktArr: wktArr, combinedWKT: combined};
  451. }
  452.  
  453. function round(val){
  454. return Math.round(val*1000000)/1000000;
  455. }
  456.  
  457. async function getManagedAreas(){
  458. naMA = await $.get(`https://www.waze.com/Descartes/app/UserProfile/Areas?userID=${W.EditorProfile.data.userID}`);
  459. rowMA = await $.get(`https://www.waze.com/row-Descartes/app/UserProfile/Areas?userID=${W.EditorProfile.data.userID}`);
  460. ilMA = await $.get(`https://www.waze.com/il-Descartes/app/UserProfile/Areas?userID=${W.EditorProfile.data.userID}`);
  461.  
  462. /*return await new W.EditorProfile.Models.ManagedAreas([],{
  463. lastEditEnv: 'na',
  464. userId: W.EditorProfile.data.userID
  465. }).fetch();*/
  466. }
  467.  
  468. function envChanged(e) {
  469. settings.Environment = e.target.value;
  470. saveSettings();
  471. location.reload();
  472. }
  473.  
  474. function injectCSS() {
  475. /*var css = [
  476. ].join(' ');
  477. $('<style type="text/css">' + css + '</style>').appendTo('head');*/
  478. }
  479.  
  480. function loadSettings() {
  481. var loadedSettings = JSON.parse(localStorage.getItem("WEPE_Settings"));
  482. var defaultSettings = {
  483. EditingStatsExpanded: true,
  484. Environment: 'default'
  485. };
  486. settings = loadedSettings ? loadedSettings : defaultSettings;
  487. for (var prop in defaultSettings) {
  488. if (!settings.hasOwnProperty(prop))
  489. settings[prop] = defaultSettings[prop];
  490. }
  491. }
  492.  
  493. function saveSettings() {
  494. if (localStorage) {
  495. var localsettings = {
  496. EditingStatsExpanded: settings.EditingStatsExpanded,
  497. Environment: settings.Environment
  498. };
  499.  
  500. localStorage.setItem("WEPE_Settings", JSON.stringify(localsettings));
  501. }
  502. }
  503. })();