-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
61 lines (55 loc) · 1.83 KB
/
app.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
let collection = [
"001.js",//circle color black
"002.js",//stairs yellow all over
"004.js",//ants black circular
"005.js",//fractal build up from top
"003.js",//circle white petals
"007.js",//circular black particles
"008.js",//black 3d
"006.js",//cubes cray
"010.js",//circular stripes black
"009.js",//white all over stripes
"011.js",//circular orbit 3d black
"012.js",//sketch white
];
//
let collectionItem = localStorage.getItem('collectionItem');
collectionItem++;
localStorage.setItem('collectionItem', collectionItem);
if (collectionItem >= collection.length) {
collectionItem = 0;
localStorage.setItem('collectionItem', collectionItem);
}
let file = collection[collectionItem];
//
function loadJS(FILE_URL, async = true) {
let scriptEle = document.createElement("script");
scriptEle.setAttribute("src", FILE_URL);
scriptEle.setAttribute("type", "text/javascript");
scriptEle.setAttribute("async", async);
document.body.appendChild(scriptEle);
// success event
scriptEle.addEventListener("load", () => {
console.log("File loaded")
});
// error event
scriptEle.addEventListener("error", (ev) => {
console.log("Error on loading file", ev);
});
}
const urlSearchParams = new URLSearchParams(window.location.search);
const params = Object.fromEntries(urlSearchParams.entries());
if (params.file) {
file = params.file;
}
loadJS("./collection/" + file, false);
async function loadSourceCode() {
const response = await fetch("./collection/" + file);
const data = await response.text();
var elemDiv = document.createElement('div');
elemDiv.innerHTML = '<pre id="preSourceCode"><code id="sourceCode" class="language-javascript"></code></pre>';
document.body.appendChild(elemDiv);
document.getElementById("sourceCode").innerHTML = data;
hljs.highlightAll();
}
setTimeout(loadSourceCode, 1000);