Skip to content

Instantly share code, notes, and snippets.

@mvolfik
Last active October 11, 2023 14:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mvolfik/5d663fd304c38a872813e0576a58573a to your computer and use it in GitHub Desktop.
Save mvolfik/5d663fd304c38a872813e0576a58573a to your computer and use it in GitHub Desktop.
Userscript to solve liveworksheets.com exercises
// ==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);
})();
@NexisCODES
Copy link

pls fix for new versio

@mvolfik
Copy link
Author

mvolfik commented Oct 11, 2023

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