Created
November 27, 2017 02:30
-
-
Save JohannesFischer/b6deba535f86c636a2ccb02ce77509eb to your computer and use it in GitHub Desktop.
e-learning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log('E-Learning Boost Activated'); | |
let initialized = false; | |
function getAnswerWindow() { | |
let win = window; | |
while (win.window.length > 0) { | |
win = win.window[1]; | |
} | |
return win; | |
} | |
window.setTimeout(() => { | |
const win = getAnswerWindow(); | |
if (win.arrowKeyEvent || window !== win) return false; | |
console.log('addEvent', win); | |
win.addEventListener('keydown', (e) => { | |
if (e.keyCode === 39) { | |
e.preventDefault(); | |
const nextBtn = win.parent.window[0].document.querySelector('#next_btn'); | |
if (nextBtn) { | |
return nextBtn.click() | |
} | |
const nextQuestion = win.document.querySelector('#btnnext a'); | |
if (nextQuestion) { | |
return nextQuestion.click(); | |
} | |
const disabledNextQuestion = win.document.querySelector('#btnnext > img'); | |
const submitResponses = win.document.querySelector('#btnsaiten a'); | |
if (disabledNextQuestion && submitResponses) { | |
return submitResponses.click(); | |
} | |
} | |
win.arrowKeyEvent = true; | |
}); | |
}, 1000); | |
function checkAnswers(win) { | |
if (!initialized) { | |
win.document.querySelector('#btnnext').addEventListener('click', () => { | |
window.setTimeout(() => { | |
checkAnswers(win); | |
}, 500); | |
}); | |
initialized = true; | |
} | |
const isTrueFalse = win.document.querySelectorAll('[class^="choice-tf"]').length > 0; | |
if (!isTrueFalse) { | |
win.disp_correct_CR("disp"); | |
} else { | |
win.disp_correct_TF("disp"); | |
} | |
window.setTimeout(() => { | |
if (isTrueFalse) { | |
const image = win.document.querySelector('[class^="crct-tf"] img'); | |
const answer = parseInt(image.parentNode.className.match(/\d+/)[0], 0); | |
win.q_choice(answer); | |
} else { | |
const images = [...win.document.querySelectorAll('td.crct-cr img')]; | |
if (images.length) { | |
for (let i = 0; i < images.length; i++) { | |
const event = new MouseEvent('click', { | |
'view': window, | |
'bubbles': true | |
}); | |
const input = images[i].parentNode.parentNode.querySelector('input'); | |
if (!input.checked) { | |
input.dispatchEvent(event); | |
} | |
} | |
} | |
} | |
}, 100); | |
} | |
window.setTimeout(() => { | |
let win = getAnswerWindow(); | |
if (!win || !win.hasOwnProperty('disp_correct_CR')) { | |
return false; | |
} else { | |
console.log('Using window object: ', win); | |
} | |
if (win.document.getElementById('btnstart') !== null) { | |
win.document.getElementById('btnstart').addEventListener('click', () => { | |
window.setTimeout(() => { | |
checkAnswers(win); | |
}, 500); | |
}); | |
} else { | |
window.setTimeout(() => { | |
checkAnswers(win); | |
}, 500); | |
} | |
}, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment