Greasy Fork 还支持 简体中文。

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!

目前為 2019-04-04 提交的版本,檢視 最新版本

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