Userscript to solve liveworksheets.com exercises
This file contains 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); | |
})(); |
@grcie this is a userscript, which you can install using a userscript manager (a browser extension), for example Tampermonkey. If that's not your question, I cannot provide any support beyond that - I made this a while ago and don't use it anymore. It worked for me at the time, so I just pasted it online, but that's it.
This is open source software, hereby declared to be under the MIT license. Please note the THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND [...]
part.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what do i do to make it work