-
Notifications
You must be signed in to change notification settings - Fork 0
/
link.js
38 lines (32 loc) · 1.15 KB
/
link.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
let isLinkHighlighted = false;
const highlightClassNameForLinks = "link-highlight-tekvision";
const highlightStyle = "border: 1px solid red;";
export const linkHighlightInit = () => {
// Create and append the style element for the highlight class
const styleElementWithHighlightClass = document.createElement("style");
styleElementWithHighlightClass.innerHTML = `.${highlightClassNameForLinks} { ${highlightStyle} !important; }`;
document.head.appendChild(styleElementWithHighlightClass);
};
const highlightLinks = () => {
const elements = document.querySelectorAll('a[href]');
if (elements.length > 0) {
elements.forEach(element => element.classList.add(highlightClassNameForLinks));
}
}
const unhighlightLinks = () => {
const elements = document.querySelectorAll('a[href]');
if (elements.length > 0) {
elements.forEach(element => element.classList.remove(highlightClassNameForLinks));
}
}
// Function to toggle heading visibility
export const toggleLinks = () => {
if (isLinkHighlighted) {
unhighlightLinks ();
alert("Links unhighlighted.");
} else {
highlightLinks ();
alert("Links highlighted.");
}
isLinkHighlighted = !isLinkHighlighted;
};