res/iframe.js (view raw)
1const loadAudio = [
2 new Audio(url="../res/sfx/os/loadelement1.ogg"),
3 new Audio(url="../res/sfx/os/loadelement2.ogg"),
4 new Audio(url="../res/sfx/os/loadelement3.ogg"),
5 new Audio(url="../res/sfx/os/loadelement4.ogg")
6]
7const not_allowed = ["AUDIO", "META", "TITLE", "LINK", "SOURCE", "SCRIPT", "BR"];
8
9function getRandomInt(min, max) {
10 min = Math.ceil(min);
11 return Math.floor(Math.random() * (Math.floor(max) - min + 1)) + min;
12}
13
14function playAudio(audio){
15 audio.volume = 0.1;
16 audio.currentTime = 0;
17 audio.play();
18}
19
20const all = document.getElementsByTagName("*");
21let total = 0;
22for (i in all) {
23 const node = all[i];
24 if((node.childElementCount == 0) && (not_allowed.indexOf(node.tagName) === -1) && node.style){
25 total++;
26 node.setAttribute("data-display", node.style.display);
27 node.style.display = "none";
28 }
29}
30
31function start_loading(speed=parent.loadSpeed, not_allowed=[], callback) {
32
33 function onNodeLoaded(node){
34 node.style.display = node.getAttribute("data-display");
35 counter++;
36 ratio = counter / total * 100;
37 randomAudio();
38
39 if (ratio >= 100 && callback)
40 callback()
41 }
42
43 let counter = 0;
44 let i = 0;
45 for (element in all) {
46 const node = all[element];
47 if((node.childElementCount == 0) && (not_allowed.indexOf(node.tagName) === -1) && node.style){
48
49 i += getRandomInt(250 / speed, 500 / speed);
50 setTimeout(() => { onNodeLoaded(node);}, i);
51 }
52 }
53}
54
55function randomAudio(){
56 const random_audio = getRandomInt(0, loadAudio.length - 1);
57 playAudio(loadAudio[random_audio]);
58}
59