Last active
December 13, 2023 13:51
-
-
Save romainmenke/03a8dac1911d1cdcd07abe99bde9e764 to your computer and use it in GitHub Desktop.
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
;(new MutationObserver((mutationList, observer) => { | |
if (!mutationList.length) return; | |
for (var i = 0; i < mutationList.length; i++) { | |
var mutation = mutationList[i]; | |
if ( | |
!('addedNodes' in mutation) || | |
!mutation.addedNodes.length | |
) continue; | |
for (var j = 0; j < mutation.addedNodes.length; j++) { | |
var node = mutation.addedNodes[j]; | |
if ( | |
!('matches' in node) || | |
!node.matches('link[rel="stylesheet"][condition]') || | |
('condition' in node) | |
) continue; | |
node.href = 'data:text/css;base64,' + btoa('@import "' + (new URL(node.href, document.baseURI)).href + '" ' + node.getAttribute('condition') + ';'); | |
node.removeAttribute('condition'); | |
} | |
} | |
})).observe(document, { attributes: false, childList: true, subtree: true }); |
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
;(new MutationObserver((mutationList, observer) => { | |
if (!mutationList.length) return; | |
for (var i = 0; i < mutationList.length; i++) { | |
var mutation = mutationList[i]; | |
if ( | |
!('addedNodes' in mutation) || | |
!mutation.addedNodes.length | |
) continue; | |
for (var j = 0; j < mutation.addedNodes.length; j++) { | |
var node = mutation.addedNodes[j]; | |
if ( | |
!('matches' in node) || | |
!node.matches('link[rel="stylesheet"]') || | |
!node.media || | |
window.matchMedia(node.media).matches || | |
node.href.startsWith('data:') | |
) continue; | |
node.href = 'data:text/css;base64,' + btoa('@import "' + (new URL(node.href, document.baseURI)).href + '" ' + node.media + ';'); | |
node.media = 'all'; | |
} | |
} | |
})).observe(document, { attributes: false, childList: true, subtree: true }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment