Waze Edit Count Monitor

Displays your daily edit count in the WME toolbar. Warns if you might be throttled.

目前为 2024-10-27 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Waze Edit Count Monitor
  3. // @namespace https://gf.qytechs.cn/en/users/45389-mapomatic
  4. // @version 2024.10.27.000
  5. // @description Displays your daily edit count in the WME toolbar. Warns if you might be throttled.
  6. // @author MapOMatic
  7. // @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor\/?.*$/
  8. // @require https://gf.qytechs.cn/scripts/24851-wazewrap/code/WazeWrap.js
  9. // @require https://update.gf.qytechs.cn/scripts/509664/WME%20Utils%20-%20Bootstrap.js
  10. // @license GNU GPLv3
  11. // @contributionURL https://github.com/WazeDev/Thank-The-Authors
  12. // @grant GM_xmlhttpRequest
  13. // @grant GM_addElement
  14. // @grant GM_addStyle
  15. // @connect www.waze.com
  16. // @connect gf.qytechs.cn
  17. // ==/UserScript==
  18.  
  19. /* global bootstrap */
  20.  
  21. (async function main() {
  22. 'use strict';
  23.  
  24. const downloadUrl = 'https://gf.qytechs.cn/scripts/40313-waze-edit-count-monitor/code/Waze%20Edit%20Count%20Monitor.user.js';
  25. const sdk = await bootstrap({ scriptUpdateMonitor: { downloadUrl } });
  26.  
  27. const TOOLTIP_TEXT = 'Your daily edit count from your profile. Click to open your profile.';
  28.  
  29. let $outputElem = null;
  30. let $outputElemContainer = null;
  31. let userName;
  32. let savesWithoutIncrease = 0;
  33. let lastProfile;
  34.  
  35. function log(message) {
  36. console.log('Edit Count Monitor:', message);
  37. }
  38.  
  39. function updateEditCount() {
  40. sdk.DataModel.Users.getUserProfile({ userName }).then(profile => {
  41. // Add the counter div if it doesn't exist.
  42. if ($('#wecm-count').length === 0) {
  43. $outputElemContainer = $('<div>', { class: 'toolbar-button', style: 'font-weight: bold; font-size: 16px; border-radius: 10px; margin-left: 4px;' });
  44. const $innerDiv = $('<div>', { class: 'item-container', style: 'padding-left: 10px; padding-right: 10px; cursor: default;' });
  45. $outputElem = $('<a>', {
  46. id: 'wecm-count',
  47. href: sdk.DataModel.Users.getUserProfileLink({ userName }),
  48. target: '_blank',
  49. style: 'text-decoration:none',
  50. 'data-original-title': TOOLTIP_TEXT
  51. });
  52. $innerDiv.append($outputElem);
  53. $outputElemContainer.append($innerDiv);
  54. if ($('#toolbar > div > div.secondary-toolbar > div.secondary-toolbar-actions > div.secondary-toolbar-actions-edit').length) {
  55. // Production WME, as of 4/25/2023
  56. $('#toolbar > div > div.secondary-toolbar > div.secondary-toolbar-actions > div.secondary-toolbar-actions-edit').after($outputElemContainer);
  57. } else {
  58. // Beta WME, as of 4/25/2023
  59. $('#toolbar > div > div.secondary-toolbar > div:nth-child(1)').after($outputElemContainer);
  60. }
  61. $outputElem.tooltip({
  62. placement: 'auto top',
  63. delay: { show: 100, hide: 100 },
  64. html: true,
  65. template: '<div class="tooltip wecm-tooltip" role="tooltip"><div class="tooltip-arrow"></div>'
  66. + '<div class="wecm-tooltip-header"><b></b></div>'
  67. + '<div class="wecm-tooltip-body tooltip-inner""></div></div>'
  68. });
  69. }
  70.  
  71. // log('edit count = ' + editCount + ', UR count = ' + urCount.count);
  72. // TODO: check all editCountByType values here?
  73. if (!lastProfile) {
  74. lastProfile = profile;
  75. } else if (lastProfile.editCount !== profile.editCount
  76. || lastProfile.editCountByType.updateRequests !== profile.editCountByType.updateRequests
  77. || lastProfile.editCountByType.mapProblems !== profile.editCountByType.mapProblems
  78. || lastProfile.editCountByType.placeUpdateRequests !== profile.editCountByType.placeUpdateRequests) {
  79. savesWithoutIncrease = 0;
  80. } else {
  81. savesWithoutIncrease++;
  82. }
  83.  
  84. let textColor;
  85. let bgColor;
  86. let warningStyleClass;
  87. if (savesWithoutIncrease < 5) {
  88. textColor = '#354148';
  89. bgColor = 'white';
  90. warningStyleClass = '';
  91. } else if (savesWithoutIncrease < 10) {
  92. textColor = '#354148';
  93. bgColor = 'yellow';
  94. warningStyleClass = 'yellow';
  95. } else {
  96. textColor = 'white';
  97. bgColor = 'red';
  98. warningStyleClass = 'red';
  99. }
  100. $outputElemContainer.css('background-color', bgColor);
  101.  
  102. $outputElem.css('color', textColor).html(profile.dailyEditCount[profile.dailyEditCount.length - 1].toLocaleString());
  103. const totalEditCountText = `<li>Total&nbsp;edits:&nbsp;${profile.totalEditCount.toLocaleString()}</li>`;
  104. const urCountText = `<li>URs&nbsp;closed:&nbsp;${profile.editCountByType.updateRequests.toLocaleString()}</li>`;
  105. const purCountText = `<li>PURs&nbsp;closed:&nbsp;${profile.editCountByType.placeUpdateRequests.toLocaleString()}</li>`;
  106. const mpCountText = `<li>MPs&nbsp;closed:&nbsp;${profile.editCountByType.mapProblems.toLocaleString()}</li>`;
  107. const segmentEditCountText = `<li>Segment&nbsp;edits:&nbsp;${profile.editCountByType.segments.toLocaleString()}</li>`;
  108. const placeEditCountText = `<li>Place&nbsp;edits:&nbsp;${profile.editCountByType.venues.toLocaleString()}</li>`;
  109. const hnEditCountText = `<li>Segment&nbsp;HN&nbsp;edits:&nbsp;${profile.editCountByType.segmentHouseNumbers.toLocaleString()}</li>`;
  110. let warningText = '';
  111. if (savesWithoutIncrease) {
  112. warningText = `<div class="wecm-warning ${warningStyleClass}">${savesWithoutIncrease} ${
  113. (savesWithoutIncrease > 1) ? 'consecutive saves' : 'save'} without an increase. ${
  114. (savesWithoutIncrease >= 5) ? '(Are you throttled?)' : ''}</div>`;
  115. }
  116. $outputElem.attr('data-original-title', `${
  117. TOOLTIP_TEXT}<ul>${
  118. totalEditCountText}${
  119. urCountText}${
  120. purCountText}${
  121. mpCountText}${
  122. segmentEditCountText}${
  123. hnEditCountText}${
  124. placeEditCountText}</ul>${
  125. warningText}`);
  126. lastProfile = profile;
  127. });
  128. }
  129.  
  130. async function init() {
  131. userName = sdk.State.getUserInfo().userName;
  132.  
  133. GM_addStyle(`
  134. .wecm-tooltip li {text-align: left;}
  135. .wecm-tooltip .wecm-warning {border-radius:8px; padding:3px; margin-top:8px; margin-bottom:5px;}
  136. .wecm-tooltip .wecm-warning.yellow {background-color:yellow; color:black;}
  137. .wecm-tooltip .wecm-warning.red {background-color:red; color:white;}
  138. `);
  139.  
  140. sdk.Events.on({ eventName: 'wme-save-finished', eventHandler: onSaveFinished });
  141. // Update the edit count first time.
  142. updateEditCount();
  143. log('Initialized.');
  144. }
  145.  
  146. function onSaveFinished(result) {
  147. if (result.success) updateEditCount();
  148. }
  149.  
  150. init();
  151. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址