WME Fix UR Interface

Fix the UR Interface

当前为 2022-01-21 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name WME Fix UR Interface
  3. // @namespace https://greasyfork.org/en/users/668704-phuz
  4. // @require https://greasyfork.org/scripts/24851-wazewrap/code/WazeWrap.js
  5. // @version 1.04
  6. // @description Fix the UR Interface
  7. // @author phuz
  8. // @include /^https:\/\/(www|beta)\.waze\.com\/(?!user\/)(.{2,6}\/)?editor\/?.*$/
  9. // @require http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js
  10. // @require https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.1/moment.min.js
  11. // @grant GM_xmlhttpRequest
  12. // @grant GM_info
  13. // @grant GM_fetch
  14. // @grant GM_addStyle
  15.  
  16. /* global OpenLayers */
  17. /* global W */
  18. /* global WazeWrap */
  19. /* global $ */
  20. /* global I18n */
  21. /* global _ */
  22. /* global MutationObserver */
  23.  
  24. // ==/UserScript==
  25.  
  26. (function () {
  27. 'use strict';
  28. //Bootstrap
  29. function bootstrap(tries = 1) {
  30. if (W && W.loginManager && W.map && W.loginManager.user && W.model
  31. && W.model.states && W.model.states.getObjectArray().length && WazeWrap && WazeWrap.Ready) {
  32. setTimeout(function () {
  33. //loadObserver();
  34. }, 500);
  35. } else if (tries < 1000) {
  36. setTimeout(function () { bootstrap(++tries); }, 200);
  37. }
  38. }
  39.  
  40. var reportID;
  41. var conversationLength;
  42. const timer = ms => new Promise(res => setTimeout(res, ms))
  43.  
  44. //thanks to dBsooner for providing the proper CSS for saving vertical space with the action buttons
  45. function injectCss() {
  46. $('<style = type="text/css">'
  47. + '#panel-container .mapUpdateRequest.panel .problem-edit .actions .controls-container label[for|="state"] { height: 22px; width: 162px; line-height: 26px; margin-bottom: 6px; }'
  48. + '#panel-container .mapUpdateRequest.panel .problem-edit[data-state="open"] .actions .controls-container label[for="state-solved"] { display: inline-block; }'
  49. + '#panel-container .mapUpdateRequest.panel .problem-edit[data-state="open"] .actions .controls-container label[for|="state-not-identified"] { display: inline-block; }'
  50. + '#panel-container .mapUpdateRequest.panel .problem-edit[data-state="solved"] .actions .controls-container label[for|="state-open"], '
  51. + '#panel-container .mapUpdateRequest.panel .problem-edit[data-state="not-identified"] .actions .controls-container label[for|="state-open"] { display: inline-block !important; }'
  52. + '#panel-container .mapUpdateRequest.panel .problem-edit[data-state="not-identified"] .actions .controls-container label[for|="state-not-identified"], '
  53. + '#panel-container .mapUpdateRequest.panel .problem-edit[data-state="not-identified"] .actions .controls-container label[for|="state-solved"] { display: none !important; }'
  54. + '</style>').appendTo('head');
  55. }
  56.  
  57. function loadObserver() {
  58. console.log("here we go...");
  59. const element = document.getElementById("panel-container");
  60. const observer = new MutationObserver((mutations) => {
  61. mutations.forEach((mutation) => {
  62. const { target } = mutation;
  63. if (mutation.attributeName === 'class') {
  64. let intervalID = setInterval(function () {
  65. if (document.getElementsByClassName("comment-list")[0]) {
  66. let commentList = document.getElementsByClassName("comment-list");
  67. $('#panel-container .mapUpdateRequest .top-section .body .conversation .conversation-region .conversation-view .comment-list').hide();
  68. $('#panel-container .mapUpdateRequest .actions .section .content .controls-container').css('text-align', 'center');
  69. $('#panel-container .mapUpdateRequest .actions .section .content .controls-container label[for=state-solved]').css('width', '135px');
  70. $('#panel-container .mapUpdateRequest .actions .section .content .controls-container label[for=state-solved]').css('margin', '2px');
  71. $('#panel-container .mapUpdateRequest .actions .section .content .controls-container label[for=state-solved]').text("Solved");
  72. $('#panel-container .mapUpdateRequest .actions .section .content .controls-container label[for=state-not-identified]').css('width', '135px');
  73. $('#panel-container .mapUpdateRequest .actions .section .content .controls-container label[for=state-not-identified]').css('margin', '2px');
  74. $('#panel-container .mapUpdateRequest .actions .section .content .controls-container label[for=state-not-identified]').text("Not Identified");
  75. const shadowDOMstyle = document.createElement('style');
  76. shadowDOMstyle.innerHTML = '.wz-button.md { height: 30px !important; width: 60px !important; padding: 0px 6px !important; }';
  77. $('#panel-container .mapUpdateRequest .top-section .body .conversation .new-comment-form .send-button')[0].shadowRoot.appendChild(shadowDOMstyle.cloneNode(true));
  78. $('#panel-container .mapUpdateRequest .top-section .body .conversation .new-comment-form .new-comment-follow').css('height', '34px');
  79. $('#panel-container .mapUpdateRequest .top-section .body .conversation .new-comment-form .new-comment-follow').css('line-height', '34px');
  80. $('wz-button.send-button').css('margin', '0px');
  81. $('wz-button.send-button').css('padding', '2px');
  82.  
  83. clearInterval(intervalID);
  84. injectCss();
  85.  
  86. if (!document.getElementById("phuzReportComments")) {
  87. buildTheComments();
  88. $('#panel-container .mapUpdateRequest .top-section .body .conversation .new-comment-form .send-button').on('click', () => { appendNewComment(); });
  89. }
  90.  
  91. }
  92. }, 50);
  93. }
  94. });
  95. });
  96. observer.observe(element, { subtree: true, childList: true, attributes: true });
  97. }
  98.  
  99. function buildTheComments() {
  100. let reports = document.getElementsByClassName("map-problem");
  101. for (i = 0; i < reports.length; i++) {
  102. if (reports[i].classList.contains("selected")) {
  103. reportID = (reports[i].getAttribute("data-id"));
  104. var newDiv = document.createElement("div");
  105. newDiv.id = "phuzReportComments";
  106. if (document.getElementById("phuzReportComments")) {
  107. //document.getElementById("phuzReportComments").remove();
  108. }
  109. $('#panel-container .mapUpdateRequest .top-section .body .conversation .conversation-region .conversation-view').prepend(newDiv);
  110. //document.getElementsByClassName("conversation-view")[0].prepend(newDiv);
  111. GM_xmlhttpRequest({
  112. method: "GET",
  113. url: "https://www.waze.com/Descartes/app/MapProblems/UpdateRequests?ids=" + reportID,
  114. onload: function (response) {
  115. let result = JSON.parse(response.responseText);
  116. let divHTML = "<table id=tblURConversation border=0 width=100% cellpadding=1 cellspacing=2>";
  117. let commentUser;
  118. conversationLength = result.updateRequestSessions.objects[0].comments.length;
  119. for (i = 0; i < conversationLength; i++) {
  120. if (result.updateRequestSessions.objects[0].comments[i].userID == -1) {
  121. commentUser = "<font color=#26bae8>Reporter</font>";
  122. } else {
  123. for (j = 0; j < result.users.objects.length; j++) {
  124. if (result.updateRequestSessions.objects[0].comments[i].userID == result.users.objects[j].id) {
  125. commentUser = result.users.objects[j].userName + "(" + (result.users.objects[j].rank + 1) + ")";
  126. }
  127. }
  128. }
  129. divHTML += "<tr><td><b>" + commentUser + "</b></td><td align=right style='font-size: 11px;'>" + moment(new Date(result.updateRequestSessions.objects[0].comments[i].createdOn)).format('lll') + "</td></tr>";
  130. divHTML += "<tr style='background: #FFFFFF;border: 1px double #E6E6E6;border-radius: 1ex; '><td colspan=2>" + result.updateRequestSessions.objects[0].comments[i].text + "</td></tr>";
  131. }
  132. divHTML += "</tbody></table>";
  133. divHTML += "<hr style='margin: 5px;'>";
  134. document.getElementById("phuzReportComments").innerHTML = divHTML;
  135. }
  136. });
  137. }
  138. }
  139. }
  140. function appendNewComment() {
  141. let tblHTML = "";
  142. GM_xmlhttpRequest({
  143. method: "GET",
  144. url: "https://www.waze.com/Descartes/app/MapProblems/UpdateRequests?ids=" + reportID,
  145. onload: async function (response) {
  146. let result = JSON.parse(response.responseText);
  147. let commentUser;
  148. let resultLength = result.updateRequestSessions.objects[0].comments.length;
  149. let lastCommentIndex = resultLength - 1;
  150. if (resultLength > conversationLength) {
  151. if (result.updateRequestSessions.objects[0].comments[lastCommentIndex].userID == -1) {
  152. commentUser = "<font color=#26bae8>Reporter</font>";
  153. } else {
  154. for (j = 0; j < result.users.objects.length; j++) {
  155. if (result.updateRequestSessions.objects[0].comments[lastCommentIndex].userID == result.users.objects[j].id) {
  156. commentUser = result.users.objects[j].userName + "(" + (result.users.objects[j].rank + 1) + ")";
  157. }
  158. }
  159. }
  160. tblHTML += "<tr><td><b>" + commentUser + "</b></td><td align=right style='font-size: 11px;'>" + moment(new Date(result.updateRequestSessions.objects[0].comments[lastCommentIndex].createdOn)).format('lll') + "</td></tr>";
  161. tblHTML += "<tr style='background: #FFFFFF;border: 1px double #E6E6E6;border-radius: 1ex; '><td colspan=2>" + result.updateRequestSessions.objects[0].comments[lastCommentIndex].text + "</td></tr>";
  162. $('#tblURConversation').append(tblHTML);
  163. conversationLength = resultLength;
  164. } else {
  165. await timer(50);
  166. appendNewComment();
  167. }
  168. }
  169. });
  170. }
  171.  
  172. bootstrap();
  173. loadObserver();
  174. })();