Random answer

Cambia l'ordinamento delle domande dei test di fine lezione

目前为 2023-11-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Random answer
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  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. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15. $("#main-contents").append("<button id='downloadDispenze' class='scriptBtn'>Random order</button>");
  16. $('#downloadDispenze').on('click', function () {
  17. // Chiamare la funzione per mescolare le righe delle tabelle
  18. shuffleTableRows();
  19.  
  20. });
  21. // Funzione per generare un numero casuale compreso tra min e max
  22. function getRandomInt(min, max) {
  23. return Math.floor(Math.random() * (max - min + 1)) + min;
  24. }
  25.  
  26. // Funzione per mescolare un array
  27. function shuffleArray(array) {
  28. for (let i = array.length - 1; i > 0; i--) {
  29. const j = getRandomInt(0, i);
  30. [array[i], array[j]] = [array[j], array[i]];
  31. }
  32. }
  33.  
  34. // Funzione per mescolare le righe delle tabelle
  35. function shuffleTableRows() {
  36. // Seleziona tutte le tabelle con la classe "table-hover"
  37. const tables = document.querySelectorAll('.table-hover');
  38.  
  39. // Per ogni tabella, mescola le righe nella sezione del corpo
  40. tables.forEach((table) => {
  41. const tbody = table.querySelector('tbody');
  42. const rows = Array.from(tbody.children);
  43.  
  44. // Mescola le righe
  45. shuffleArray(rows);
  46.  
  47. // Rimuovi le righe esistenti dalla tabella
  48. rows.forEach((row) => {
  49. tbody.removeChild(row);
  50. });
  51.  
  52. // Aggiungi le righe mescolate alla tabella
  53. rows.forEach((row) => {
  54. tbody.appendChild(row);
  55. });
  56. });
  57. }
  58.  
  59.  
  60. })();
  61. const injectCSS = css => {
  62. let el = document.createElement('style');
  63. el.type = 'text/css';
  64. el.innerText = css;
  65. document.head.appendChild(el);
  66. return el;
  67. };
  68. injectCSS(`
  69. .scriptBtn {
  70. margin: 10px 10px 20px 0;
  71. background-color: #a42c52;
  72. font-style: italic;
  73. color: white;
  74. border: none;
  75. border-radius: 10px;
  76. padding: 10px;
  77. box-shadow: 5px 5px 8px -5px rgba(0,0,0,0.69);
  78. top: 100px;
  79. position: absolute;
  80. left: 540px;
  81. }
  82. `);