Skip to content

Instantly share code, notes, and snippets.

@romainmenke
Last active December 13, 2023 13:51
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 romainmenke/03a8dac1911d1cdcd07abe99bde9e764 to your computer and use it in GitHub Desktop.
Save romainmenke/03a8dac1911d1cdcd07abe99bde9e764 to your computer and use it in GitHub Desktop.
;(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 });
;(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