-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunfix-all-the-toolbars.js
96 lines (81 loc) · 2.29 KB
/
unfix-all-the-toolbars.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
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
92
93
94
95
96
// ==UserScript==
// @name unfix-all-the-toolbars
// @description Removes "position: fixed" style from elements, unfixing "toolbars" and the such.
// @namespace https://t.me/beton_kruglosu_totchno
// @include *
// @version 2
// @grant none
// ==/UserScript==
window.fixed_items = [];
var searched = false;
var windowHeightSearched = false;
var counter = 0;
window.badPosition=['static','fixed','sticky','absolute']
function traverse(node){
console.log('traversing')
var style = window.getComputedStyle(node);
var innHeightPx = window.innerHeight*window.devicePixelRatio;
var innHeight = window.innerHeight;
if(style.display!='none' && style.visibility!='hidden')
console.log(node)
if( (! window.badPosition.includes(style.position)) && parseInt(style.height) < innHeight)
return;
if(
style.display != 'none' &&
style.visibility != "hidden" &&
style.visibility != "collapse" &&
(
parseInt(style.top)+parseInt(style.height) < innHeight/3
|| parseInt(style.top)> innHeight*2/3
|| (style.top === "auto" && parseInt(style.bottom)< innHeight/3)
)&&
parseInt(style.height)<innHeight/3
){
window.fixed_items.push([node,style.visibility,style.display]);
node.style.visibility = "collapse";
}
var children = Array.from(node.children);
children.forEach(traverse)
}
function unfixAll() {
//console.log("======= unfix");
if(!searched){
traverse(document.body);
searched=true;
} else {
window.fixed_items.forEach(
function(el) {
el[0].style.visibility = "collapse";
}
)
}
}
function fixBack()
{
window.fixed_items.forEach(
function(el) {
el[0].style.visibility = el[1];
}
)
}
function onScroll()
{
if (window.scrollY > 0)
{
if (window.scrollY > window.innerHeight+700 && windowHeightSearched==false)
{
searched=false;
windowHeightSearched=true;
}
unfixAll();
}
else
{
fixBack();
window.fixed_items = [];
searched = false;
windowHeightSearched = false;
}
}
window.addEventListener("scroll", onScroll);
window.unfixAll=unfixAll;