-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.js
More file actions
39 lines (36 loc) · 1.12 KB
/
init.js
File metadata and controls
39 lines (36 loc) · 1.12 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
// JSON structured as "name-of-file": ["possible", "search", "terms"]
// TODO put search terms for each file here
const jsFiles = {
'app.js': [],
'multiple.js': [],
'click.js': [],
'outrun.js': [],
'penrose.js': [],
'paradise.js': [],
'global.js': [],
'graph.js': [],
'energy.js': [],
};
var debug = false;
window.onload = () => {
var script = document.createElement('script');
script.type = 'module';
var url = window.location.href;
var split = url.split('?');
var param = split[split.length - 1];
var visited = Object.keys(sessionStorage);
var files = Object.keys(jsFiles);
var unvisited = files.filter((v) => !visited.includes(v));
if (param != undefined && files.some((file) => file.includes(param))) {
script.src = 'js/' + files.find((file) => file.includes(param));
} else {
if (unvisited.length == 0) {
sessionStorage.clear();
unvisited = files;
}
var source = unvisited[Math.floor(Math.random() * unvisited.length)];
script.src = 'js/' + source;
sessionStorage.setItem(source, 'visited');
}
document.getElementsByTagName('footer')[0].appendChild(script);
};