-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathucm-cv-mod-assign-mark.js
69 lines (54 loc) · 2.08 KB
/
ucm-cv-mod-assign-mark.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// ==UserScript==
// @name Mod de marcas de entregas realizadas CV UCM (ucm-cv-mod-assign-mark)
// @namespace https://juancrrn.io
// @version 0.2
// @description Mod de marcas de entregas realizadas para el Campus virtual de la Universidad Complutense de Madrid
// @author juancrrn
// @match https://cvmdp.ucm.es/moodle/course/*
// @require https://code.jquery.com/jquery-3.5.1.slim.min.js
// ==/UserScript==
/**
* @var {Object} mod Auxiliar object used as namespace for variables and functions
*/
var mod = {};
/**
* @var {string} name Name of the current mod, for console debugging.
*/
mod.name = 'ucm-cv-mod-assign-mark';
/**
* @var {string} storageName Name of the stored assignments cookie.
*/
mod.storageName = 'ucm_cvmdp_stored_submitted_assignments_data_v0.2';
/**
* Retrieves a client cookie by its name.
*
* @param {string} name Name of the cookie to retrieve.
*
* @return {string} Content of the retrieved cookie.
*/
mod.readCookie = function (name) {
var nameEQ = name + '=';
var ca = document.cookie.split(';');
for(var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
// Wait for the document to be loaded
$(() => {
// Get stored assignments cookie
var storedAssignmentsRaw = mod.readCookie(mod.storageName);
console.log(mod.name + ': Currently stored assignments are ' + storedAssignmentsRaw);
// Parse cookie
var storedAssignments = storedAssignmentsRaw.split('-');
$.each(storedAssignments, function (k, v) {
var id = '#module-' + v;
console.log(mod.name + ': ' + id + ' is stored as submitted.');
var badgeHtml = '<span style="text-indent: 0; color: #398439; vertical-align: middle;"><i class="icon fa fa-check fa-fw " title="Entregado"></i></span>';
// Mark the assignments
$(badgeHtml).insertBefore(id + ' .instancename');
$(id + ' .instancename').css('vertical-align', 'middle');
});
});