Advertisement
gur111

Moodle Hide answers in quiz overview

Mar 28th, 2022
739
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var isHidden = false;
  2. function hideAnswers(hidden) {
  3.     console.log('Answers will now be hidden:', hidden);
  4.     var elements = document.getElementsByClassName("outcome");
  5.     for (let i = 0; i < elements.length; i++) {
  6.         elements[i].style.display = hidden ? "none" : "block"
  7.     }
  8. }
  9.  
  10.  
  11.  
  12. let child = document.createElement('button');
  13. let body = document.getElementsByTagName('body')[0];
  14. let timeout = document.createElement('input');
  15. timeout.style = child.style = "background-color: #4CAF50;position: fixed; top: 100px; left: 29px; z-index: 1000000;";
  16. child.innerText = "Toggle Answers";
  17. child.id = 'toggle-btn';
  18. body.appendChild(child);
  19. timeout.style.backgroundColor = undefined;
  20. timeout.value = 0;
  21. timeout.style.top = "125px";
  22. body.appendChild(timeout);
  23.  
  24. child.onclick = () => {
  25.     let btn = document.getElementById('toggle-btn');
  26.     // btn.value = !btn.value;
  27.     isHidden = !isHidden;
  28.     if (isHidden) {
  29.         btn.style.backgroundColor = '#4CAF50';
  30.     } else {
  31.         btn.style.backgroundColor = "rgb(175 76 76)"
  32.     }
  33.     hideAnswers(isHidden);
  34.  
  35.     if (isHidden == false && timeout.value != 0) {
  36.         setTimeout(()=> child.onclick(), timeout.value);
  37.     }
  38. }
  39.  
  40. child.onclick();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement