Skip to content

Instantly share code, notes, and snippets.

@elteammate
Last active November 4, 2022 15:09
Show Gist options
  • Save elteammate/0978978892701ef4ce67167dfd4e2f7c to your computer and use it in GitHub Desktop.
Save elteammate/0978978892701ef4ce67167dfd4e2f7c to your computer and use it in GitHub Desktop.
TestSys helper
// ==UserScript==
// @name TestSys helper
// @namespace http://tampermonkey.net/
// @version 0.1
// @description cringe
// @author elteammate
// @match https://acm.math.spbu.ru/tsweb/submit*
// @grant none
// ==/UserScript==
(function() {
if (document.querySelector("h1").innerText === "Submit Status") {
window.location = "https://acm.math.spbu.ru/tsweb/submit";
}
var cssPatch = document.createElement("style");
document.head.appendChild(cssPatch);
var container = document.createElement("section");
container.style.display = "flex";
var newBody = document.createElement("div");
newBody.style.flexGrow = "1";
[...document.body.children].forEach(child => {
newBody.appendChild(child);
});
container.appendChild(newBody);
document.body.innerHTML = "";
document.body.appendChild(container);
var rightBox = document.createElement("div");
container.appendChild(rightBox);
rightBox.style.display = "flex";
rightBox.style.flexDirection = "column";
var submFrame = document.createElement("div");
submFrame.style.margin = "12px";
rightBox.appendChild(submFrame);
var contestsFrame = document.createElement("div");
contestsFrame.style.margin = "12px";
rightBox.appendChild(contestsFrame);
var clarFrame = document.createElement("section");
clarFrame.style.margin = "12px";
document.body.appendChild(clarFrame);
var monFrame = document.createElement("section");
monFrame.style.margin = "12px";
monFrame.style.width = "100%";
document.body.appendChild(monFrame);
function switchShowMode() {
var root = document.querySelector(":root");
if (getComputedStyle(root).getPropertyValue('--shouldShowAll') == "none") {
root.style.setProperty("--shouldShowAll", "table-row");
} else {
root.style.setProperty("--shouldShowAll", "none");
}
}
switchShowMode();
function reload() {
fetch("https://acm.math.spbu.ru/tsweb/allsubmits").then(e => e.arrayBuffer()).then(e => {
var decoder = new TextDecoder('koi8-r');
e = decoder.decode(e);
var frame = document.createElement("section");
frame.innerHTML = e;
var table = frame.querySelector(":scope > table");
var button = document.createElement("button");
button.innerText = "Show all/less";
button.onclick = () => switchShowMode();
table.firstChild.firstChild.firstChild.replaceChildren(button);
[...table.querySelectorAll("tr")].forEach((e, i) => {
if (i > 20) {
e.style.display = "var(--shouldShowAll)";
}
})
table.id = "subm";
submFrame.replaceChildren(table);
fetch("https://acm.math.spbu.ru/tsweb/monitor").then(e => e.arrayBuffer()).then(e => {
var decoder = new TextDecoder('koi8-r');
e = decoder.decode(e);
var frame = document.createElement("section");
frame.innerHTML = e;
var table = frame.querySelector(".mtab");
monFrame.replaceChildren(table);
});
});
}
fetch("https://acm.math.spbu.ru/tsweb/contests?mask=1").then(e => e.arrayBuffer()).then(e => {
var decoder = new TextDecoder('koi8-r');
e = decoder.decode(e);
var frame = document.createElement("section");
frame.innerHTML = e;
var table = frame.querySelector(":scope > table");
contestsFrame.replaceChildren(table);
[...table.querySelectorAll("tr")].forEach((e, i) => {
if (i > 10) {
e.style.display = "var(--shouldShowAll)";
}
[...e.querySelectorAll("td, th")].forEach((e, i) => {
if (i >= 2) {
e.style.display = "var(--shouldShowAll)";
}
});
})
});
fetch("https://acm.math.spbu.ru/tsweb/clars").then(e => e.arrayBuffer()).then(e => {
var decoder = new TextDecoder('koi8-r');
e = decoder.decode(e);
var frame = document.createElement("section");
frame.innerHTML = e;
var table = frame.querySelector("table");
clarFrame.replaceChildren(table);
});
document.addEventListener("keypress", e => {
if (e.code == "KeyR") {
reload();
}
});
setInterval(() => {
if ([...document.querySelectorAll("table .fno")].length != 0) {
reload();
console.log("Reloading...");
}
}, 300);
reload();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment