From 88ce17561f0f9cb5b67370ab422c6169d1b322c7 Mon Sep 17 00:00:00 2001 From: gorhill Date: Tue, 5 Dec 2017 14:37:12 -0500 Subject: [PATCH] fix #3321: make uBO the bigger person and walk away from a pointless fight --- platform/chromium/vapi-usercss.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/platform/chromium/vapi-usercss.js b/platform/chromium/vapi-usercss.js index 9d3cf8e88..df050cc97 100644 --- a/platform/chromium/vapi-usercss.js +++ b/platform/chromium/vapi-usercss.js @@ -34,6 +34,7 @@ if ( typeof vAPI === 'object' ) { // >>>>>>>> start of HUGE-IF-BLOCK vAPI.userStylesheet = { style: null, + styleFixCount: 0, css: new Map(), disabled: false, apply: function() { @@ -47,7 +48,12 @@ vAPI.userStylesheet = { var observer = new MutationObserver(function() { if ( this.style === null ) { return; } if ( this.style.sheet !== null ) { return; } - parent.appendChild(this.style); + this.styleFixCount += 1; + if ( this.styleFixCount < 32 ) { + parent.appendChild(this.style); + } else { + observer.disconnect(); + } }.bind(this)); observer.observe(parent, { childList: true }); }, @@ -66,11 +72,13 @@ vAPI.userStylesheet = { if ( cssRule === undefined ) { return; } this.css.delete(cssText); if ( this.style === null ) { return; } - var rules = this.style.sheet.cssRules, + var sheet = this.style.sheet; + if ( !sheet ) { return; } + var rules = sheet.cssRules, i = rules.length; while ( i-- ) { if ( rules[i] !== cssRule ) { continue; } - this.style.sheet.deleteRule(i); + sheet.deleteRule(i); break; } if ( rules.length !== 0 ) { return; }