1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-15 07:22:28 +02:00

Simplify code

Related commit:
- b779f1f7c9
This commit is contained in:
Raymond Hill 2020-12-13 12:14:37 -05:00
parent fd960e19e8
commit 1ff8132216
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -26,13 +26,9 @@
(( ) => {
if ( typeof vAPI !== 'object' ) { return; }
if ( vAPI.load3rdPartyCSS ) { return; }
vAPI.load3rdPartyCSS = true;
const links = document.querySelectorAll('link[rel="stylesheet"]');
if ( links.length === 0 ) { return; }
const toLoadMaybe = new Map(Array.from(links).map(a => [ a.href, a ]));
if ( vAPI.dynamicReloadToken === undefined ) {
vAPI.dynamicReloadToken = vAPI.randomToken();
}
for ( const sheet of Array.from(document.styleSheets) ) {
let loaded = false;
@ -41,10 +37,11 @@
} catch(ex) {
}
if ( loaded ) { continue; }
const link = toLoadMaybe.get(sheet.href);
if ( link === undefined ) { continue; }
toLoadMaybe.delete(sheet.href);
const link = sheet.ownerNode || null;
if ( link === null || link.localName !== 'link' ) { continue; }
if ( link.hasAttribute(vAPI.dynamicReloadToken) ) { continue; }
const clone = link.cloneNode(true);
clone.setAttribute(vAPI.dynamicReloadToken, '');
link.replaceWith(clone);
}
})();