MENDO.MK Enhancement

Adds dark mode, search in tasks and other to MENDO.MK

当前为 2022-09-08 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name MENDO.MK Enhancement
  3. // @namespace -
  4. // @version 2
  5. // @description Adds dark mode, search in tasks and other to MENDO.MK
  6. // @author Plantt
  7. // @match https://mendo.mk/*
  8. // @match http://mendo.mk/*
  9. // @icon https://mendo.mk/img/favicon.ico
  10. // @grant none
  11. // @license CC-BY-ND
  12. // ==/UserScript==
  13.  
  14. console.log("%cMENDO.MK Enhancement%c loaded", "color: magenta; text-decoration: underline", "");
  15. var loadingSuccess = false;
  16. setTimeout(() => {
  17. if (loadingSuccess) {
  18. console.log("Loading %csuccessful", "color: #0f0");
  19. }
  20. else {
  21. console.warn("Loading %cunsuccessful", "color: red");
  22. }
  23. }, 1000);
  24. async function MendoMkEnhancement() {
  25. function logFinish(taskName) {
  26. console.log("%cFinished task:%c " + taskName, "color: #0f0", "");
  27. }
  28. console.groupCollapsed("Start log");
  29. loadingSuccess = true;
  30. var style = document.createElement("style");
  31. style.innerHTML = `
  32. html, img, svg, #cboxOverlay {
  33. filter: invert(1);
  34. }
  35. body, img, svg {
  36. background: white;
  37. }
  38. ::-webkit-scrollbar {
  39. width: initial;
  40. }
  41. ::-webkit-scrollbar-track {
  42. background: #111;
  43. }
  44. ::-webkit-scrollbar-thumb {
  45. background: #222;
  46. }
  47. #search {
  48. font-family: consolas;
  49. }
  50. #search, #search-submit {
  51. border: solid 2px black;
  52. }
  53. #search-submit:hover {
  54. cursor: pointer;
  55. }
  56. #search:focus {
  57. background: #eee;
  58. }
  59. #search-submit:hover, #search:hover {
  60. background: #ddd;
  61. }
  62. .copy-io-btn {
  63. float: right;
  64. background: #222;
  65. padding: 5px;
  66. filter: invert(1);
  67. cursor: pointer;
  68. border-radius: 5px;
  69. user-select: none;
  70. }
  71. .copy-io-btn:hover {
  72. background: #181818;
  73. }
  74. /*
  75. * {
  76. color: white !important;
  77. background-color: #222 !important;
  78. }
  79. h1.pagetitle {
  80. border-bottom-color: rgb(60, 60, 60) !important;
  81. }
  82. a {
  83. color: darkred !important;
  84. }
  85. div.main-navigation *, div.main-navigation {
  86. background-color: #111 !important;
  87. }
  88. */
  89. `;
  90. document.head.appendChild(style);
  91. logFinish("dark mode");
  92. if (/^http(s)?:\/\/(www\.)?mendo\.mk\/Training\.do/.test(document.URL)) {
  93. logFinish("training site detected");
  94. document.querySelectorAll("div.main-content > div:nth-child(3) > div > table > tbody > tr > td:nth-child(2) > a").forEach(e => {
  95. e.target = "_blank";
  96. });
  97. logFinish("make task links open in another window");
  98. var search = document.createElement("form");
  99. search.className = "content-search";
  100. search.action = "#";
  101. search.innerHTML = `
  102. <input type=text id=search autocomplete=off>
  103. <input type=submit id=search-submit value=Search>
  104. `;
  105. search.onsubmit = e => {
  106. e.preventDefault();
  107. var kw = search.querySelector("#search").value.toLowerCase();
  108. document.querySelectorAll("body > div.page-container > div.main > div.main-content > div:nth-child(4) > div > table > tbody > tr").forEach(elm => {
  109. if (!elm.querySelector("td:nth-child(2) > a")) {
  110. return;
  111. }
  112. if (elm.innerText.toLowerCase().includes(kw) || elm.querySelector("td:nth-child(2) > a").href.toLowerCase().includes(kw)) {
  113. elm.style.display = "";
  114. }
  115. else {
  116. elm.style.display = "none";
  117. }
  118. });
  119. }
  120. document.querySelector(".main-content").prepend(search);
  121. logFinish("add task search bar");
  122. }
  123. if (document.querySelector("body > div.page-container > div.header > div.header-breadcrumbs > ul > li:last-child > a")) {
  124. window.name = document.querySelector("body > div.page-container > div.header > div.header-breadcrumbs > ul > li:last-child > a").innerText;
  125. }
  126. else if (document.querySelector(".pagetitle")) {
  127. window.name = document.querySelector(".pagetitle").innerText;
  128. }
  129. document.title = window.name + " – МЕНДО";
  130. logFinish("document title set");
  131. if (document.URL.includes("Task.do?id=")) {
  132. document.querySelectorAll("body > div.page-container > div.main > div.main-content > div.column1-unit.taskContentView > table pre").forEach(pre => {
  133. var text = pre.innerText.substr(pre.innerText.indexOf("\n") + 1);
  134. var copyIoBtn = document.createElement("span");
  135. copyIoBtn.innerText = "📃";
  136. copyIoBtn.setAttribute("onclick", `navigator.clipboard.writeText(${JSON.stringify(text)})`);
  137. copyIoBtn.className = "copy-io-btn";
  138. pre.parentElement.appendChild(copyIoBtn);
  139. });
  140. logFinish("copy io buttons");
  141. }
  142. /*
  143. if (/^http(s)?:\/\/(www\.)?mendo\.mk\/Task\.do/.test(document.URL)) {
  144. await fetch("https://entityplantt.github.io/Canvas2d.js/Canvas2d.js").then(arg => arg.text()).then((1, eval));
  145. console.log(window.Canvas2d);
  146. async function nameOf(id) {
  147. var i = document.createElement("iframe");
  148. i.src = "https://mendo.mk/Task.do?id=" + id;
  149. i.style.display = "none";
  150. document.body.append(i);
  151. await new Promise(res => {
  152. i.onload = res;
  153. });
  154. if (!i.contentDocument.querySelector(".pagetitle")) {
  155. return null;
  156. }
  157. const r = i.contentDocument.querySelector(".pagetitle").innerText;
  158. i.remove();
  159. return r;
  160. }
  161. window.nameOf = nameOf;
  162. var canvas = new window.Canvas2d.Scene(), id = parseInt(document.URL.substr(28));
  163. canvas.background = "#111";
  164. var grayCircle = await fetch("https://upload.wikimedia.org/wikipedia/commons/thumb/5/55/Small-dark-grey-circle.svg/1024px-Small-dark-grey-circle.svg.png").then(arg => arg.blob());
  165. grayCircle = await createImageBitmap(grayCircle);
  166. document.querySelector(".main-content").prepend(canvas.canvas);
  167. canvas.width = 500;
  168. var points = new Array, boundLeft = id, boundRight = id, selected = id;
  169. async function addToPoints(id) {
  170. points[id] = await nameOf(id);
  171. var img = new window.Canvas2d.ImageAsset(grayCircle, 50, 50);
  172. img.posFromCenter = true;
  173. img.x = 100 * id;
  174. img.y = canvas.height / 2;
  175. canvas.add(img);
  176. var text = new window.Canvas2d.TextAsset(points[id], id * 100, canvas.height / 2, "15px Arial", "white");
  177. text.align = "center";
  178. text.baseline = "middle";
  179. canvas.add(text);
  180. }
  181. function extendBound(right) {
  182. if (right) {
  183. addToPoints(boundRight);
  184. boundRight++;
  185. }
  186. else {
  187. addToPoints(boundLeft);
  188. boundLeft--;
  189. }
  190. }
  191. canvas.context.translate(selected * 100, 0);
  192. canvas.canvas.onwheel = e => {
  193. e.preventDefault();
  194. if (e.deltaY > 0) {
  195. canvas.context.translate(100, 0);
  196. selected++;
  197. }
  198. else {
  199. canvas.context.translate(-100, 0);
  200. selected--;
  201. }
  202. while (boundLeft > selected - 5) {
  203. extendBound(false);
  204. }
  205. while (boundRight < selected + 5) {
  206. extendBound(true);
  207. }
  208. canvas.draw();
  209. };
  210. canvas.canvas.onwheel({preventDefault: () => {}, deltaY: -1});
  211. }
  212. */
  213. console.groupEnd();
  214. }
  215. window.MendoMkEnhancement = MendoMkEnhancement;
  216. MendoMkEnhancement();