Skip to content

Instantly share code, notes, and snippets.

@NuarkNoir
Last active April 23, 2019 05:52
Show Gist options
  • Save NuarkNoir/b7e01e9e1c176f0d3f8fc9cf826c06c3 to your computer and use it in GitHub Desktop.
Save NuarkNoir/b7e01e9e1c176f0d3f8fc9cf826c06c3 to your computer and use it in GitHub Desktop.
Reshuege autosolver - Automatically solves tests from reshguege
// ==UserScript==
// @name Reshuege autosolver
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Automatically solve tests from reshguege
// @author Nuark
// @match *://*.sdamgia.ru/test*
// @grant none
// @run-at document-end
// ==/UserScript==
(function() {
'use strict';
window.zxc = function(e, do_alert=true) {
let href = e.parentNode.querySelector(".prob_nums > a").href;
fetch(href).then(r => r.text()).then(text => {
let holder = document.createElement("div");
holder.innerHTML = text;
[...holder.querySelectorAll("script"), ...holder.querySelectorAll("link")].forEach(scr => scr.remove())
let solution = holder.querySelector(".solution");
let matches = solution.innerText.match(/Ответ: (.+)/gmi);
if (matches !== null) {
e.value = matches[0].replace(/Ответ: (.+)/mi, "$1");
if (e.value.endsWith(".")) {
e.value = e.value.slice(0, e.value.length-1);
}
if (e.value.indexOf("|") !== -1) {
e.value = e.value.split("|").pop();
}
}
else if (do_alert) {
let winop = window.open(href, "_blank");
winop.blur();
window.focus();
}
});
}
window.solveAll = function() {
document.querySelectorAll(".prob_list .test_inp").forEach(x => window.zxc(x, false));
}
let init = function() {
document.querySelectorAll(".prob_list .test_inp").forEach(x => {
x.ondblclick = function () {
window.zxc(this);
}
});
let input = document.createElement("input");
input.type = "button";
input.onclick = window.solveAll;
input.value = "Решить всё";
document.querySelector('div.content input[type="button"]').parentNode.append(input);
}
init();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment