-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpluginVM.js
More file actions
91 lines (70 loc) · 2.39 KB
/
pluginVM.js
File metadata and controls
91 lines (70 loc) · 2.39 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
function PluginVM() {
this.onInit = function() {
const button = document.createElement("button"),
div = document.createElement("div");
button.innerHTML = "Executar plugin";
button.addEventListener("click", PluginVM.makeChanges);
button.className += "btn btn-danger";
button.setAttribute("id", "buttonPluginVM");
button.style.position = "fixed";
button.style.zIndex = "2";
button.style.bottom = "10px";
button.style.fontFamily = "Arial";
div.style.width = "100%";
div.style.display = "flex";
div.style.justifyContent = "center";
document.body.appendChild(div);
div.appendChild(button);
};
this.makeChanges = function() {
var aux,
temp,
filterFunction,
filteredTree,
textNodes = [];
filterFunction = function(node) {
return (node.nodeType === 3 &&
node.textContent.trim() !== "" &&
node.parentNode.id != "buttonPluginVM") ||
node.tagName == "IMG"
? NodeFilter.FILTER_ACCEPT
: NodeFilter.FILTER_SKIP;
};
temp = /MSIE|Trident/.test(navigator.userAgent)
? filterFunction
: {
acceptNode: filterFunction
};
filteredTree = document.createTreeWalker(
document.body,
NodeFilter.SHOW_ALL,
temp,
false
);
while ((aux = filteredTree.nextNode())) textNodes[textNodes.length] = aux;
for (var i = textNodes.length - 1; i >= 0; i--) {
const element = textNodes[i];
setFontSizeAndFamily(element.parentNode);
if (element.tagName === "A") setHighlightsInLinks(element.parentNode);
if (element.tagName == "IMG" && !element.getAttribute("alt"))
setHighlightsInImages(element);
}
};
function setFontSizeAndFamily(element) {
element.style.setProperty(
"font-size",
parseFloat(getComputedStyle(element).fontSize) * 1.2 + "px"
);
element.style.setProperty("font-family", "Arial");
}
function setHighlightsInLinks(element) {
element.style.setProperty("background-color", "#FFE599");
element.style.setProperty("text-decoration", "underline");
element.style.setProperty("font-style", "italic");
}
function setHighlightsInImages(element) {
element.style.setProperty("border", "5px dotted red");
}
}
var PluginVM = new PluginVM();
PluginVM.onInit();