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 1
  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. /*
  63. * {
  64. color: white !important;
  65. background-color: #222 !important;
  66. }
  67. h1.pagetitle {
  68. border-bottom-color: rgb(60, 60, 60) !important;
  69. }
  70. a {
  71. color: darkred !important;
  72. }
  73. div.main-navigation *, div.main-navigation {
  74. background-color: #111 !important;
  75. }
  76. */
  77. `;
  78. document.head.appendChild(style);
  79. logFinish("dark mode");
  80. if (/^http(s)?:\/\/(www\.)?mendo\.mk\/Training\.do/.test(document.URL)) {
  81. logFinish("training site detected");
  82. document.querySelectorAll("div.main-content > div:nth-child(3) > div > table > tbody > tr > td:nth-child(2) > a").forEach(e => {
  83. e.target = "_blank";
  84. });
  85. logFinish("make task links open in another window");
  86. var search = document.createElement("form");
  87. search.className = "content-search";
  88. search.action = "#";
  89. search.innerHTML = `
  90. <input type=text id=search autocomplete=off>
  91. <input type=submit id=search-submit value=Search>
  92. `;
  93. search.onsubmit = e => {
  94. e.preventDefault();
  95. var kw = search.querySelector("#search").value.toLowerCase();
  96. document.querySelectorAll("body > div.page-container > div.main > div.main-content > div:nth-child(4) > div > table > tbody > tr").forEach(elm => {
  97. if (!elm.querySelector("td:nth-child(2) > a")) {
  98. return;
  99. }
  100. if (elm.innerText.toLowerCase().includes(kw) || elm.querySelector("td:nth-child(2) > a").href.toLowerCase().includes(kw)) {
  101. elm.style.display = "";
  102. }
  103. else {
  104. elm.style.display = "none";
  105. }
  106. });
  107. }
  108. document.querySelector(".main-content").prepend(search);
  109. logFinish("add task search bar");
  110. }
  111. if (document.querySelector("body > div.page-container > div.header > div.header-breadcrumbs > ul > li:last-child > a")) {
  112. window.name = document.querySelector("body > div.page-container > div.header > div.header-breadcrumbs > ul > li:last-child > a").innerText;
  113. }
  114. else if (document.querySelector(".pagetitle")) {
  115. window.name = document.querySelector(".pagetitle").innerText;
  116. }
  117. document.title = window.name + " – МЕНДО";
  118. logFinish("document title set");
  119. /*
  120. if (/^http(s)?:\/\/(www\.)?mendo\.mk\/Task\.do/.test(document.URL)) {
  121. await fetch("https://entityplantt.github.io/Canvas2d.js/Canvas2d.js").then(arg => arg.text()).then((1, eval));
  122. console.log(window.Canvas2d);
  123. async function nameOf(id) {
  124. var i = document.createElement("iframe");
  125. i.src = "https://mendo.mk/Task.do?id=" + id;
  126. i.style.display = "none";
  127. document.body.append(i);
  128. await new Promise(res => {
  129. i.onload = res;
  130. });
  131. if (!i.contentDocument.querySelector(".pagetitle")) {
  132. return null;
  133. }
  134. const r = i.contentDocument.querySelector(".pagetitle").innerText;
  135. i.remove();
  136. return r;
  137. }
  138. window.nameOf = nameOf;
  139. var canvas = new window.Canvas2d.Scene(), id = parseInt(document.URL.substr(28));
  140. canvas.background = "#111";
  141. 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());
  142. grayCircle = await createImageBitmap(grayCircle);
  143. document.querySelector(".main-content").prepend(canvas.canvas);
  144. canvas.width = 500;
  145. var points = new Array, boundLeft = id, boundRight = id, selected = id;
  146. async function addToPoints(id) {
  147. points[id] = await nameOf(id);
  148. var img = new window.Canvas2d.ImageAsset(grayCircle, 50, 50);
  149. img.posFromCenter = true;
  150. img.x = 100 * id;
  151. img.y = canvas.height / 2;
  152. canvas.add(img);
  153. var text = new window.Canvas2d.TextAsset(points[id], id * 100, canvas.height / 2, "15px Arial", "white");
  154. text.align = "center";
  155. text.baseline = "middle";
  156. canvas.add(text);
  157. }
  158. function extendBound(right) {
  159. if (right) {
  160. addToPoints(boundRight);
  161. boundRight++;
  162. }
  163. else {
  164. addToPoints(boundLeft);
  165. boundLeft--;
  166. }
  167. }
  168. canvas.context.translate(selected * 100, 0);
  169. canvas.canvas.onwheel = e => {
  170. e.preventDefault();
  171. if (e.deltaY > 0) {
  172. canvas.context.translate(100, 0);
  173. selected++;
  174. }
  175. else {
  176. canvas.context.translate(-100, 0);
  177. selected--;
  178. }
  179. while (boundLeft > selected - 5) {
  180. extendBound(false);
  181. }
  182. while (boundRight < selected + 5) {
  183. extendBound(true);
  184. }
  185. canvas.draw();
  186. };
  187. canvas.canvas.onwheel({preventDefault: () => {}, deltaY: -1});
  188. }
  189. */
  190. console.groupEnd();
  191. };
  192. window.MendoMkEnhancement = MendoMkEnhancement;
  193. MendoMkEnhancement();