-
Notifications
You must be signed in to change notification settings - Fork 1
/
Hide webpage floating elements (alt ver).js
42 lines (40 loc) · 1.54 KB
/
Hide webpage floating elements (alt ver).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
/*
This alternate version works by appending a CSS rule to "document.head",
then appends the given class name to each floating element.
Overcomes the problem of child nodes having "visibility:visible", faced by the original version.
*/
javascript:
if (typeof aoeuToggle != "number"){
/* declare global variables for toggle functionality */
var aoeuToggle;
var aoeuFloats = [];
/* append CSS rule */
(function(){
var aoeuStyle = document.createElement("style");
aoeuStyle.type = "text/css";
aoeuStyle.innerHTML = ".aoeuHideFloater, .aoeuHideFloater * { visibility: hidden !important; }";
document.head.appendChild(aoeuStyle);
})();
}
(function(){
if (aoeuToggle != 1){
/* generate array of floating elements to be hidden */
var aoeuElems = document.body.getElementsByTagName("*");
aoeuFloats=[]; /*reset for each toggle on*/
for (var i=0;i<aoeuElems.length;i++) {
var positionValue = window.getComputedStyle(aoeuElems[i]).getPropertyValue("position");
if ( ["fixed","sticky"].includes(positionValue) ) {
aoeuFloats[aoeuFloats.length]=aoeuElems[i]; /*store the relevant element, for toggle purposes*/
aoeuElems[i].classList.add("aoeuHideFloater"); /*then hide it*/
}
}
/*alert(aoeuFloats.length);*/
aoeuToggle=1;
} else{
/* un-hide previously hidden elements */
for(var i=0; i<aoeuFloats.length; i++){
aoeuFloats[i].classList.remove("aoeuHideFloater");
}
aoeuToggle=0;
}
})();