Skip to content

Instantly share code, notes, and snippets.

@cborac
Last active May 21, 2021 06:15
Show Gist options
  • Save cborac/f850e51d31e890af5eba1aaef065155b to your computer and use it in GitHub Desktop.
Save cborac/f850e51d31e890af5eba1aaef065155b to your computer and use it in GitHub Desktop.
Are you bored from doing your LearningApps Homeworks? just use this script
(function () {
'use strict';
function randomInRange(min, max) {
return (Math.floor((Math.random() * (max - min) + 1) + min));
}
return function () {
const i = document.querySelectorAll("iframe");
console.log()
if (Array.from(i).map(x => {
if (x && x.src.startsWith("https://learningapps")) {
window.location.assign(x.src);
return true;
}
}).filter(x => !!x).length !== 0) return;
if (window.currentCrossword) {
for (const item of window.currentCrossword.items) {
for (let i = 0; i < item.word.length; i++) {
if (item.direction === "|") {
document.getElementById('grid_' + (item.x) + '_' + (item.y + i)).innerHTML = item.word[i]
} else {
document.getElementById('grid_' + (item.x + i) + '_' + (item.y)).innerHTML = item.word[i]
}
}
}
} else if (window.cardList) {
cardList.forEach(x => x.card.input[0].value = x.card.solution)
} else if (window.allCards) {
window.showAllCards();
setTimeout(() =>
window.allCards.forEach((x) => {
const cluster = x.cluster.htmlElement[0]
x.htmlElement[0].style.left = randomInRange(cluster.offsetLeft, cluster.offsetLeft + cluster.offsetWidth - 100) + "px";
x.htmlElement[0].style.top = randomInRange(cluster.offsetTop, cluster.offsetTop + cluster.offsetHeight - 100) + "px";
setTimeout(() => {
x.htmlElement[0].dispatchEvent(new Event('mousedown'));
setTimeout(() => x.htmlElement[0].dispatchEvent(new Event('mouseup')), 500)
}, 500)
}), 2500)
} else if (window.GameQuestions) {
setInterval(() => {
document.getElementById(window.correctAnswer).style.background = "#86da33"
}, 200)
} else if (window.MODEL) {
window.MODEL.forEach((x, i) => document.querySelector(`.input-field[data-model-index="${i}"]`).value = x.correctAnswer)
} else if (window.Pair1List) {
setTimeout(() => {
window.Pair1List.forEach((x, i) => {
x.card.htmlElement[0].style.top = x.card.matchingCards[0].htmlElement[0].style.top
x.card.htmlElement[0].style.left = x.card.matchingCards[0].htmlElement[0].style.left
})
alert("All the cards are matched with their corresponded answers. Just click over a card and it will match with it's response.")
}, 1500)
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment