JUST Kit

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

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

  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.15
  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. body>[wd-root]{overflow:unset;}
  65. .personalinfo>.list_nav_box>iframe:first-child{display:none;}
  66. /* .rememberdiv{display:none;} */
  67. `.replace(/;/g, "!important;");
  68.  
  69. // Auto login
  70. waitValue(() => document.querySelector(".login_btn")).then((el) => {
  71. // Remember forever
  72. // const loginInfo = localStorage
  73. // .getItem("autoLoginInfo")
  74. // .replace(/"expires":\d+/, '"expires":4796812800000');
  75. // localStorage.setItem("autoLoginInfo", loginInfo);
  76. el.click();
  77. });
  78.  
  79. // Fix P.E. page left frame
  80. waitValue(() => leftFrame.document.readyState === "complete").then(() => {
  81. leftFrame.document.querySelectorAll("[onclick]").forEach((el) => {
  82. const v = el.getAttribute("onclick").replace("href(", "href=(");
  83. el.setAttribute("onclick", v);
  84. });
  85. });
  86.  
  87. // Health clock in
  88. waitValue(() => input_zwtw).then(() => {
  89. addFloatButton("Clock in", () => {
  90. input_tw.value = input_zwtw.value = 36;
  91. post.click();
  92. });
  93. });
  94.  
  95. // Schedule dump
  96. waitValue(() => kbtable).then((el) => {
  97. addFloatButton("Dump schedule", () => {
  98. saveStr(
  99. `schedule_${zc.value}_${Date.now().toString(36).slice(1, -2)}.html`,
  100. `<!DOCTYPE html><meta name="viewport" content="width=device-width">` +
  101. el.outerHTML
  102. );
  103. });
  104. });
  105.  
  106. // Evaluation of teaching
  107. waitValue(() => location.pathname.endsWith("/xspj_edit.do")).then(() => {
  108. addFloatButton("Fill form", () => {
  109. for (const el of document.querySelectorAll("[type=radio]:first-child"))
  110. el.click();
  111. document.querySelector("[type=radio]:not(:first-child)").click();
  112. });
  113. });
  114.  
  115. // Fix `window.showModalDialog`
  116. (this.unsafeWindow || self).showModalDialog = async (url, args, opt = "") => {
  117. // Thanks for github.com/niutech/showModalDialog
  118. const dialog = document.body.appendChild(document.createElement("dialog"));
  119. dialog.style = `padding:0;${opt.replace(/dialog/gi, "")}`;
  120. const iframe = dialog.appendChild(document.createElement("iframe"));
  121. iframe.style = "width:100%;height:100%;border:0";
  122. iframe.src = url;
  123. dialog.showModal();
  124. await new Promise((r) => (iframe.onload = r));
  125. iframe.contentWindow.close = () => dialog.remove();
  126. iframe.contentWindow.dialogArguments = args;
  127. };
  128.  
  129. // Free WLAN?
  130. // (this.unsafeWindow || self).XMLHttpRequest = new Proxy(XMLHttpRequest, {
  131. // construct: (T, args) => {
  132. // const ret = new T(...args);
  133. // let inner = null;
  134. // Object.defineProperty(ret, "onreadystatechange", {
  135. // value(...args) {
  136. // if (ret.readyState == 4 &&ret.responseURL === "http://10.250.255.34/api/v1/login") {}
  137. // if (inner) inner(...args);
  138. // },
  139. // set: (n) => (inner = n),
  140. // });
  141. // return ret;
  142. // },
  143. // });
  144. // if (property == "responseText" && target.responseURL === "http://10.250.255.34/api/v1/login") {
  145. // const json = JSON.parse(target.responseText);
  146. // if (json?.data?.policy?.pagenumb === "mondaypage") {
  147. // json.data.policy.channels.push({ name: "XSWK", id: "1" });
  148. // target.responseText = JSON.stringify(json);
  149. // }
  150. // let b = target.responseText;
  151. // let a = `{"code":200,"message":"ok","data":{"reauth":true,"policy":{"pagenumb":"mondaypage","channels":[{"name":"中国移动","id":"2"},{"name":"中国电信","id":"3"},{"name":"中国联通","id":"4"}]}}}`;
  152. // }
  153.  
  154. /* ===== Notes ===== *
  155.  
  156. 个人主页:my.just.edu.cn
  157. VPN2反代:vpn2.just.edu.cn
  158. Bing through VPN2:client.v.just.edu.cn/https/webvpn75e21a7d71bfef5014373fde6b3dc8d6/
  159. 教务系统自动登录:jwgl.just.edu.cn:8080/sso.jsp
  160. 后勤:hqgy.just.edu.cn/sg/wechat/index.jsp
  161. 查寝分数:hqgy.just.edu.cn/sg/wechat/healthCheck.jsp
  162. 体育:tyxy.just.edu.cn
  163. 网课:teach.just.edu.cn
  164. 实验课成绩:202.195.195.198/sy/
  165. 退出登录:http://ids2.just.edu.cn/cas/logout
  166. 智慧树:http://portals.zhihuishu.com/just
  167. 超星:http://just.fanya.chaoxing.com/
  168.  
  169. 教务系统内网:
  170. http://202.195.206.36:8080/jsxsd
  171. http://202.195.206.37:8080/jsxsd
  172.  
  173. /* ================= */