-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib.js
71 lines (64 loc) · 1.84 KB
/
lib.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
70
71
function setCookie(cname, cvalue, exdays = 999) {
var d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/;SameSite=Lax";
}
function getCookie(cname) {
var name = cname + "=";
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);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function load_cookie(matiere = "anglais") {
var txt = getCookie(matiere + "_disabled");
if (txt == "") {
return [];
}
//
try {
var data_disabled = JSON.parse(txt);
if (data_disabled != null) {
return data_disabled;
} else {
return [];
}
} catch (error) {
return [];
}
}
function save_cookie(data_disabled, matiere = "anglais") {
var txt = JSON.stringify(data_disabled);
setCookie(matiere + "_disabled", txt, 730);
}
function arrayRemove(arr, value) {
return arr.filter(function(ele) {
return ele != value;
});
}
// Function to download data to a file
function download(data, filename, type) {
var file = new Blob([data], { type: type });
if (window.navigator.msSaveOrOpenBlob) // IE10+
window.navigator.msSaveOrOpenBlob(file, filename);
else { // Others
var a = document.createElement("a"),
url = URL.createObjectURL(file);
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
setTimeout(function() {
document.body.removeChild(a);
window.URL.revokeObjectURL(url);
}, 0);
}
}