-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariables.js
54 lines (40 loc) · 1022 Bytes
/
variables.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
//Because of changing the innerHTML
class Variable {
constructor(name, value, varTag) {
this.__name = name;
this.__val = value;
this.__tag = varTag;
}
get value() {
this.__val = eval(this.__tag.innerHTML);
return this.__val;
}
set value(newValue){
this.__val = newValue;
this.__tag.innerHTML = this.__val;
}
get name() {
return this.__name;
}
get tag() {
return this.__tag;
}
}
function __isValidVarName(name) {
return name.length > 0 && isNaN(name[0]);
}
function loadVariables(){
var vars = __getTags("var");
for(let i = 0; i < vars.length; i++) {
if(!__isValidVarName(vars[i].getAttribute("name"))) {
console.error("invalid variable name");
continue;
}
//Global variables can be assigned using window.variable = value
eval(`window.${vars[i].getAttribute("name")} = new Variable(\"${vars[i].getAttribute("name")}\", ${vars[i].innerHTML}, vars[i])`);
if(!boolValue(vars[i].getAttribute("visible"))){
vars[i].style.display = "none";
}
}
}
loadVariables();