// ==UserScript==
// @name JUST EVO
// @description Patches & tools for JUST Website
// @namespace https://greasyfork.org/users/197529
// @version 0.1.2
// @author kkocdko
// @license Unlicense
// @match *://*.just.edu.cn/*
// @noframes
// @downloadURL none
// ==/UserScript==
"use strict";
const { addFloatButton, waitValue } = {
addFloatButton(text, onClick) /* 20200707-1237 */ {
if (!document.addFloatButton) {
const container = document.body
.appendChild(document.createElement("div"))
.attachShadow({ mode: "open" });
container.innerHTML =
"";
document.addFloatButton = (text, onClick) => {
const button = document.createElement("button");
button.textContent = text;
button.addEventListener("click", onClick);
return container.appendChild(button);
};
}
return document.addFloatButton(text, onClick);
},
waitValue(fn, interval = 200, timeout = 3000) /* 20210928-1143 */ {
return new Promise((resolve, reject) => {
const intervalHandle = setInterval(() => {
try {
const value = fn();
if (!value) return;
clearInterval(intervalHandle);
clearTimeout(timeoutHandle);
resolve(value);
} catch {}
}, interval);
const timeoutHandle = setTimeout(() => {
clearInterval(intervalHandle);
reject();
}, timeout);
});
},
};
// Auto login
waitValue(() => document.querySelector(".login_btn")).then((e) => e.click());
// Fix JUST P.E.
waitValue(() => leftFrame.document.readyState === "complete").then(() => {
leftFrame.document.querySelectorAll("[onclick]").forEach((el) => {
const v = el.getAttribute("onclick").replace("href(", "href=(");
el.setAttribute("onclick", v);
});
});