gur111 icon

Moodle Hide answers in quiz overview

gur111 | PRO | 03/28/22 05:58:47 PM UTC | 0 ⭐ | 1046 👁️ | Never ⏰ | []
JavaScript |

1.21 KB

|

None

|

0 👍

/

0 👎

var isHidden = false;
function hideAnswers(hidden) {
    console.log('Answers will now be hidden:', hidden);
    var elements = document.getElementsByClassName("outcome");
    for (let i = 0; i < elements.length; i++) {
        elements[i].style.display = hidden ? "none" : "block"
    }
}
 
 
 
let child = document.createElement('button');
let body = document.getElementsByTagName('body')[0];
let timeout = document.createElement('input');
timeout.style = child.style = "background-color: #4CAF50;position: fixed; top: 100px; left: 29px; z-index: 1000000;";
child.innerText = "Toggle Answers";
child.id = 'toggle-btn';
body.appendChild(child);
timeout.style.backgroundColor = undefined;
timeout.value = 0;
timeout.style.top = "125px";
body.appendChild(timeout);
 
child.onclick = () => {
    let btn = document.getElementById('toggle-btn');
    // btn.value = !btn.value;
    isHidden = !isHidden;
    if (isHidden) {
        btn.style.backgroundColor = '#4CAF50';
    } else {
        btn.style.backgroundColor = "rgb(175 76 76)"
    }
    hideAnswers(isHidden);
 
    if (isHidden == false && timeout.value != 0) {
        setTimeout(()=> child.onclick(), timeout.value);
    }
}
 
child.onclick();

Comments