Skip to content

Instantly share code, notes, and snippets.

@raitonoberu
Last active December 3, 2022 19:37
Show Gist options
  • Save raitonoberu/381f7e6eaa89c6f320880c2341f13f9c to your computer and use it in GitHub Desktop.
Save raitonoberu/381f7e6eaa89c6f320880c2341f13f9c to your computer and use it in GitHub Desktop.
exam1 english helper | tampermonkey
// ==UserScript==
// @name EXAM1 ENGLISH HELPER
// @namespace https://github.com/raitonoberu/
// @version 0.1
// @description Помогает с копированием тестов
// @author raitonoberu
// @encoding utf-8
// @homepage https://github.com/raitonoberu/
// @match https://exam1.urfu.ru/mod/quiz/review.php?*
// @grant none
// @require https://cdnjs.cloudflare.com/ajax/libs/cash/8.1.2/cash.min.js
// @updateURL https://gist.github.com/raitonoberu/381f7e6eaa89c6f320880c2341f13f9c/raw/002cacd5253e842344ae1da183e97fd94817e12d/exam1.user.js
// @downloadURL https://gist.github.com/raitonoberu/381f7e6eaa89c6f320880c2341f13f9c/raw/002cacd5253e842344ae1da183e97fd94817e12d/exam1.user.js
// ==/UserScript==
(function () {
"use strict";
// выбор слов
$(".select.custom-select.incorrect, .form-control.mb-1.incorrect").each(
function (i, e) {
let text = $(e).next().next().contents()[2];
if (text === undefined) return;
text = text.data.split(": ").splice(1).join(": ");
$(e).children().first().text(text);
$(e).removeAttr("disabled");
$(e).attr("value", text);
$(e).parent().get()[0].addEventListener("click", paste(text));
}
);
// пропуски в тексте
$(
".que.gapselect.deferredfeedback.notanswered," +
".que.ddwtos.deferredfeedback.notanswered"
).each(function (i, e) {
let answer = $(e).find("div.rightanswer").text();
if (answer === "") return;
let questions = [];
let fields = [];
$(e)
.find("div.qtext")
.children()
.each(function (i, e) {
let contents = $(e).contents();
contents.each(function (i, e) {
if (e.localName === "span" && i != 0 && contents[i - 1].data != "") {
questions.push(contents[i - 1].data);
fields.push(e);
}
});
});
if (questions.length === 0) return;
questions.forEach(function (q, i) {
q = escape(q);
let re = new RegExp(q + "\\[([^\\]]*)\\]");
let match = answer.match(re);
if (!match) {
// для строк с несколькими пропусками
re = new RegExp(q.substring(1) + "\\[([^\\]]*)\\]");
match = answer.match(re);
if (!match) return;
}
$(fields[i]).find("option").first().text(match[1]);
if ($(fields[i]).hasClass("drop")) $(fields[i]).text(match[1]);
$(fields[i]).find("select").removeAttr("disabled");
// $(fields[i]).get()[0].addEventListener("click", paste(match[1]));
});
});
// матчи
$(".que.match.deferredfeedback.notanswered").each(function (i, e) {
let answer = $(e).find("div.rightanswer").text();
if (answer === "") return;
let questions = [];
let fields = [];
$(e)
.find("tbody")
.children()
.each(function (i, e) {
let text = $(e).find("p").text();
let field = $(e).find("select").get();
if (!text || !field) return;
questions.push(text);
fields.push(field);
});
if (questions.length === 0) return;
questions.forEach(function (q, i) {
let re = new RegExp(escape(q) + " → ([^,$]*)");
let match = answer.match(re);
if (!match) {
return;
}
$(fields[i]).find("option").first().text(match[1]);
$(fields[i]).removeAttr("disabled");
// $(fields[i]).get()[0].addEventListener("click", paste(match[1]));
});
});
})();
function escape(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
function paste(text) {
return function () {
navigator.clipboard.writeText(text);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment