-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
88 lines (81 loc) · 2.74 KB
/
script.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/* Slideshow stuff */
var homePage = Boolean(window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1) == "index.html");
var openPageURL = window.location.protocol + '//' + window.location.hostname + '/';
var openPage = Boolean(window.location.href == openPageURL);
if (homePage || openPage) {
var slideIndex = 1;
showDivs(slideIndex);
function plusDivs(n) {
showDivs(slideIndex += n);
}
function currentDiv(n) {
showDivs(slideIndex = n);
}
function showDivs(n) {
var i;
var x = document.getElementsByClassName("testy");
var dots = document.getElementsByClassName("demo");
if (n > x.length) {slideIndex = 1}
if (n < 1) {slideIndex = x.length}
for (i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
for (i = 0; i < dots.length; i++) {
dots[i].className = dots[i].className.replace(" w3-black", "");
}
x[slideIndex-1].style.display = "block";
dots[slideIndex-1].className += " w3-black";
}
}
/* Refresh goes back to beginning */
//history.scrollRestoration = "manual";
//window.onload = function() {
// window.scrollTo(0,0);
// document.querySelector('html').style.scrollBehavior = '';
//}
/* Dark Mode Implementation */
var modeButton = document.querySelector(".theme-toggle");
var iconType = document.getElementById("sunmoon");
const prefersDarkScheme = window.matchMedia("(prefers-color-scheme: dark)");
var currentTheme = localStorage.getItem("theme");
var welcomeMsg = document.getElementById("welcome");
if (currentTheme == "dark") {
document.body.classList.toggle("dark-mode");
if (iconType.className == "fas fa-moon") {
iconType.className = "fas fa-sun";
}
if (homePage) {
welcomeMsg.innerHTML = "Welcome to my dark side.";
}
}
else if (currentTheme == "light") {
document.body.classList.toggle("light-mode");
if (iconType.className == "fas fa-sun") {
iconType.className = "fas fa-moon";
}
if (homePage) {
welcomeMsg.innerHTML = "Learn more about me!";
}
};
modeButton.addEventListener("click", function() {
if (prefersDarkScheme.matches) {
document.body.classList.toggle("light-mode");
var theme = document.body.classList.contains("light-mode") ? "light" : "dark";
} else {
document.body.classList.toggle("dark-mode");
var theme = document.body.classList.contains("dark-mode") ? "dark" : "light";
}
localStorage.setItem("theme", theme);
if (theme == "light") {
if (homePage) {
welcomeMsg.innerHTML = "Learn more about me!";
}
iconType.className = "fas fa-moon";
}
else {
if (homePage) {
welcomeMsg.innerHTML = "Welcome to my dark side.";
}
iconType.className = "fas fa-sun";
}
});