Auto select all right answer

try to take over the world!

  1. // ==UserScript==
  2. // @name Auto select all right answer
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.9
  5. // @description try to take over the world!
  6. // @author You
  7. // @run-at document-start
  8. // @match https://lms-courses.pegaso.multiversity.click/main/lp-video_student_view/*
  9. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js/
  10. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  11. // @grant none
  12. // @require http://code.jquery.com/jquery-latest.js
  13. // ==/UserScript==
  14. /* global $ */
  15. (function() {
  16. 'use strict';
  17. //RANDOME BOXES END
  18. function htmlToNode(htmlString) {
  19. // Crea un oggetto Range
  20. var range = document.createRange();
  21.  
  22. // Crea un nodo DocumentFragment utilizzando createContextualFragment
  23. var fragment = range.createContextualFragment(htmlString);
  24.  
  25. // Restituisci il primo nodo del DocumentFragment
  26. return fragment.firstChild;
  27. }
  28. var htmlString = "<button id='selectAllrights' class='scriptBtn'>FILL RIGHT ANSWER</button>";
  29. var nodoDOM = htmlToNode(htmlString);
  30. if(document.querySelector('.button-container')) {
  31.  
  32.  
  33. // Esempio di utilizzo
  34. buttonContainer = document.querySelector('.button-container');
  35.  
  36. buttonContainer.appendChild(nodoDOM)
  37. // Aggiunta del pulsante al div
  38. } else {
  39.  
  40. // Creazione di un nuovo elemento div
  41. var buttonContainer = document.createElement("div");
  42.  
  43. // Assegnazione della classe "colore" al nuovo div
  44. buttonContainer.classList.add("button-container");
  45. // Aggiunta del div al body (puoi aggiungerlo dove preferisci)
  46. var navbarPegaso = document.querySelector('.navbar-pegaso');
  47. //navbarPegaso.append(buttonContainer);
  48. navbarPegaso.parentNode.insertBefore(buttonContainer, navbarPegaso.nextSibling);
  49.  
  50. buttonContainer.appendChild(nodoDOM)
  51.  
  52. }
  53. $('.btn-submit').on('click', function() {
  54. $(document).ready(function() {
  55. // Conta gli elementi tr con la classe "success"
  56. var countSuccess = $("tr.success").length;
  57.  
  58. // Scrivi il totale in un paragrafo
  59. alert("Risposte esatte: " + countSuccess + " /10");
  60. });
  61. })
  62.  
  63. $('#selectAllrights').on('click',function (){
  64. async function runFirst(){
  65. var rightAns = [];
  66. var scriptTags = document.getElementsByTagName('script');
  67.  
  68. for (var i = 0; i < scriptTags.length; i++) {
  69. var script = scriptTags[i];
  70. var scriptText = script.innerHTML;
  71.  
  72. if (scriptText.includes("this.rightAns")) {
  73. var rightAnsString = scriptText.match(/this.rightAns\[(.*?)\]="(.*?)";/g);
  74.  
  75. for (var j = 0; j < rightAnsString.length; j++) {
  76. var match = rightAnsString[j].match(/this.rightAns\[(.*?)\]="(.*?)";/);
  77. var index = parseInt(match[1]);
  78. var value = match[2];
  79. rightAns[index] = value;
  80. }
  81. }
  82. }
  83.  
  84. for (var i = 1; i <= rightAns.length; i++) {
  85. var valueToSelect = rightAns[i];
  86. var selector = '.a-' + i + '[value="' + valueToSelect + '"]';
  87. var radioButton = document.querySelector(selector);
  88.  
  89. if (radioButton) {
  90. radioButton.checked = true;
  91. }
  92. }
  93.  
  94. await submitTest();
  95. }
  96. runFirst();
  97. });
  98. })();
  99. const injectCSS = css => {
  100. let el = document.createElement('style');
  101. el.type = 'text/css';
  102. el.innerText = css;
  103. document.head.appendChild(el);
  104. return el;
  105. };
  106.  
  107. injectCSS(`
  108. .btn-success, .btn-warning {
  109. position: fixed;
  110. top: 100px;
  111. width: 100px;
  112. border-radius: 50%;
  113. height: 100px;
  114. right: 0;
  115. bottom: 0;
  116. z-index: 1;
  117. }
  118. .button-container {
  119. z-index: 1;
  120. right: 0;
  121. position: fixed;
  122. top: 35%;
  123. padding: 10px;
  124. display: flex;
  125. flex-direction: column;
  126. align-items: center;
  127. }
  128.  
  129. `);