mirror of
https://github.com/gorhill/uBlock.git
synced 2026-03-11 09:04:36 +00:00
This commit is contained in:
parent
8c424c15b2
commit
91de400a64
1 changed files with 22 additions and 16 deletions
|
|
@ -38,19 +38,25 @@ vAPI.userStylesheet = {
|
||||||
disabled: false,
|
disabled: false,
|
||||||
apply: function() {
|
apply: function() {
|
||||||
},
|
},
|
||||||
|
inject: function() {
|
||||||
|
this.style = document.createElement('style');
|
||||||
|
this.style.disabled = this.disabled;
|
||||||
|
var parent = document.head || document.documentElement;
|
||||||
|
if ( parent === null ) { return; }
|
||||||
|
parent.appendChild(this.style);
|
||||||
|
var observer = new MutationObserver(function() {
|
||||||
|
if ( this.style === null ) { return; }
|
||||||
|
if ( this.style.sheet !== null ) { return; }
|
||||||
|
parent.appendChild(this.style);
|
||||||
|
}.bind(this));
|
||||||
|
observer.observe(parent, { childList: true });
|
||||||
|
},
|
||||||
add: function(cssText) {
|
add: function(cssText) {
|
||||||
if ( cssText === '' || this.css.has(cssText) ) { return; }
|
if ( cssText === '' || this.css.has(cssText) ) { return; }
|
||||||
if ( this.style === null ) {
|
if ( this.style === null ) { this.inject(); }
|
||||||
this.style = document.createElement('style');
|
var sheet = this.style.sheet;
|
||||||
this.style.disabled = this.disabled;
|
|
||||||
var parent = document.head || document.documentElement;
|
|
||||||
if ( parent !== null ) {
|
|
||||||
parent.appendChild(this.style);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var sheet = this.style.sheet,
|
|
||||||
i = sheet.cssRules.length;
|
|
||||||
if ( !sheet ) { return; }
|
if ( !sheet ) { return; }
|
||||||
|
var i = sheet.cssRules.length;
|
||||||
sheet.insertRule(cssText, i);
|
sheet.insertRule(cssText, i);
|
||||||
this.css.set(cssText, sheet.cssRules[i]);
|
this.css.set(cssText, sheet.cssRules[i]);
|
||||||
},
|
},
|
||||||
|
|
@ -67,12 +73,12 @@ vAPI.userStylesheet = {
|
||||||
this.style.sheet.deleteRule(i);
|
this.style.sheet.deleteRule(i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if ( rules.length === 0 ) {
|
if ( rules.length !== 0 ) { return; }
|
||||||
var parent = this.style.parentNode;
|
var style = this.style;
|
||||||
if ( parent !== null ) {
|
this.style = null;
|
||||||
parent.removeChild(this.style);
|
var parent = style.parentNode;
|
||||||
}
|
if ( parent !== null ) {
|
||||||
this.style = null;
|
parent.removeChild(style);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
toggle: function(state) {
|
toggle: function(state) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue