Last active
May 5, 2020 18:59
-
-
Save KarolBarzowski/d609fd313ec0cf39839215af98920a0f to your computer and use it in GitHub Desktop.
Pomaga zdać egzamin ee.08
This file contains 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 Pomoc w egzaminie ee.08 | |
// @version 1.1.0 | |
// @description Jak użyć? - Klikasz Pomocy w prawym gornym rogu i czekasz. | |
// @author haker | |
// @match https://technikinformatyk.pl/kwalifikacja-ee-08-egzamin-online/* | |
// @match https://www.google.com/* | |
// @match https://www.e-nafarcie.pl/* | |
// @match http://egzamin-e13.blogspot.com/* | |
// @match http://egzamin-e12.blogspot.com/* | |
// @match http://egzamin-ee08.blogspot.com/* | |
// @match https://www.google.com/sorry/* | |
// @grant GM_setValue | |
// @grant GM_getValue | |
// @grant GM_deleteValue | |
// @grant GM_addValueChangeListener | |
// @grant GM_removeValueChangeListener | |
// @grant GM_openInTab | |
// @grant GM_addStyle | |
// @run-at document-end | |
// ==/UserScript== | |
const getAllAnswers = () => { | |
const questions = Array.from(document.querySelectorAll(".pytanie")); | |
const checked = []; | |
GM_addValueChangeListener("questionNumber", (name, old_value, new_value) => { | |
const check = setInterval(() => { | |
const isRunning = GM_getValue("isRunning", false); | |
checked.forEach((id) => { | |
if (new_value === id) { | |
clearInterval(check); | |
GM_removeValueChangeListener("questionNumber"); | |
return; | |
} | |
}); | |
if (new_value === 40) { | |
clearInterval(check); | |
checked.push(40); | |
GM_removeValueChangeListener("questionNumber"); | |
return; | |
} | |
if (!isRunning && old_value + 1 === new_value) { | |
clearInterval(check); | |
checked.push(new_value); | |
const text = questions[new_value] | |
.querySelector(".pytanietext") | |
.textContent.trim() | |
.replace(`Pytanie ${new_value + 1}. `, ""); | |
const url = encodeURIComponent(`${text} site:e-nafarcie.pl`); | |
const answers = Array.from( | |
questions[new_value].querySelectorAll(".odpcont") | |
); | |
let availableAnswers = []; | |
answers.forEach((ans) => { | |
availableAnswers.push(ans.textContent); | |
}); | |
GM_setValue("isRunning", true); | |
GM_setValue("availableAnswers", availableAnswers); | |
const tab = window.open(`https://www.google.com/search?q=${url}`); | |
GM_addValueChangeListener("answer", (name, old_value, new_value) => { | |
GM_setValue("isRunning", false); | |
const qNumber = GM_getValue("questionNumber", null); | |
answers.forEach((ans, i) => { | |
if ( | |
new_value.includes(ans.textContent) || | |
ans.textContent.includes(new_value) || | |
ans.textContent === new_value | |
) { | |
ans.querySelector("input").click(); | |
if (qNumber < 41) { | |
GM_setValue("questionNumber", parseFloat(qNumber) + 1); | |
} | |
GM_removeValueChangeListener("answer"); | |
return false; | |
} | |
}); | |
}); | |
} else if (old_value + 1 !== new_value) { | |
clearInterval(check); | |
GM_removeValueChangeListener("questionNumber"); | |
} | |
}, 500); | |
}); | |
GM_setValue("questionNumber", -1); | |
GM_setValue("questionNumber", 0); | |
GM_setValue("isRunning", false); | |
}; | |
const currentURL = window.location.href; | |
const isRunning = GM_getValue("isRunning", false); | |
if ( | |
currentURL.includes( | |
"https://technikinformatyk.pl/kwalifikacja-ee-08-egzamin-online/" | |
) | |
) { | |
GM_addStyle(` | |
._box { | |
position: fixed; | |
top: 15px; | |
right: 15px; | |
color: #000; | |
visiblity: visible; | |
} | |
._hidden { | |
visibility: hidden; | |
} | |
._helpBtn { | |
margin-left: 15px; | |
} | |
`); | |
const wrapper = document.querySelector(".tibg"); | |
const box = document.createElement('div'); | |
box.classList.add('_box'); | |
const helpBtn = document.createElement("button"); | |
helpBtn.textContent = "Pomocy"; | |
helpBtn.classList.add("_helpBtn"); | |
const hideBtn = document.createElement("button"); | |
hideBtn.textContent = "Ukryj na 30s"; | |
box.append(hideBtn); | |
box.append(helpBtn); | |
wrapper.append(box); | |
hideBtn.addEventListener('click', () => { | |
box.classList.add('_hidden'); | |
setTimeout(() => { | |
box.classList.remove('_hidden'); | |
}, 30000) | |
}) | |
helpBtn.addEventListener("click", getAllAnswers); | |
} else if ( | |
currentURL.includes("https://www.google.com/search?q=") && | |
isRunning | |
) { | |
if (document.querySelectorAll(".g").length) { | |
const results = Array.from(document.querySelectorAll(".g")); | |
const [bestResult] = results; | |
const link = bestResult.querySelector("a"); | |
link.click(); | |
} else { | |
const qNumber = GM_getValue("questionNumber", "nieznany"); | |
document.title = `Pytanie ${qNumber + 1} - BRAK`; | |
if (qNumber < 41) { | |
GM_setValue("questionNumber", parseFloat(qNumber) + 1); | |
} | |
GM_setValue("isRunning", false); | |
} | |
} else if (currentURL.includes("https://www.e-nafarcie.pl") && isRunning) { | |
if (document.querySelector("#Answers")) { | |
const answers = Array.from(document.querySelector("#Answers").children); | |
answers.forEach((answer) => { | |
const bgColor = getComputedStyle(answer).backgroundColor; | |
if (bgColor === "rgb(100, 255, 100)") { | |
const answersData = GM_getValue("availableAnswers", null); | |
const qNumber = GM_getValue("questionNumber", "nieznany"); | |
answersData.forEach((ans, i) => { | |
if ( | |
answer.textContent.includes(ans) || | |
ans.includes(answer.textContent) || | |
ans === answer.textContent | |
) { | |
GM_setValue("answer", answer.textContent); | |
window.close(); | |
return false; | |
} else if (i === answers.length - 1) { | |
document.title = `Pytanie ${qNumber + 1} - BRAK`; | |
if (qNumber < 41) { | |
GM_setValue("questionNumber", parseFloat(qNumber) + 1); | |
} | |
GM_setValue("isRunning", false); | |
} | |
}); | |
} | |
}); | |
} else { | |
const qNumber = GM_getValue("questionNumber", "nieznany"); | |
document.title = `Pytanie ${qNumber + 1} - BRAK`; | |
if (qNumber < 41) { | |
GM_setValue("questionNumber", parseFloat(qNumber) + 1); | |
} | |
GM_setValue("isRunning", false); | |
} | |
} else if ( | |
(currentURL.includes("http://egzamin-e13.blogspot.com/") || | |
currentURL.includes("http://egzamin-e12.blogspot.com/")) && | |
isRunning | |
) { | |
const wrapper = document.querySelector(".post-body"); | |
const answers = Array.from(wrapper.querySelector("ol").children); | |
const ans = wrapper.querySelector("b").textContent; | |
let result; | |
switch (ans) { | |
case "A": | |
result = answers[0].textContent; | |
break; | |
case "B": | |
result = answers[1].textContent; | |
break; | |
case "C": | |
result = answers[2].textContent; | |
break; | |
case "D": | |
result = answers[3].textContent; | |
break; | |
default: | |
break; | |
} | |
GM_setValue("answer", result); | |
const answersData = GM_getValue("availableAnswers", null); | |
const qNumber = GM_getValue("questionNumber", "nieznany"); | |
answersData.forEach((ans, i) => { | |
if (result.includes(ans) || ans.includes(result)) { | |
GM_setValue("answer", result); | |
window.close(); | |
return false; | |
} else if (i === answers.length - 1) { | |
document.title = `Pytanie ${qNumber + 1} - BRAK`; | |
if (qNumber < 41) { | |
GM_setValue("questionNumber", parseFloat(qNumber) + 1); | |
} | |
GM_setValue("isRunning", false); | |
} | |
}); | |
} else if (currentURL.includes("https://www.google.com/sorry")) { | |
GM_setValue("isRunning", true); | |
const heading = document.createElement("h1"); | |
heading.textContent = "Wypelnij captache i jedziemy dalej"; | |
document.body.prepend(heading); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment