NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @license MIT // @name Reshu-ege extension // @namespace http://tampermonkey.net/ // @version 0.7.8 // @description Adds useful stuff to the site // @author You // @include https://*ege.sdamgia.ru/test?id=* // @include https://*vpr.sdamgia.ru/test?id=* // @grant none // ==/UserScript== //(function() { var timer; window.fieldsNodes = []; var areHiddenFields = true; //CreatedByDeuS7 // Служебные функции function getRandomArbitrary(min, max) { return Math.round(Math.random() * (max - min) + min); } /*function toggleAnswers(status) { var ans = document.getElementsByClassName("answerButton"); var controlButton = document.getElementById("showAnswersButton"); if (status == false) { for (var i = 0;i<ans.length;i++) { ans[i].style.display = "inline-block"; } controlButton.classList.add("activeControlButton"); } else { for (var i = 0;i<ans.length;i++) { ans[i].style.display = "none"; } controlButton.classList.remove("activeControlButton"); } return !status; }*/ function isNumber(n) { return !isNaN(parseFloat(n)) && isFinite(n); } function sanitizeAnswers(str) { if (str.indexOf("|") != -1) { return str.split("|")[0]; } return str.trim(); } function refreshBar() { var bar = document.getElementById("progressBar"); var fields = document.querySelectorAll("input[name^='answer']"); var completedTasks = 0; for (var i = 0;i<fields.length;i++) { if (fields[i].value != "") completedTasks++; } bar.style.width = completedTasks/fields.length*100 + "%"; } function evaluatorFunc(node) { node.value = evaluate(node.value); } function replaceComas(elem) { elem.value = elem.value.replace(/\./ig, ","); } function evaluate(str) { str = str.replace(/\,/ig, "."); try { return eval(str).toString().replace(/\./ig, ",") || str.replace(/\./ig, ","); } catch(e) { return str.replace(/\./ig, ","); } } //Функции контроля function toggleTimer(status) { if (status == true) { ticker = window.setInterval(tick,1000); document.getElementById("stopTimeButton").classList.remove("activeControlButton"); } else { clearInterval(ticker); document.getElementById("stopTimeButton").classList.add("activeControlButton"); } return !status; } function createTheAnswers() { var adress = "https://" + window.location.hostname + "/problem?id="; var fields = document.querySelectorAll("input[name^='answer']"); for (var i = 0;i<fields.length;i++) { var a = document.createElement("a"); a.className = "answerButton"; a.innerHTML = "Show the Answer"; a.href = adress + fields[i].getAttribute("name").split("_").pop().replace(/[^0-9]/gi, ""); a.target = "_blank"; fields[i].parentNode.insertBefore(a, fields[i].nextSibling); } } function submit_form(){ if (sent != 0){ return; } sent = 1; var f = $('<form method="post" action="/test" style="display:none"></form>'); $('.test_inp').clone().appendTo(f); $('body').append(f); f[0].submit(); } function createProgressBar() { document.body.innerHTML += '<div id="progressBar"></div>'; var fields = document.querySelectorAll("input[name^='answer']"); for (var i = 0;i<fields.length;i++) { fields[i].addEventListener('blur', function() { refreshBar(); }); } } function goToTop() { var tasks = document.getElementsByClassName("prob_num"); $('html, body').animate({ scrollTop: $(tasks[0]).offset().top }, 800); } function goToBottom() { var tasks = document.getElementsByClassName("prob_num"); $('html, body').animate({ scrollTop: $(tasks[tasks.length - 1]).offset().top }, 800); } function toggleAutoSender(status) { var senderButton = document.getElementById("setAutoSending"); if (status) { clearTimeout(timer); } else { var time = getRandomArbitrary(1500, 2400); console.log(time); timer = setTimeout(function() { submit_form(); }, time*1000); } senderButton.classList.toggle("activeControlButton"); return !status; } function toggleEvaluator(status) { var fields = document.querySelectorAll("input[name^='answer']"); if (status) { for (let i = 0;i<fields.length;i++) { fields[i].onblur = null; } document.getElementById("evaluateOn").classList.remove("activeControlButton"); } else { for (let i = 0;i<fields.length;i++) { fields[i].onblur = function() { fields[i].value = evaluate(fields[i].value); } } document.getElementById("evaluateOn").classList.add("activeControlButton"); } return !status; } //Инициализация классов и контроллирующих элементов function createStyles() { var style = document.createElement('style'); style.type = 'text/css'; style.innerHTML += '.answerButton { padding: 7px 23px; border: 4px solid #4060ED; display: inline-block; font-size: 13px; border-radius: 7px; font-weight: bold; cursor: pointer; transition: .3s; color: #4060ED; transition: .3s; margin-left: 15px; display: none; vertical-align: bottom; text-decoration: none; } \n'; style.innerHTML += '.answerButton:hover { background: #4060ED; color: white; }'; style.innerHTML += '.activeControlButton { background: #4060ED; color: white !important; }'; style.innerHTML += '.controlPanel{ width: 60px; position: fixed; border: 3px solid #4060ED; top: 50%; transform: translateY(-50%); left: 0; z-index: 999999;} \n'; style.innerHTML += '.controlButton{ height: 60px; line-height: 60px; font-size: 35px; color: #4060ED; text-align: center; transition: .3s; cursor: pointer; margin: 0; user-select: none;} \n'; style.innerHTML += '.controlButton:hover { color: white; background: #4060ED; } \n'; style.innerHTML += '.controlButtonInactive { cursor: no-drop; opacity: .5;} \n'; style.innerHTML += '#progressBar { height: 5px; position: fixed; top: 0; left: 0; background: #4060ED; transition: .3s; width: 0; margin: 0; z-index: 999999; } \n'; style.innerHTML += '@keyframes bounceAnim { 0% { background: #4060ED; color: white; } 50% { transform: scale(1.4);} } \n'; style.innerHTML += '.animatedControlButton { animation-name: bounceAnim; animation-duration: .5s; animation-iteration-count: 2; } \n'; style.innerHTML += '.alertState { box-shadow: 0 0 20px 4px red !important; } \n'; style.innerHTML += '.undefinedState { box-shadow: 0 0 20px 4px grey !important; } \n'; style.innerHTML += '.correctState { box-shadow: 0 0 20px 4px #21ff00 !important; } \n'; document.getElementsByTagName('head')[0].appendChild(style); } function createButtons() { var buttons = [ {id : "toUpArrow", title: "Пролистать к верху работы.", content : "▲" }, {id : "evaluateOn", title: "Включить автоматическое вычисление выражений", content : "∑" }, //{id : "showAnswersButton", title: "Показать кнопки ответов", content : "Æ" }, {id : "showAllAnswers", title: "Показать ответы. (Нужно отрпавить работу, учителю она не придет).", content : "⚠" }, {id : "setAutoSending", title: "Настроить автоматическую отправку работы", content : "TS" }, {id : "stopTimeButton", title: "Останавливает таймер, предотвращая преждевременную отправку работ.", content : "🕐" }, {id : "sendWorkButton", title: "Отправить работу.", content : "✉" }, {id : "toBottomArrow", title: "Пролистать к низу работы.", content : "▼" } ]; var delay = 10; var delayDiff = 0.1; var panel = document.createElement("div"); panel.className += "controlPanel"; for (var i = 0;i<buttons.length;i++) { var button = document.createElement("div"); button.className = "controlButton"; button.className += " animatedControlButton"; button.style.animationDelay = delay + "s"; button.style.position = "relative"; button.id = buttons[i].id; button.title = buttons[i].title; button.innerHTML += buttons[i].content; panel.appendChild(button); delay += delayDiff; } document.body.appendChild(panel); } function fixFields() { var fields = document.querySelectorAll("input[name^='answer']"); for (let i = 0;i<fields.length;i++) { fields[i].onchange = replaceComas.bind(null, fields[i]); } } //Главный инициализирующий элемент (function() { // var areAnswersShown = false; var isTimerStopped = false; //var areFieldsFilled = false; var isWorkChecked = false; var isEvaluatorTurnedOn = false; var isAutoSenderOn = false; createStyles(); createButtons(); createTheAnswers(); createProgressBar(); fixFields(); initHiddenFields(); document.getElementById("stopTimeButton").onclick = function() { isTimerStopped = toggleTimer(isTimerStopped); } document.getElementById("sendWorkButton").onclick = function() { submit_form(); } document.getElementById("showAllAnswers").onclick = function() { toggleHiddenFields(); } document.getElementById("toUpArrow").onclick = function() { goToTop(); } document.getElementById("toBottomArrow").onclick = function() { goToBottom(); } document.getElementById("evaluateOn").onclick = function() { isEvaluatorTurnedOn = toggleEvaluator(isEvaluatorTurnedOn); } document.getElementById("setAutoSending").onclick = function() { isAutoSenderOn = toggleAutoSender(isAutoSenderOn); } })(); function initHiddenFields() { try { var nosols = document.querySelector("input[name='nosols']").cloneNode(); } catch(e) { var nosols = document.createElement("div"); nosols.id = 'dummy'; } var stat_id = document.querySelector("input[name='stat_id']").cloneNode(); var test_id = document.querySelector("input[name='test_id']").cloneNode(); fieldsNodes.push(nosols); fieldsNodes.push(stat_id); fieldsNodes.push(test_id); } function toggleHiddenFields() { if (areHiddenFields) { try { document.querySelector("input[name='nosols']").remove(); } catch(e) { } document.querySelector("input[name='stat_id']").remove(); document.querySelector("input[name='test_id']").remove(); document.getElementById("showAllAnswers").classList.toggle("activeControlButton"); areHiddenFields = false; } else { document.body.appendChild(fieldsNodes[0]); document.body.appendChild(fieldsNodes[1]); document.body.appendChild(fieldsNodes[2]); document.getElementById("showAllAnswers").classList.toggle("activeControlButton"); areHiddenFields = true; } } //}());