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!

当前为 2023-03-06 提交的版本,查看 最新版本

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