Skip to content

Instantly share code, notes, and snippets.

@mvolfik
Created March 18, 2021 19:31
Show Gist options
  • Save mvolfik/af53d9f52825bf1c4911d8536980fb43 to your computer and use it in GitHub Desktop.
Save mvolfik/af53d9f52825bf1c4911d8536980fb43 to your computer and use it in GitHub Desktop.
Userscript to solve learingapps.org exercises
// ==UserScript==
// @name Learningapps.org solver
// @namespace https://mvolfik.github.io/
// @version 0.1
// @description Add button to autofill learningapps.org
// @author Matěj Volf
// @match https://learningapps.org/tools/*/watch?id=*
// @downloadUrl https://gist.github.com/mvolfik/af53d9f52825bf1c4911d8536980fb43/raw/liveworksheets.user.js
// @updateUrl https://gist.github.com/mvolfik/af53d9f52825bf1c4911d8536980fb43/raw/liveworksheets.user.js
// @grant none
// ==/UserScript==
/* globals $ */
(function() {
'use strict';
const runners = {
"text_gaps": () => {
const solution = {};
for (const item of window.MODEL) {
solution[item.index] = item.correctAnswer;
}
$(".gap-dropdown .gap").each((i, el) => {
const data = $(el).data();
if (data.value === solution[data.index]) {
el.click();
}
});
}
};
const supported_tools = [{tool: "140", version: "41", func: "text_gaps"}]
const tool = window.AppClientAppData.tool;
const version = window.AppClientAppData.version;
for (const t of supported_tools) {
if (tool === t.tool && version === t.version) {
const but = document.createElement("div");
but.style["margin-right"] = "0.2em";
but.classList.add("largeBlueButton");
but.innerHTML = "<i class='glyphicon glyphicon-pencil'></i>";
but.addEventListener("click", runners[t.func]);
document.getElementById("checksolutionBtnPanel").insertAdjacentElement("afterbegin", but);
return
}
}
alert("This tool isn't supported. Seems like you'll have to do some work today.");
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment