-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewpoly.js
More file actions
80 lines (76 loc) · 2.06 KB
/
newpoly.js
File metadata and controls
80 lines (76 loc) · 2.06 KB
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
72
73
74
75
76
77
78
79
80
function setCookie(cname, cvalue, exdays) {
const d = new Date();
d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
let expires = "expires="+d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
function getCookie(cname) {
let name = cname + "=";
let ca = document.cookie.split(';');
for(let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
// Underli holds all underlined vars (pre-cookie)
let underli = []
function underline(elem) {
// Target the innerHTML of the button, not the button element
if (elem.firstChild && elem.firstChild.tagName === "MARK") {
// Unwrap the <mark>
const mark = elem.firstChild;
elem.innerHTML = mark.innerHTML;
underli.splice(underli.indexOf(elem), 1);
} else {
// Wrap all inner content in <mark>
elem.innerHTML = `<mark>${elem.innerHTML}</mark>`;
underli.push(elem);
}
clean(underli, "arr");
jsoSET(underli);
}
// send each line of a array to html (array, htmlElem)
function clean(un,arr){
let arra = document.getElementById(arr);
let text = "";
for (let i=0;i<un.length;i++) {
text += un[i].id +", ";
}
arra.innerHTML = text;
}
// Turn a String into array (array)
function jsoSET(un){
let convarr = []
for(let i =0;i<un.length;i++){
convarr.push(un[i].id);
}
let j = JSON.stringify(convarr);
setCookie("un",j,364);
}
// Retrieve a String Array (cookie)
function jsoRET(cookie){
let str = getCookie(cookie);
return JSON.parse(str);
}
window.main = function(){
requestAnimationFrame( main );
// Retrieve the ID's of all previously saved verses
jj = jsoRET("un")
document.getElementById("cook").innerHTML = jj;
if(jj !=undefined){
for(let i = 0; i<jj.length;i++){
// Rerender all saved verses
let tempelm = document.getElementById(jj[i])
underline(tempelm);
}
}
};main();
function delCooki(){
setCookie("un","",-365);
}