Skip to content

Instantly share code, notes, and snippets.

@vbuaraujo
Last active March 29, 2018 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vbuaraujo/c2ee48cd67ee0e8d7cdd7f451113a161 to your computer and use it in GitHub Desktop.
Save vbuaraujo/c2ee48cd67ee0e8d7cdd7f451113a161 to your computer and use it in GitHub Desktop.
Yet another attempt at getting rid of "position: fixed" toolbars
// ==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