Random answer

Cambia l'ordinamento delle domande dei test di fine lezione.

目前为 2023-12-01 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Random answer
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description Cambia l'ordinamento delle domande dei test di fine lezione.
  6. // @author You
  7. // @match https://lms-courses.pegaso.multiversity.click/main/lp-video_student_view/lesson_student_view.php*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=multiversity.click
  9. // @grant none
  10. // @license MIT
  11. // @require http://code.jquery.com/jquery-latest.js
  12. // ==/UserScript==
  13. /* global $ */
  14.  
  15. (function () {
  16. 'use strict';
  17. //RANDOM BOXES START
  18. function randomBoxes() {
  19. // Funzione per mischiare gli elementi di un array
  20. function shuffleArray(array) {
  21. for (let i = array.length - 1; i > 0; i--) {
  22. const j = Math.floor(Math.random() * (i + 1));
  23. [array[i], array[j]] = [array[j], array[i]];
  24. }
  25. }
  26.  
  27. // Ottieni tutti gli elementi con classe "panel-default"
  28. const panels = $('.col-md-8 .panel-default');
  29.  
  30. // Converti gli elementi jQuery in un array JavaScript
  31. const panelsArray = $.makeArray(panels);
  32.  
  33. // Mischia l'array di pannelli
  34. shuffleArray(panelsArray);
  35.  
  36. // Rimuovi tutti i pannelli dal documento
  37. $('.col-md-8 .panel-default').remove();
  38.  
  39. // Aggiungi i pannelli in ordine casuale al documento
  40. panelsArray.forEach(panel => {
  41. $('.col-md-8').append(panel);
  42. });
  43. }
  44. //RANDOME BOXES END
  45. if(!$('.button-container')) {
  46. // Creazione di un nuovo elemento div
  47. var buttonContainer = document.createElement("div");
  48.  
  49. // Assegnazione della classe "colore" al nuovo div
  50. buttonContainer.classList.add("button-container");
  51. } else {
  52.  
  53.  
  54. // Aggiunta del pulsante al div
  55. buttonContainer.innerHTML = "<button id='downloadDispenze' class='scriptBtn'>Random order</button>";
  56.  
  57. // Aggiunta del div al body (puoi aggiungerlo dove preferisci)
  58. document.body.appendChild(buttonContainer);
  59. }
  60. $('#downloadDispenze').on('click', function () {
  61. // Chiamare la funzione per mescolare le righe delle tabelle
  62. shuffleTableRows();
  63. randomBoxes();
  64.  
  65. });
  66. // Funzione per generare un numero casuale compreso tra min e max
  67. function getRandomInt(min, max) {
  68. return Math.floor(Math.random() * (max - min + 1)) + min;
  69. }
  70.  
  71. // Funzione per mescolare un array
  72. function shuffleArray(array) {
  73. for (let i = array.length - 1; i > 0; i--) {
  74. const j = getRandomInt(0, i);
  75. [array[i], array[j]] = [array[j], array[i]];
  76. }
  77. }
  78.  
  79. // Funzione per mescolare le righe delle tabelle
  80. function shuffleTableRows() {
  81. // Seleziona tutte le tabelle con la classe "table-hover"
  82. const tables = document.querySelectorAll('.table-hover');
  83.  
  84. // Per ogni tabella, mescola le righe nella sezione del corpo
  85. tables.forEach((table) => {
  86. const tbody = table.querySelector('tbody');
  87. const rows = Array.from(tbody.children);
  88.  
  89. // Mescola le righe
  90. shuffleArray(rows);
  91.  
  92. // Rimuovi le righe esistenti dalla tabella
  93. rows.forEach((row) => {
  94. tbody.removeChild(row);
  95. });
  96.  
  97. // Aggiungi le righe mescolate alla tabella
  98. rows.forEach((row) => {
  99. tbody.appendChild(row);
  100. });
  101. });
  102. }
  103.  
  104.  
  105. })();
  106. const injectCSS = css => {
  107. let el = document.createElement('style');
  108. el.type = 'text/css';
  109. el.innerText = css;
  110. document.head.appendChild(el);
  111. return el;
  112. };
  113.  
  114. injectCSS(`
  115. .scriptBtn {
  116. margin: 10px 10px 20px 0;
  117. background-color: #a42c52;
  118. font-style: italic;
  119. color: white;
  120. border: none;
  121. border-radius: 10px;
  122. padding: 10px;
  123. box-shadow: 5px 5px 8px -5px rgba(0,0,0,0.69);
  124. top: 100px;
  125. position: absolute;
  126. left: 540px;
  127. }
  128. `);