add slow loading
Marco Andronaco andronacomarco@gmail.com
Sun, 18 Sep 2022 21:19:51 +0200
9 files changed,
57 insertions(+),
7 deletions(-)
M
index.html
→
index.html
@@ -69,6 +69,7 @@ <span id="song-text">Jay Tholen - Awesome Rap Beat (Hypnospace Outlaw Original Soundtrack, Vol. 2)</span>
</div> </div> <script src="res/script.js"></script> + <script src="res/slow_load.js"></script> </body> </html>
M
pages/about.html
→
pages/about.html
@@ -4,11 +4,12 @@
<head> <meta charset="UTF-8"> <link rel="stylesheet" href="../res/style.css"> - <link href="https://pvinis.github.io/iosevka-webfont/3.4.1/iosevka.css" rel="stylesheet" /> </head> <body> <h1>About me</h1> + + <script src="../res/slow_load.js"></script> </body> </html>
M
pages/anime.html
→
pages/anime.html
@@ -6,7 +6,6 @@ <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <link rel="stylesheet" href="../res/style.css"> - <link href="https://pvinis.github.io/iosevka-webfont/3.4.1/iosevka.css" rel="stylesheet" /> </head> <body>@@ -16,6 +15,8 @@ JoJo's Bizarre Adventure
Gurren Lagann Dragon Quest Dai's Adventure (remake 2021) --> + + <script src="../res/slow_load.js"></script> </body> </html>
M
pages/dragonquest.html
→
pages/dragonquest.html
@@ -6,11 +6,12 @@ <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <link rel="stylesheet" href="../res/style.css"> - <link href="https://pvinis.github.io/iosevka-webfont/3.4.1/iosevka.css" rel="stylesheet" /> </head> <body> <h1>Dragon Quest</h1> + + <script src="../res/slow_load.js"></script> </body> </html>
M
pages/earthbound.html
→
pages/earthbound.html
@@ -6,11 +6,12 @@ <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <link rel="stylesheet" href="../res/style.css"> - <link href="https://pvinis.github.io/iosevka-webfont/3.4.1/iosevka.css" rel="stylesheet" /> </head> <body> <h1>Earthbound</h1> + + <script src="../res/slow_load.js"></script> </body> </html>
M
pages/gf.html
→
pages/gf.html
@@ -6,11 +6,12 @@ <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <link rel="stylesheet" href="../res/style.css"> - <link href="https://pvinis.github.io/iosevka-webfont/3.4.1/iosevka.css" rel="stylesheet" /> </head> <body> <h1>My love Giulia</h1> + + <script src="../res/slow_load.js"></script> </body> </html>
M
pages/indies.html
→
pages/indies.html
@@ -6,7 +6,6 @@ <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <link rel="stylesheet" href="../res/style.css"> - <link href="https://pvinis.github.io/iosevka-webfont/3.4.1/iosevka.css" rel="stylesheet" /> </head> <body>@@ -17,6 +16,8 @@ <h2>Fran Bow</h2>
<h2>Psychonauts</h2> <h2>Undertale</h2> <h2>Hylics</h2> + + <script src="../res/slow_load.js"></script> </body> </html>
M
pages/zelda.html
→
pages/zelda.html
@@ -6,11 +6,12 @@ <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <link rel="stylesheet" href="../res/style.css"> - <link href="https://pvinis.github.io/iosevka-webfont/3.4.1/iosevka.css" rel="stylesheet" /> </head> <body> <h1>The Legend of Zelda</h1> + + <script src="../res/slow_load.js"></script> </body> </html>
A
res/slow_load.js
@@ -0,0 +1,42 @@
+ + +function slow_load(speed=0.5, not_allowed=[], callback) { + + function onFinish(node, initial_display){ + node.style.display = initial_display; + counter++; + ratio = counter / total * 100; + + if (ratio >= 100 && callback) + callback() + } + + function getRandomInt(min, max) { + min = Math.ceil(min); + return Math.floor(Math.random() * (Math.floor(max) - min + 1)) + min; + } + + const all = document.getElementsByTagName("*"); + let counter = 0; + let total = 0; + let i = 0; + for (i in all) { + const node = all[i]; + if((node.childElementCount == 0) && (not_allowed.indexOf(node.tagName) === -1) && node.style){ + i += getRandomInt(5 / speed, 20 / speed); + total++; + const initial_display = node.style.display; + node.style.display = "none"; + setTimeout(() => { onFinish(node, initial_display);}, i); + } + } +} + +const not_allowed = ["META", "TITLE", "LINK", "SOURCE", "SCRIPT"]; + +function finishedCallback() { + console.log("FINISHED!"); +} + +// page logic +slow_load(speed=1.25, not_allowed, finishedCallback);