-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
67 lines (58 loc) · 1.83 KB
/
Copy pathscripts.js
File metadata and controls
67 lines (58 loc) · 1.83 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
//TEMA
(() => {
const root = document.documentElement;
const stikaloTeme = document.getElementById("stikaloTeme");
// Ob nalaganju strani preveri, ali je uporabnik že izbral temo
const tema = localStorage.getItem("tema");
if (tema === "light") {
root.classList.add("light");
}
// Ob kliku preklopi temo in shrani izbiro
if (stikaloTeme) {
stikaloTeme.addEventListener("click", function(event) {
event.preventDefault();
root.classList.toggle("light");
// Shrani novo stanje
if (root.classList.contains("light")) {
localStorage.setItem("tema", "light");
} else {
localStorage.setItem("tema", "dark");
}
});
}
})();
document.querySelectorAll('h1, h2, h3, h4, h5, h6').forEach(heading => {
if (heading.id) {
heading.style.cursor = 'pointer';
heading.addEventListener('click', () => {
window.location.hash = heading.id;
});
}
});
document.addEventListener("keydown", function(event) {
// Ne sproži bližnjic, če uporabnik tipka v vnosno polje
const urejevalni_elementi = ['INPUT', 'TEXTAREA', 'SELECT'];
if (urejevalni_elementi.includes(event.target.tagName) || event.target.isContentEditable) {
return;
}
// Preveri, da je Shift pritisnjen, Ctrl/Alt/Meta pa ne
if (!event.shiftKey || event.ctrlKey || event.altKey || event.metaKey) return;
const key = event.key.toUpperCase(); // velike črke, ker Shift običajno pomeni velike
switch (key) {
case 'B': {
const stikaloTeme = document.getElementById("stikaloTeme");
if (stikaloTeme) stikaloTeme.click();
break;
}
case 'M': {
const linkMD = document.getElementById("linkMD");
if (linkMD) linkMD.click();
break;
}
case 'D': {
const domov = document.getElementById("domov");
if (domov) domov.click();
break;
}
}
});