Skip to content

Instantly share code, notes, and snippets.

@bihius
Forked from Qwizi/ang.js
Last active January 24, 2025 15:45
Show Gist options
  • Save bihius/76afc76023e78f6ec5a1fe8e43bfb4db to your computer and use it in GitHub Desktop.
Save bihius/76afc76023e78f6ec5a1fe8e43bfb4db to your computer and use it in GitHub Desktop.
ang
// ==UserScript==
// @name SCORM Module Completer
// @namespace https://moodle2.e-wsb.pl/
// @version 1.1
// @match https://moodle2.e-wsb.pl/pluginfile.php/*/mod_scorm/content/*/index_lms*.html
// @grant none
// ==/UserScript==
(() => {
'use strict';
console.log('Moodle solver');
// Poczekaj, aż strona w pełni załaduje się
window.addEventListener('load', () => {
console.log('Executing SCORM completion script...');
try {
// Twój kod do uruchomienia
(() => {
try {
// Mark all objectives as completed
const objectiveCount = Number(SCORM2004_CallGetValue('cmi.objectives._count'));
if (objectiveCount > 0) console.log(`Completing ${objectiveCount} objectives`);
for (var i = 0; i < objectiveCount; i++) {
const objectiveId = SCORM2004_CallGetValue('cmi.objectives.' + i + '.id');
SCORM2004_SetObjectiveStatus(objectiveId, LESSON_STATUS_PASSED);
}
// Mark all interactions as correct
const interactionCount = Number(SCORM2004_CallGetValue('cmi.interactions._count'));
if (interactionCount > 0) console.log(`Completing ${interactionCount} interactions`);
for (var i = 0; i < interactionCount; i++) {
const interactionId = SCORM2004_CallGetValue('cmi.interactions.' + i + '.id');
const correctResponse = SCORM2004_GetInteractionCorrectResponse(interactionId);
const interactionType = SCORM2004_GetInteractionType(interactionId);
SCORM2004_RecordInteraction(
interactionId,
correctResponse,
true,
correctResponse,
'',
0,
0,
'',
new Date(),
interactionType
);
}
// Set the score above the passing score
const passingScore = SCORM2004_GetPassingScore() + 1;
const minScore = SCORM2004_CallGetValue('cmi.score.min');
const maxScore = SCORM2004_CallGetValue('cmi.score.max');
// Not all courses/modules have a score, so we need to check if it exists
if (minScore !== '' && maxScore !== '') {
const score = Math.min(Math.max(passingScore, minScore), maxScore);
console.log(`Setting score to ${score} out of ${maxScore} possible points`);
SCORM2004_SetScore(score, minScore, maxScore);
}
// Mark the module as completed and passed
console.log('Setting module as completed and passed');
SCORM2004_SetPassed();
// Fake the time it took to complete the module
const milisecondsInMinute = 60 * 1000;
const randomTime =
Math.floor(Math.random() * 15 * milisecondsInMinute) + 5 * milisecondsInMinute;
console.log(`Setting time to ${randomTime / milisecondsInMinute} minutes`);
SCORM2004_SaveTime(randomTime);
// Finish the module
SCORM2004_Finish(SCORM2004_NORMAL_EXIT, false);
// Dodanie potwierdzenia na ekranie
alert('Module completed!');
const confirmationDiv = document.createElement('div');
confirmationDiv.style.position = 'fixed';
confirmationDiv.style.bottom = '10px';
confirmationDiv.style.right = '10px';
confirmationDiv.style.padding = '15px';
confirmationDiv.style.backgroundColor = '#4CAF50';
confirmationDiv.style.color = 'white';
confirmationDiv.style.fontSize = '16px';
confirmationDiv.style.borderRadius = '5px';
confirmationDiv.style.boxShadow = '0px 4px 6px rgba(0, 0, 0, 0.1)';
confirmationDiv.textContent = '✔️ Moduł został ukończony!';
document.body.appendChild(confirmationDiv);
setTimeout(() => {
confirmationDiv.remove();
}, 5000);
console.log('Module completed successfully, you can close the window');
} catch (error) {
console.error('An error occurred while trying to complete the module', error);
alert('There is error. You will die.');
}
})();
} catch (error) {
console.error('Error executing script:', error);
alert('Błąd krytyczny podczas uruchamiania skryptu.');
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment