Last active
April 10, 2024 12:00
-
-
Save griffi-gh/904161e63f5b408f716b1483d53d8e77 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 naurok bypass | |
// @description get answers to naurok quizes | |
// @namespace Violentmonkey Scripts | |
// @match https://naurok.com.ua/test/*.html | |
// @exclude-match https://naurok.com.ua/test/*/* | |
// @inject-into page | |
// @grant none | |
// @version 1.2 | |
// @author griffi-gh | |
// @license MIT | |
// @description 17.02.2023, 02:41:50 | |
// @icon https://naurok.com.ua/favicon.ico | |
// ==/UserScript== | |
const NUM_REQUESTS = 5; | |
const stripTags = x => x.replace(/<\/?[^>]+(>|$)/g, ""); | |
(async () => { | |
//Parse things | |
const referrer = location.href.slice(0, -4) + '/match'; | |
const id = location.pathname.split('/').at(-1).split('-').at(-1).split('.')[0] | 0; | |
const answers = new Map(); | |
const answers_raw = new Map(); | |
for(let i = 0; i < NUM_REQUESTS; i++) { | |
//Do request | |
const res = await fetch(`https://naurok.com.ua/api/test/documents/${id}/match`, { | |
"credentials": "include", | |
"headers": { | |
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/110.0", | |
"Accept": "application/json, text/plain, */*", | |
"Accept-Language": "uk,ru-RU;q=0.8,ru;q=0.7,en-US;q=0.5,en;q=0.3,en-GB;q=0.2", | |
"Content-Type": "application/json;charset=utf-8", | |
"Sec-Fetch-Dest": "empty", | |
"Sec-Fetch-Mode": "cors", | |
"Sec-Fetch-Site": "same-origin" | |
}, | |
"referrer": referrer, | |
"body": "{\"uuid\":\"\"}", | |
"method": "POST", | |
"mode": "cors" | |
}).then(res => res.json()); | |
//Check response | |
if (!res?.result) { | |
console.error("Result error", res); | |
if (confirm("Не вдалося завантажити відповіді!\nМожливо ви не увійшли в На Урок, хочете зробити це зараз?")) { | |
location.href = "https://naurok.com.ua/login"; | |
} | |
return; | |
} | |
const items = res.items; | |
//Get answers | |
items.forEach(item => { | |
answers_raw.set(item.name, items.find(x => (x.id === item.id) && (x.name != item.name)).name); | |
answers.set(stripTags(item.name), stripTags(answers_raw.get(item.name))); | |
}); | |
} | |
console.log("Answer map:\n", answers, "\nRaw:\n", answers_raw); | |
//Put answers onto the page | |
Array.from(document.getElementsByClassName("question-view-item")).forEach(element => { | |
const questionText = element.querySelector(".question-view-item-content > p")?.textContent; | |
const answerText = questionText ? answers.get(questionText) : null; | |
if (answerText) { | |
//Add answer text | |
const answerElement = document.createElement("p"); | |
answerElement.textContent = `(Відповідь: ${answerText})`; | |
answerElement.style = "color: gray; font-size: .7em;"; | |
element.querySelector(".question-view-item-content").append(answerElement); | |
//Highlight option | |
let found = false; | |
Array.from(element.querySelectorAll(".text-only-option")).forEach(option => { | |
const tc = option.querySelector(".option-text p").textContent; | |
if ( | |
(tc == answerText) || | |
(tc == stripTags(answerText)) || | |
(stripTags(tc) == answerText) || | |
(stripTags(tc) == stripTags(answerText)) | |
) { | |
option.querySelector(".option-marker").style = "border: 5px solid darkgreen"; | |
found = true; | |
} | |
}); | |
//if not found make the answer bigger | |
if (!found) { | |
answerElement.style = "color: darkgreen; font-size: 1em; font-weight: bold;"; | |
} | |
} else { | |
const noAnswerElement = document.createElement("p"); | |
noAnswerElement.textContent = `(!) Немає відповіді`; | |
noAnswerElement.style = "color: darkred; font-size: .9em; font-weight: bold;"; | |
try { element.querySelector(".question-view-item-content").append(noAnswerElement); } catch(_) {} | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Alex11110
please use the new one at https://gist.github.com/griffi-gh/2cf11b9763b5158337d649d3b64ae154 instead.
this one's broken and there's no way to unpublish it without deleting.
(new one may broken too but idk, i havent touched it for a while; can be used as both userscript and bookmarklet if minimized and wrapped in a function call)