WME Fix UR Interface

Fix the UR Interface that Waze devs ruined :(

目前为 2023-03-09 提交的版本,查看 最新版本

  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.10
  6. // @description Fix the UR Interface that Waze devs ruined :(
  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. var reportID;
  27. var conversationLength;
  28. const timer = ms => new Promise(res => setTimeout(res, ms))
  29. const pmIcon = 'data:image/png;base64,R0lGODlhDgAMAPcAANaGh6dLTs9obK5cXrpkZ9JydqtfYbZnaqhtb/Kjpverrcudn//b3P/n6LNQVZ9KT9l2e85zeL9zd35MT/+ip8mBheSZnZJkZ59ydb2Mj//AxP/BxbmMj/jAw//KzeO2uf7R1P/a3P/d35IxOMZlbMdocNZ1fMRvdslyesZ0eqZhZsBxd859hP+xt/ess6t6ft2ssIlQVuiLldqJkvyirKd0ebB9gphucqR6fv/Bx8SXnMqdor2UmMCXm//N0v/q7KZTXc1tealocJhpb/+yvP+2wP/EzP/N1K9baP+vvNSSnKx3f82YoMyXn//s7//x85ldZ7N0f7N1gLh5hLd5hLV5g6p4gf/e5P/h5qllcqFnc9CMmeScqqVcbadeb8SSnf/M1//x9NaPof/j6v/r8P/v9P/o8P/q8f/67//47v/37f/16v/37//59P/w5v/t4//28f/o3P/z7cmroP/x7P/39P/s5v/v6v/08f/e1v/q5f/o49Stpv/n4+KimfHMxv/i3v/w7olKQ7B7df/Qyv/Z1PbTz//19IBhX/jMya+Qjv/j4bVxboljYoVrav/m5cJ4d7ZwcOi4uP/Qz66QkP/09P///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAJYALAAAAAAOAAwAAAi4AC1JybJlChMdPHrsaEIFygdFGHyUCVOpTps2dQ6BgHGhUQYyHRj0sbMH0KJHITzEUOGCxQkDg/JAGtAAwIMcK4DQkEFEgyA/AQRAKOCgBQokSYKUIMCIUAQKI0yQMJJCSJEZFiYVuhNJwYEEEjZUQLRA0h81a+LMeSNHD59ECBxx+AEnDRs2aNzgCUTH0IQvXbhccXIGyxMRY8wcsfHCkhgvS2qAUYIBR5UoWqxY2ryZ0pAbnEMHBAA7';
  30.  
  31. (function () {
  32. 'use strict';
  33. //Bootstrap
  34. function bootstrap(tries = 1) {
  35. if (W && W.loginManager && W.map && W.loginManager.user && W.model
  36. && W.model.states && W.model.states.getObjectArray().length && WazeWrap && WazeWrap.Ready) {
  37. setTimeout(function () {
  38. //loadObserver();
  39. fixClosures();
  40. }, 500);
  41. } else if (tries < 1000) {
  42. setTimeout(function () { bootstrap(++tries); }, 200);
  43. }
  44. }
  45.  
  46. //thanks to dBsooner for providing the proper CSS for saving vertical space with the action buttons
  47. function injectCss() {
  48. $('<style = type="text/css">'
  49. + '#panel-container .mapUpdateRequest.panel .problem-edit .actions .controls-container label[for|="state"] { height: 22px; width: 162px; line-height: 26px; margin-bottom: 6px; }'
  50. + '#panel-container .mapUpdateRequest.panel .problem-edit[data-state="open"] .actions .controls-container label[for="state-solved"] { display: inline-block; }'
  51. + '#panel-container .mapUpdateRequest.panel .problem-edit[data-state="open"] .actions .controls-container label[for|="state-not-identified"] { display: inline-block; }'
  52. + '#panel-container .mapUpdateRequest.panel .problem-edit[data-state="solved"] .actions .controls-container label[for|="state-open"], '
  53. + '#panel-container .mapUpdateRequest.panel .problem-edit[data-state="not-identified"] .actions .controls-container label[for|="state-open"] { display: inline-block !important; }'
  54. + '#panel-container .mapUpdateRequest.panel .problem-edit[data-state="not-identified"] .actions .controls-container label[for|="state-not-identified"], '
  55. + '#panel-container .mapUpdateRequest.panel .problem-edit[data-state="not-identified"] .actions .controls-container label[for|="state-solved"] { display: none !important; }'
  56. + '</style>').appendTo('head');
  57. }
  58.  
  59. function loadObserver() {
  60. const element = document.getElementById("panel-container");
  61. const observer = new MutationObserver((mutations) => {
  62. mutations.forEach((mutation) => {
  63. const { target } = mutation;
  64. if (mutation.attributeName === 'class') {
  65. let intervalID = setInterval(function () {
  66. if (document.getElementsByClassName("comment-list")[0]) {
  67. let commentList = document.getElementsByClassName("comment-list");
  68. $('#panel-container .mapUpdateRequest .top-section .body .conversation .content .conversation-view .comment-list').hide();
  69. $('#panel-container .mapUpdateRequest .actions .section .content .controls-container').css('text-align', 'center');
  70. $('#panel-container .mapUpdateRequest .actions .section .content .controls-container label[for=state-solved]').css('width', '135px');
  71. $('#panel-container .mapUpdateRequest .actions .section .content .controls-container label[for=state-solved]').css('margin', '2px');
  72. $('#panel-container .mapUpdateRequest .actions .section .content .controls-container label[for=state-solved]').text("Solved");
  73. $('#panel-container .mapUpdateRequest .actions .section .content .controls-container label[for=state-not-identified]').css('width', '135px');
  74. $('#panel-container .mapUpdateRequest .actions .section .content .controls-container label[for=state-not-identified]').css('margin', '2px');
  75. $('#panel-container .mapUpdateRequest .actions .section .content .controls-container label[for=state-not-identified]').text("Not Identified");
  76. const shadowDOMstyle = document.createElement('style');
  77. shadowDOMstyle.innerHTML = '.wz-button.md { height: 30px !important; width: 60px !important; padding: 0px 6px !important; }';
  78. $('#panel-container .mapUpdateRequest .top-section .body .conversation .new-comment-form .send-button')[0].shadowRoot.appendChild(shadowDOMstyle.cloneNode(true));
  79. $('#panel-container .mapUpdateRequest .top-section .body .conversation .new-comment-form .new-comment-follow').css('height', '34px');
  80. $('#panel-container .mapUpdateRequest .top-section .body .conversation .new-comment-form .new-comment-follow').css('line-height', '34px');
  81. $('wz-button.send-button').css('margin', '0px');
  82. $('wz-button.send-button').css('padding', '2px');
  83.  
  84. clearInterval(intervalID);
  85. injectCss();
  86.  
  87. if (!document.getElementById("phuzReportComments")) {
  88. buildTheComments();
  89. $('#panel-container .mapUpdateRequest .top-section .body .conversation .new-comment-form .send-button').on('click', () => { appendNewComment(); });
  90. }
  91.  
  92. }
  93. }, 50);
  94. }
  95. });
  96. });
  97. observer.observe(element, { subtree: true, childList: true, attributes: true });
  98. }
  99.  
  100. function fixClosures() {
  101. const element = document.getElementById("edit-panel");
  102. const observer = new MutationObserver((mutations) => {
  103. mutations.forEach((mutation) => {
  104. if (document.getElementById("segment-edit-closures")) {
  105. $('#segment-edit-closures .closures .closures-list').css('display', 'inline');
  106. }
  107. });
  108. });
  109. observer.observe(element, { subtree: true, childList: true, attributes: true });
  110. }
  111.  
  112. function buildTheComments() {
  113. let reports = document.getElementsByClassName("map-problem");
  114. for (let i = 0; i < reports.length; i++) {
  115. if (reports[i].classList.contains("selected")) {
  116. reportID = (reports[i].getAttribute("data-id"));
  117. var newDiv = document.createElement("div");
  118. newDiv.id = "phuzReportComments";
  119. if (document.getElementById("phuzReportComments")) {
  120. //document.getElementById("phuzReportComments").remove();
  121. }
  122. $('#panel-container .mapUpdateRequest .top-section .body .conversation .content .conversation-view').prepend(newDiv);
  123. document.getElementById("phuzReportComments").style = "width: 100%";
  124. //document.getElementsByClassName("conversation-view")[0].prepend(newDiv);
  125. GM_xmlhttpRequest({
  126. method: "GET",
  127. url: "https://www.waze.com/Descartes/app/MapProblems/UpdateRequests?ids=" + reportID,
  128. onload: function (response) {
  129. let result = JSON.parse(response.responseText);
  130. let divHTML = "<table id=tblURConversation border=0 cellpadding=1 cellspacing=2 style='table-layout: fixed; width: 100%'>";
  131. let commentUser;
  132. conversationLength = result.updateRequestSessions.objects[0].comments.length;
  133. for (let i = 0; i < conversationLength; i++) {
  134. if (result.updateRequestSessions.objects[0].comments[i].userID == -1) {
  135. commentUser = "<font color=#26bae8>Reporter</font>";
  136. } else {
  137. for (let j = 0; j < result.users.objects.length; j++) {
  138. if (result.updateRequestSessions.objects[0].comments[i].userID == result.users.objects[j].id) {
  139. commentUser = "<a href='https://www.waze.com/forum/user_message_redirect.php?username=" + result.users.objects[j].userName + "' target='_blank'><img src='" + pmIcon + "'></a> " + result.users.objects[j].userName + "(" + (result.users.objects[j].rank + 1) + ")";
  140. }
  141. }
  142. }
  143. 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>";
  144. divHTML += "<tr style='background: #FFFFFF;border: 1px double #E6E6E6;border-radius: 1ex; '><td colspan=2 style='word-wrap:break-word !important;'>" + result.updateRequestSessions.objects[0].comments[i].text + "</td></tr>";
  145. }
  146. divHTML += "</tbody></table>";
  147. document.getElementById("phuzReportComments").innerHTML = divHTML;
  148. }
  149. });
  150. }
  151. }
  152. }
  153.  
  154. function appendNewComment() {
  155. let tblHTML = "";
  156. GM_xmlhttpRequest({
  157. method: "GET",
  158. url: "https://www.waze.com/Descartes/app/MapProblems/UpdateRequests?ids=" + reportID,
  159. onload: async function (response) {
  160. let result = JSON.parse(response.responseText);
  161. let commentUser;
  162. let resultLength = result.updateRequestSessions.objects[0].comments.length;
  163. //Remove the "No Comments" text if comments are present
  164. if (resultLength > 0) {
  165. $('#panel-container .mapUpdateRequest .top-section .body .conversation .content .conversation-view .no-comments').hide();
  166. }
  167. let lastCommentIndex = resultLength - 1;
  168. if (resultLength > conversationLength) {
  169. if (result.updateRequestSessions.objects[0].comments[lastCommentIndex].userID == -1) {
  170. commentUser = "<font color=#26bae8>Reporter</font>";
  171. } else {
  172. for (let j = 0; j < result.users.objects.length; j++) {
  173. if (result.updateRequestSessions.objects[0].comments[lastCommentIndex].userID == result.users.objects[j].id) {
  174. commentUser = "<a href='https://www.waze.com/forum/user_message_redirect.php?username=" + result.users.objects[j].userName + "' target='_blank'><img src='" + pmIcon + "'></a> " + result.users.objects[j].userName + "(" + (result.users.objects[j].rank + 1) + ")";
  175. }
  176. }
  177. }
  178. 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>";
  179. tblHTML += "<tr style='background: #FFFFFF;border: 1px double #E6E6E6;border-radius: 1ex; '><td colspan=2>" + result.updateRequestSessions.objects[0].comments[lastCommentIndex].text + "</td></tr>";
  180. $('#tblURConversation').append(tblHTML);
  181. conversationLength = resultLength;
  182. } else {
  183. await timer(50);
  184. appendNewComment();
  185. }
  186. }
  187. });
  188. }
  189.  
  190. bootstrap();
  191. loadObserver();
  192.  
  193. })();