Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getCookie(name) {
- let matches = document.cookie.match(new RegExp(
- "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
- ));
- return matches ? decodeURIComponent(matches[1]) : undefined;
- }
- function getRandomInt(max) {
- return Math.floor(Math.random() * Math.floor(max));
- }
- function goToNext() {
- if($(".cn-nav-right-Exercise").length != 0){
- document.location.href = $(".cn-nav-right-Exercise").attr("href");
- }else{
- console.log("go back");
- document.location.href = $(".cn-nav-top-").attr("href");
- }
- }
- function switchBot() {
- if(botStatement){
- document.cookie = "botStatement=false; max-age=13600";
- document.cookie = "wrongAnswers; max-age=-1";
- document.cookie = "currentAnswers; max-age=-1";
- }else{
- document.cookie = "botStatement=true; max-age=13600";
- }
- document.location.reload();
- }
- botStatement = false;
- $(function() {
- console.log("pastebin edition");
- //Проверка на включенность
- if(getCookie("botStatement") == "true"){
- botStatement = true;
- setTimeout(function() {
- //Проверка на местонахождение на странице с отдельным вопросом
- if($(".no-bmarg").length != 0){
- //Проверка на страницу с результатами
- if($(".gxs-result").length != 0){
- //Если ответ правильный
- if($(".gxs-result").attr("data-is-correct") == "true"){
- console.log("next");
- document.cookie = "wrongAnswers; max-age=-1";
- document.cookie = "currentAnswers; max-age=-1";
- goToNext()
- //Если ответ ложный
- }else{
- console.log(getCookie("currentAnswers") + " is wrong");
- console.log("retry");
- document.cookie = "wrongAnswers=" + JSON.parse(getCookie("wrongAnswers")).push(getCookie("currentAnswers")) + "; max-age=13600";
- document.cookie = "currentAnswers; max-age=-1";
- document.location.href = $("div.task-buttons > a.btn").attr("href");
- }
- //Страница с вопросом и вариантами ответа
- }else{
- if (($("input[type=radio]").length == 1 || $("select.gxs-answer-dropdown").length == 1) && $("input[type=text]").length == 0) {
- console.log("checking...");
- if(getCookie("wrongAnswers") != undefined){
- wrongAnswers = JSON.parse(getCookie("wrongAnswers"));
- }else{
- wrongAnswers = [];
- }
- console.log("wrong answers:");
- console.log(wrongAnswers);
- var i = 0;
- if($("input[type=radio]").length == 1){
- for (; i < $("input[type=radio]").length; i++) {
- if(!(wrongAnswers.includes($($("input[type=radio]")[i]).val()))){
- break;
- }
- }
- $($("input[type=radio]")[i]).click();
- document.cookie = "currentAnswers=" + $($("input[type=radio]")[i]).val() + "; max-age=13600";
- }else if($("select.gxs-answer-dropdown").length == 1){
- for (; i < $("select.gxs-answer-dropdown > option").length; i++) {
- if(!(wrongAnswers.includes($($("select.gxs-answer-dropdown > option")[i]).val()))){
- break;
- }
- }
- $($("select.gxs-answer-dropdown > option")[i]).attr('selected', 'true');
- document.cookie = "currentAnswers=" + $($("select.gxs-answer-dropdown > option")[i]).val() + "; max-age=13600";
- }
- console.log(getCookie("currentAnswers"));
- $("#submitAnswerBtn").click();
- }else{
- console.log("too hard");
- goToNext();
- }
- }
- }
- }, 3000)
- }
- //Панель управления
- if(botStatement){
- buttonText = "Выкл";
- }else{
- buttonText = "Вкл";
- }
- $("<div style='display: flex;justify-content: center;align-items: center;top: calc(100vh - 50px);left: 0;position: fixed;z-index: 100;background: aquamarine;padding: 10px;height: 50px;'><span style='margin-right:10px;'>Бот</span><button onclick='switchBot()'>" + buttonText + "</button></div>").appendTo($("body"));
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement