Last active
October 11, 2023 14:13
-
-
Save mvolfik/5d663fd304c38a872813e0576a58573a to your computer and use it in GitHub Desktop.
Userscript to solve liveworksheets.com exercises
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Liveworksheets.com solver | |
// @namespace https://mvolfik.github.io/ | |
// @version 0.2 | |
// @description Add button to autofill liveworksheets.com | |
// @author Matěj Volf | |
// @match https://www.liveworksheets.com/* | |
// @downloadUrl https://gist.github.com/mvolfik/5d663fd304c38a872813e0576a58573a/raw/liveworksheets.user.js | |
// @updateUrl https://gist.github.com/mvolfik/5d663fd304c38a872813e0576a58573a/raw/liveworksheets.user.js | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
const but = document.createElement("button"); | |
but.style.position = "absolute"; | |
but.style.top = "0"; | |
but.style.left = "0"; | |
but.style["z-index"] = "999"; | |
but.innerText = "Fill correct values"; | |
function fillItem(i, value) { | |
const is = i.toString(); | |
const textbox = document.getElementById("textbox" + is); | |
if (textbox !== null) { | |
textbox.innerText = value; | |
return true | |
} | |
const select = document.getElementById("selectablediv" + is); | |
if (select !== null) { | |
if (select.classList.contains("selectedselectablediv") !== (value === "select:yes")) { | |
console.log(`selectanswer({is})`); | |
window.selectanswer(i); | |
} | |
return true | |
} | |
} | |
function clickHandler() { | |
but.remove(); | |
const data = JSON.parse(window.contenidojson); | |
const failed = []; | |
data.forEach(function(values, i){ | |
const is = i.toString(); | |
try { | |
if (fillItem(i, values[0])) { | |
return | |
} | |
} catch (e) {} | |
failed.push(is); | |
}); | |
const sub = document.getElementById("capafinish"); | |
sub.scrollIntoView({block: "center"}); | |
if (failed.length > 0) { | |
alert("Failed to autofill these items: " + failed.join(", ")); | |
} | |
} | |
but.addEventListener("click", clickHandler); | |
document.getElementById("capa1").insertAdjacentElement("afterbegin", but); | |
})(); |
Hey, I don't have any use for this anymore, so I probably won't spend my time to update this. Nonetheless, you are more that welcome to adapt the code and publish your own, updated version.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
pls fix for new versio