-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
69 lines (56 loc) · 1.92 KB
/
Copy pathscript.js
File metadata and controls
69 lines (56 loc) · 1.92 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
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
document.addEventListener("DOMContentLoaded", () => {
const themeToggle = document.getElementById("themeToggle");
if (localStorage.getItem("theme") === "dark") {
document.body.classList.add("darkMode");
}
themeToggle.addEventListener("click", () => {
document.body.classList.toggle("darkMode");
if (document.body.classList.contains("darkMode")) {
localStorage.setItem("theme", "dark");
} else {
localStorage.setItem("theme", "light");
}
});
const hamburger = document.getElementById("hamburger");
const navMenu = document.getElementById("navMenu");
hamburger.addEventListener("click", () => {
navMenu.classList.toggle("active");
});
const navLink = document.querySelectorAll(".navLink");
navLink.forEach((link) => {
link.addEventListener("click", () => {
navMenu.classList.remove("active");
});
});
const sections = document.querySelectorAll("section");
const navLinks = document.querySelectorAll(".navLink");
window.addEventListener("scroll", () => {
let currentSection = "";
sections.forEach((section) => {
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
if (scrollY >= sectionTop - 80) {
currentSection = section.getAttribute("id");
}
navLinks.forEach((link) => {
link.classList.remove("active");
if (link.getAttribute("href") === `#${currentSection}`) {
link.classList.add("active");
}
});
});
});
document.getElementById("year").textContent = new Date().getFullYear();
function disableDeveloper() {
document.addEventListener("contextmenu", (e) => e.preventDefault());
document.addEventListener("keydown", (e) => {
if (e.ctrlKey && e.shiftKey && (e.key === "I" || e.key === "J")) {
e.preventDefault();
}
if (e.key === "F12") {
e.preventDefault();
}
});
}
disableDeveloper();
});