Skip to content

Instantly share code, notes, and snippets.

@gerardpaapu
Forked from lionicsheriff/dft-position-unfixed.js
Created September 17, 2012 21:21
Show Gist options
  • Save gerardpaapu/3739883 to your computer and use it in GitHub Desktop.
Save gerardpaapu/3739883 to your computer and use it in GitHub Desktop.
unfix position
// ==UserScript==
// @id dft-postion-unfixed
// @name Remove position fixed
// @version 1.0
// @namespace dft
// @author Matthew Goodall
// @description Changes position:fixed to position:relative
// @include *
// @run-at document-idle
// ==/UserScript==
function replace(old, _new) {
var parent = old.parentNode;
parent.insertBefore(old, _new);
parent.removeChild(old);
return _new;
}
function cleanStyleSheet(sheet){
if (!sheet.href || sheet.href.split('/')[2] === window.location.hostname){
// Same origin stylesheets can be modified
var rules = sheet.cssRules;
if (!rules){
return;
}
for (var r = 0; r < rules.length; r++){
var rule = rules[r];
console.log(rule);
if (rule.style && rule.style.position === 'fixed'){
rules[r].style.position = 'relative';
}
}
} else {
// The stylesheet needs to be retrieved and put into the document directly
GM_xmlhttpRequest({
method:'GET',
url:sheet.href,
onload:function(resp){
// place the stylesheet at the end of the document
// don't need to delete the existing one since this will be applied over it
createStyleSheet(resp.responseText);
// and finally clean it
cleanStyleSheet(document.styleSheets[document.styleSheets.length - 1]);
}
});
}
}
function createStyleSheet(content){
var sheet = document.createElement('style');
sheet.setAttribute('type','text/css');
sheet.textContent=content;
return document.documentElement.appendChild(sheet);
}
// START
var sheets = document.styleSheets;
for (var s = 0; s < sheets.length; s++){
var sheet = sheets[s];
console.log(sheet);
if (sheet){
cleanStyleSheet(sheet);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment