JUST Kit

用于江苏科技大学网站的补丁与工具。

目前为 2022-01-07 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name JUST Kit
  3. // @description Patches & tools for JUST Website.
  4. // @description:zh-CN 用于江苏科技大学网站的补丁与工具。
  5. // @namespace https://greasyfork.org/users/197529
  6. // @version 0.1.19
  7. // @author kkocdko
  8. // @license Unlicense
  9. // @match *://*.just.edu.cn/*
  10. // @match *://*.just.edu.cn:8080/*
  11. // @match *://*.just.edu.cn:80/*
  12. // @match *://10.250.255.34/*
  13. // @match *://10.250.255.34/authentication/*
  14. // @match *://202.195.195.198/*
  15. // @match *://202.195.206.36:8080/*
  16. // @match *://202.195.206.37:8080/*
  17. // ==/UserScript==
  18. "use strict";
  19.  
  20. const { addFloatButton, waitValue, saveStr } = {
  21. addFloatButton(text, onClick) /* 20200707-1237 */ {
  22. if (!document.addFloatButton) {
  23. const container = document.body
  24. .appendChild(document.createElement("div"))
  25. .attachShadow({ mode: "open" });
  26. container.innerHTML =
  27. "<style>:host{position:fixed;top:3px;left:3px;z-index:2147483647;height:0}#i{display:none}*{float:left;margin:4px;padding:1em;outline:0;border:0;border-radius:5px;background:#1e88e5;box-shadow:0 1px 4px rgba(0,0,0,.1);color:#fff;font-size:14px;line-height:0;transition:.3s}:active{background:#42a5f5;box-shadow:0 2px 5px rgba(0,0,0,.2)}button:active{transition:0s}:checked~button{visibility:hidden;opacity:0;transform:translateY(-3em)}label{border-radius:50%}:checked~label{opacity:.3;transform:translateY(3em)}</style><input id=i type=checkbox><label for=i></label>";
  28. document.addFloatButton = (text, onClick) => {
  29. const button = document.createElement("button");
  30. button.textContent = text;
  31. button.addEventListener("click", onClick);
  32. return container.appendChild(button);
  33. };
  34. }
  35. return document.addFloatButton(text, onClick);
  36. },
  37. waitValue(fn, interval = 200, timeout = 3000) /* 20220104-1405 */ {
  38. return new Promise((resolve, reject) => {
  39. const intervalHandle = setInterval(() => {
  40. try {
  41. const value = fn();
  42. if (!value) return;
  43. clearInterval(intervalHandle);
  44. clearTimeout(timeoutHandle);
  45. resolve(value);
  46. } catch {}
  47. }, interval);
  48. const timeoutHandle = setTimeout(() => {
  49. clearInterval(intervalHandle);
  50. reject("waitValue: timeout");
  51. }, timeout);
  52. });
  53. },
  54. saveStr(name, str) /* 20211203-1130 */ {
  55. const el = document.createElement("a");
  56. el.download = name;
  57. el.href = URL.createObjectURL(new Blob([str]));
  58. el.click();
  59. },
  60. };
  61.  
  62. // Styles
  63. document.lastChild.appendChild(document.createElement("style")).textContent = `
  64. .personalinfo>.list_nav_box>iframe:first-child,browserPrompt{display:none;}
  65. .button{background:#07e;}
  66. `.replace(/;/g, "!important;");
  67.  
  68. // Force page to scroll on x axis
  69. waitValue(() => document.readyState !== "loading").then(() => {
  70. if (document.documentElement.offsetWidth >= 1280) return;
  71. addFloatButton("Scroll X Axis", () => {
  72. let v = document.documentElement.getAttribute("style") ?? "";
  73. v += `width:1280px!important;min-width:1280px!important;overflow-x:scroll!important`;
  74. document.documentElement.setAttribute("style", v);
  75. });
  76. });
  77.  
  78. // Auto login
  79. waitValue(() => document.querySelector(".login_btn")).then((el) => el.click());
  80.  
  81. // Fix P.E. page left frame
  82. waitValue(() => leftFrame.document.readyState === "complete").then(() => {
  83. leftFrame.document.querySelectorAll("[onclick]").forEach((el) => {
  84. const v = el.getAttribute("onclick").replace("href(", "href=(");
  85. el.setAttribute("onclick", v);
  86. });
  87. });
  88.  
  89. // Health clock in
  90. waitValue(() => input_zwtw).then(() => {
  91. addFloatButton("Clock in", () => {
  92. input_tw.value = input_zwtw.value = 36;
  93. post.click();
  94. });
  95. });
  96.  
  97. // Schedule dump
  98. waitValue(() => kbtable).then((el) => {
  99. addFloatButton("Dump schedule", () => {
  100. saveStr(
  101. `schedule_${zc.value}_${Date.now().toString(36).slice(0, -2)}.html`,
  102. `<!DOCTYPE html><meta name="viewport" content="width=device-width">` +
  103. el.outerHTML
  104. );
  105. });
  106. });
  107.  
  108. // Evaluation of teaching
  109. waitValue(() => location.pathname.endsWith("/xspj_edit.do")).then(() => {
  110. addFloatButton("Fill form", () => {
  111. for (const el of document.querySelectorAll("[type=radio]:first-child"))
  112. el.click();
  113. document.querySelector("[type=radio]:not(:first-child)").click();
  114. });
  115. });
  116.  
  117. // Fix `window.showModalDialog`
  118. (this.unsafeWindow || self).showModalDialog = async (url, args, opt = "") => {
  119. // Thanks for github.com/niutech/showModalDialog
  120. const dialog = document.body.appendChild(document.createElement("dialog"));
  121. dialog.style = `padding:0;${opt.replace(/dialog/gi, "")}`;
  122. const iframe = dialog.appendChild(document.createElement("iframe"));
  123. iframe.style = "width:100%;height:100%;border:0";
  124. iframe.src = url;
  125. dialog.showModal();
  126. await new Promise((r) => (iframe.onload = r));
  127. iframe.contentWindow.close = () => dialog.remove();
  128. iframe.contentWindow.dialogArguments = args;
  129. };
  130.  
  131. // Free WLAN?
  132. // (this.unsafeWindow || self).XMLHttpRequest = new Proxy(XMLHttpRequest, {
  133. // construct: (T, args) => {
  134. // const ret = new T(...args);
  135. // let inner = null;
  136. // Object.defineProperty(ret, "onreadystatechange", {
  137. // value(...args) {
  138. // if (ret.readyState == 4 &&ret.responseURL === "http://10.250.255.34/api/v1/login") {}
  139. // if (inner) inner(...args);
  140. // },
  141. // set: (n) => (inner = n),
  142. // });
  143. // return ret;
  144. // },
  145. // });
  146. // if (property == "responseText" && target.responseURL === "http://10.250.255.34/api/v1/login") {
  147. // const json = JSON.parse(target.responseText);
  148. // if (json?.data?.policy?.pagenumb === "mondaypage") {
  149. // json.data.policy.channels.push({ name: "XSWK", id: "1" });
  150. // target.responseText = JSON.stringify(json);
  151. // }
  152. // let b = target.responseText;
  153. // let a = `{"code":200,"message":"ok","data":{"reauth":true,"policy":{"pagenumb":"mondaypage","channels":[{"name":"中国移动","id":"2"},{"name":"中国电信","id":"3"},{"name":"中国联通","id":"4"}]}}}`;
  154. // }
  155.  
  156. /* ===== Notes ===== *
  157.  
  158. 个人主页:my.just.edu.cn
  159. VPN2反代:vpn2.just.edu.cn
  160. Bing via VPN2:client.v.just.edu.cn/https/webvpn75e21a7d71bfef5014373fde6b3dc8d6/
  161. 教务系统自动登录:jwgl.just.edu.cn:8080/sso.jsp
  162. 后勤:hqgy.just.edu.cn/sg/wechat/index.jsp
  163. 查寝分数:hqgy.just.edu.cn/sg/wechat/healthCheck.jsp
  164. 体育:tyxy.just.edu.cn
  165. 网课:teach.just.edu.cn
  166. 实验课成绩:202.195.195.198/sy/
  167. 退出登录:ids2.just.edu.cn/cas/logout
  168. 智慧树:http://portals.zhihuishu.com/just
  169. 超星:http://just.fanya.chaoxing.com/
  170.  
  171. 教务系统内网:
  172. http://202.195.206.36:8080/jsxsd
  173. http://202.195.206.37:8080/jsxsd
  174.  
  175. https://client.v.just.edu.cn/enlink/#/client/app
  176.  
  177. /* ================= */