From 1ff8132216082b4461bfaf8f0dad4910d8aa86a0 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Sun, 13 Dec 2020 12:14:37 -0500 Subject: [PATCH] Simplify code Related commit: - https://github.com/gorhill/uBlock/commit/b779f1f7c9deea32970b93e11a8d33ef7efe5db8 --- src/js/scriptlets/load-3p-css.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/js/scriptlets/load-3p-css.js b/src/js/scriptlets/load-3p-css.js index 1d0df772c..92f402d92 100644 --- a/src/js/scriptlets/load-3p-css.js +++ b/src/js/scriptlets/load-3p-css.js @@ -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); } })();