Advertisement
ParasherX01

Untitled

Apr 4th, 2020
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getCookie(name) {
  2.   let matches = document.cookie.match(new RegExp(
  3.     "(?:^|; )" + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + "=([^;]*)"
  4.   ));
  5.   return matches ? decodeURIComponent(matches[1]) : undefined;
  6. }
  7. function getRandomInt(max) {
  8.   return Math.floor(Math.random() * Math.floor(max));
  9. }
  10. function goToNext() {
  11.   if($(".cn-nav-right-Exercise").length != 0){
  12.     document.location.href = $(".cn-nav-right-Exercise").attr("href");
  13.   }else{
  14.     console.log("go back");
  15.     document.location.href = $(".cn-nav-top-").attr("href");
  16.   }
  17. }
  18. function switchBot() {
  19.   if(botStatement){
  20.     document.cookie = "botStatement=false; max-age=13600";
  21.     document.cookie = "wrongAnswers; max-age=-1";
  22.     document.cookie = "currentAnswers; max-age=-1";
  23.   }else{
  24.     document.cookie = "botStatement=true; max-age=13600";
  25.   }
  26.   document.location.reload();
  27. }
  28.  
  29. botStatement = false;
  30. $(function() {
  31. console.log("pastebin edition");
  32.   //Проверка на включенность
  33.   if(getCookie("botStatement") == "true"){
  34.     botStatement = true;
  35.     setTimeout(function() {
  36.       //Проверка на местонахождение на странице с отдельным вопросом
  37.       if($(".no-bmarg").length != 0){
  38.         //Проверка на страницу с результатами
  39.         if($(".gxs-result").length != 0){
  40.           //Если ответ правильный
  41.           if($(".gxs-result").attr("data-is-correct") == "true"){
  42.             console.log("next");
  43.             document.cookie = "wrongAnswers; max-age=-1";
  44.             document.cookie = "currentAnswers; max-age=-1";
  45.             goToNext()
  46.           //Если ответ ложный
  47.           }else{
  48.             console.log(getCookie("currentAnswers") + " is wrong");
  49.             console.log("retry");
  50.             document.cookie = "wrongAnswers=" + JSON.parse(getCookie("wrongAnswers")).push(getCookie("currentAnswers")) + "; max-age=13600";
  51.             document.cookie = "currentAnswers; max-age=-1";
  52.             document.location.href = $("div.task-buttons > a.btn").attr("href");
  53.           }
  54.         //Страница с вопросом и вариантами ответа
  55.         }else{
  56.           if (($("input[type=radio]").length == 1 || $("select.gxs-answer-dropdown").length == 1) && $("input[type=text]").length == 0) {
  57.             console.log("checking...");
  58.            
  59.             if(getCookie("wrongAnswers") != undefined){
  60.               wrongAnswers = JSON.parse(getCookie("wrongAnswers"));
  61.             }else{
  62.               wrongAnswers = [];
  63.             }
  64.             console.log("wrong answers:");
  65.             console.log(wrongAnswers);
  66.             var i = 0;
  67.            
  68.             if($("input[type=radio]").length == 1){
  69.               for (; i < $("input[type=radio]").length; i++) {
  70.                 if(!(wrongAnswers.includes($($("input[type=radio]")[i]).val()))){
  71.                   break;
  72.                 }
  73.               }
  74.               $($("input[type=radio]")[i]).click();
  75.               document.cookie = "currentAnswers=" + $($("input[type=radio]")[i]).val() + "; max-age=13600";
  76.             }else if($("select.gxs-answer-dropdown").length == 1){
  77.               for (; i < $("select.gxs-answer-dropdown > option").length; i++) {
  78.                 if(!(wrongAnswers.includes($($("select.gxs-answer-dropdown > option")[i]).val()))){
  79.                   break;
  80.                 }
  81.               }
  82.               $($("select.gxs-answer-dropdown > option")[i]).attr('selected', 'true');
  83.               document.cookie = "currentAnswers=" + $($("select.gxs-answer-dropdown > option")[i]).val() + "; max-age=13600";
  84.             }
  85.            
  86.             console.log(getCookie("currentAnswers"));
  87.             $("#submitAnswerBtn").click();
  88.            
  89.           }else{
  90.             console.log("too hard");
  91.             goToNext();
  92.           }
  93.         }
  94.       }
  95.     }, 3000)
  96.   }
  97.  
  98.   //Панель управления
  99.   if(botStatement){
  100.     buttonText = "Выкл";
  101.   }else{
  102.     buttonText = "Вкл";
  103.   }
  104.   $("<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"));
  105. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement