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

目前為 2018-07-03 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Waze Editor Profile Enhancements
  3. // @namespace http://tampermonkey.net/
  4. // @version 2018.07.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
  6. // @author JustinS83
  7. // @include https://www.waze.com/*user/editor*
  8. // @include https://beta.waze.com/*user/editor*
  9. // @grant GM_xmlhttpRequest
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. var wkts = [];
  16. let combinedWKT = "";
  17.  
  18. function bootstrap(tries) {
  19. tries = tries || 1;
  20.  
  21. if (W &&
  22. W.EditorProfile &&
  23. $) {
  24. init();
  25. } else if (tries < 1000) {
  26. console.log(tries);
  27. setTimeout(function () {bootstrap(tries++);}, 200);
  28. }
  29. }
  30.  
  31. bootstrap();
  32.  
  33. async function init(){
  34. $.get('https://www.waze.com/forum/memberlist.php?username=' + W.EditorProfile.data.username, function(forumResult){
  35. var re = 0;
  36. var matches = forumResult.match(/<a.*?"Search user’s posts">(\d+)<\/a>/);
  37. if(matches && matches.length > 0)
  38. re = matches[1];
  39. var WazeVal = $('#header > div > div.user-info > div > div.user-highlights > div > div:nth-child(3) > div.user-stats-value')[0].innerHTML.trim();
  40. var userForumID = forumResult.match(/<a href="\.\/memberlist\.php\?mode=viewprofile&amp;u=(\d+)"/)[1];
  41.  
  42. $('#header > div > div.user-info > div > div.user-highlights > div > div:nth-child(3) > div.highlight-title').css('position', 'relative');
  43.  
  44. if(WazeVal !== re.toString()){
  45. $('#header > div > div.user-info > div > div.user-highlights > div > div:nth-child(3) > div.user-stats-value')[0].innerHTML = re;
  46. $('#header > div > div.user-info > div > div.user-highlights > div > div:nth-child(3) > div.user-stats-value').css('color','red');
  47. $('#header > div > div.user-info > div > div.user-highlights > div > div:nth-child(3) > div.user-stats-value').prop('title', 'Waze reported value: ' + WazeVal);
  48. }
  49.  
  50. $('#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>');
  51.  
  52. $('#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>');
  53. });
  54.  
  55. var count = 0;
  56. W.EditorProfile.data.editingActivity.forEach(function(x) { if(x !== 0) count++; });
  57. $('#editing-activity > div > h3').append(" (" + count + " of last 91 days)");
  58.  
  59. let areas = await getManagedAreas();
  60.  
  61. if(areas.managedAreas.length > 0){
  62. $('#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>');
  63.  
  64. $('#userMA').click(function(){
  65. if($('#wpeWKT').css('visibility') === 'visible')
  66. $('#wpeWKT').css({'visibility': 'hidden'});
  67. else
  68. $('#wpeWKT').css({'visibility': 'visible'});
  69. });
  70.  
  71. let wkt = "";
  72. for(let i=0; i<areas.managedAreas.length; i++){
  73. if(i>0)
  74. combinedWKT += ",";
  75. wkt = "";
  76. combinedWKT += "(";
  77. for(let j=0; j<areas.managedAreas[i].coordinates.length; j++){
  78. if(j>0){
  79. wkt += ",";
  80. combinedWKT += ",";
  81. }
  82. combinedWKT += "(";
  83. wkt +="(";
  84. for(let k=0; k<areas.managedAreas[i].coordinates[j].length; k++){
  85. if(k > 0){
  86. wkt+=", ";
  87. combinedWKT += ",";
  88. }
  89. wkt += round(parseFloat(areas.managedAreas[i].coordinates[j][k][0])).toString() + " " + round(parseFloat(areas.managedAreas[i].coordinates[j][k][1])).toString();
  90. combinedWKT += round(parseFloat(areas.managedAreas[i].coordinates[j][k][0])).toString() + " " + round(parseFloat(areas.managedAreas[i].coordinates[j][k][1])).toString();
  91. }
  92. combinedWKT += ")";
  93. wkt += ")";
  94. }
  95. combinedWKT += ")";
  96. wkt = `POLYGON${wkt}`;
  97. wkts.push(wkt);
  98. }
  99. if(areas.managedAreas.length > 1)
  100. combinedWKT = `MULTIPOLYGON(${combinedWKT})` ;
  101. else
  102. combinedWKT = `POLYGON${combinedWKT}`;
  103. debugger;
  104. var $section = $("<div>", {style:"padding:8px 16px"});
  105. $section.html([
  106. '<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
  107. '<div id="wpeAreas" style="float:left;"><h3 style="float:left; left:50%;">Editor Areas</h3><br>' + buildAreaList() + '</div>',
  108. '<div id="wpePolygons" style="float:left; padding-left:15px;"><h3 style="position:relative; float:left; left:40%;">Area WKT</h3><br><textarea rows="7" cols="55" id="wpeAreaWKT" style="height:auto;"></textarea></div>',
  109. '<div id="wpeFooter" style="clear:both; margin-top:10px;">Display the WKT areas on <a href="http://map.wazedev.com" target="_blank">http://map.wazedev.com</a></div>',
  110. '</div>' //end main div
  111. ].join(' '));
  112.  
  113. $('body').append($section.html());
  114.  
  115. $('[id^="wpeAreaButton"]').click(function(){
  116. let index = parseInt($(this)[0].id.replace("wpeAreaButton", ""));
  117. $('#wpeAreaWKT').text(wkts[index]);
  118. $('#wpePolygons > h3').text(`Area ${index+1} WKT`);
  119. });
  120.  
  121. $('#wpeCombinedAreaButton').click(function(){
  122. $('#wpeAreaWKT').text(combinedWKT);
  123. $('#wpePolygons > h3').text(`Combined Area WKT`);
  124. });
  125. }
  126. }
  127.  
  128. function buildAreaList(){
  129. let html = "";
  130. for(let i=0; i<wkts.length; i++){
  131. html +=`<button id="wpeAreaButton${i}" class="btn btn-outline-primary" style="margin-bottom:5px;">Area ${i+1}</button><br>`;
  132. }
  133. if(wkts.length > 1)
  134. html +=`<button id="wpeCombinedAreaButton" class="btn btn-outline-primary" style="margin-bottom:5px;">Combined</button><br>`;
  135. return html;
  136. }
  137.  
  138. function round(val){
  139. return Math.round(val*1000000)/1000000;
  140. }
  141.  
  142. async function getManagedAreas(){
  143. return await new W.EditorProfile.Models.ManagedAreas([],{
  144. lastEditEnv: 'na',
  145. userId: W.EditorProfile.data.userID
  146. }).fetch();
  147. }
  148. })();