forked from dasistdaniel/heiseminus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheiseminus.js
50 lines (43 loc) · 1.46 KB
/
heiseminus.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
class HeiseMinus {
constructor(config, imageTag) {
this.newLogo = imageTag
this.searches = config.searches
this.#hideHeisePlus()
}
#hideHeisePlus() {
Object.values(this.searches).forEach(search => {
const selection = this.#selectElements(search.startIdentifier)
selection.forEach(selectedElement => {
const endNode = this.#findEndNodeOf(selectedElement, search.endIdentifier)
if (endNode) {
switch (search.action) {
case "hide":
this.#hideElement(endNode)
break
case "replaceImg":
this.#replaceElement(endNode)
break
}
}
});
});
}
#selectElements(identifier) {
return document.querySelectorAll(identifier);
}
#findEndNodeOf(selectedElement, endIdentifier) {
if (selectedElement == null) {
return null
}
if (selectedElement.tagName === endIdentifier) {
return selectedElement
}
return this.#findEndNodeOf(selectedElement.parentNode, endIdentifier)
}
#hideElement(elementToHide) {
elementToHide.style.display = "none"
}
#replaceElement(elementToReplace) {
elementToReplace.parentNode.replaceChild(this.newLogo, elementToReplace)
}
}