Last active
March 29, 2018 02:45
-
-
Save vbuaraujo/c2ee48cd67ee0e8d7cdd7f451113a161 to your computer and use it in GitHub Desktop.
Yet another attempt at getting rid of "position: fixed" toolbars
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Unfix all toolbars! | |
// @version 1 | |
// @grant none | |
// ==/UserScript== | |
function unfix(el) { | |
if (["fixed", "sticky"].indexOf(window.getComputedStyle(el).position) >= 0) { | |
if (el.offsetWidth >= document.documentElement.clientWidth) { | |
console.log("Unfix element:", el); | |
el.style.setProperty('position', 'static', 'important'); | |
} | |
} | |
}; | |
(function() { | |
// Unfix all nodes. | |
window.addEventListener("load", function(event) { | |
Array.forEach(document.querySelectorAll("*"), unfix); | |
}); | |
// Keep track of new nodes. [TOO SLOW! Some sites mutate elements every time you scroll :(] | |
/*var observer = new MutationObserver(function(mutations, observer) { | |
Array.forEach(mutations, function(mutation) { | |
unfix(mutation.target) | |
}); | |
}); | |
observer.observe(document.body, { | |
childList: true, | |
subtree: true, | |
attributes: true, | |
//attributeFilter: ['class', 'style'], | |
});*/ | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment