Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
77 lines (57 loc) · 2.28 KB
/
Copy pathscript.js
File metadata and controls
77 lines (57 loc) · 2.28 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
70
71
72
73
74
75
76
77
const visits = trackVisits()
applyAnimationMultiplier(visits)
customiseLinkBehaviour()
detectPersonalMode()
function trackVisits() {
const visitCountStorageKey = "timesHomerPageVisited";
let visits = Number(localStorage.getItem(visitCountStorageKey)) || 0;
localStorage.setItem(visitCountStorageKey, ++visits);
console.log(`You've visited this site ${visits} times.`)
return visits
}
function applyAnimationMultiplier(visits) {
// Restrict this value between 1 and 8 (inclusive)
const visitCountCapped = Math.min(Math.max(visits, 1), 8);
const animationMultiplier = 1 - ((visitCountCapped - 1) * 0.1);
document.documentElement.style.setProperty("--animation-speed-multiplier", animationMultiplier);
}
function customiseLinkBehaviour() {
const anchorTags = document.getElementsByTagName("a");
for (const anchorTag of anchorTags) {
anchorTag.addEventListener("click", (e) => {
e.preventDefault();
const targetAnchorObject = e.currentTarget;
const href = targetAnchorObject.href;
const rel = targetAnchorObject.rel;
const relCsv = rel.split(" ").join(",");
targetAnchorObject.style.cursor = 'wait';
setTimeout(() => {
targetAnchorObject.style.cursor = '';
window.open(href, "_target", relCsv);
}, 1000);
})
}
}
function detectPersonalMode() {
if (window.location.hash === '#me') {
enablePersonalMode()
}
}
function enablePersonalMode() {
const highlightedElements = document.getElementsByClassName('highlighted')
// Delay before the highlighting animation (in seconds)
const delayBeforeHighlighting = 10
setTimeout(() => {
for (let index = 0; index < highlightedElements.length; index++) {
setTimeout(() => {
const element = highlightedElements[index]
element.style.cssText += 'background-color: white;'
setTimeout(() => {
element.style.cssText -= 'background-color: white;'
}, 3000);
}, index * 5000)
}
}, delayBeforeHighlighting * 1000)
const musicLink = document.getElementById('music-link')
musicLink.href = 'https://the-practice-page.vercel.app#me'
}