mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 01:27:12 +02:00
fix #1952
This commit is contained in:
parent
0d7e326dce
commit
33234fdd8b
@ -319,15 +319,31 @@ var contentObserver = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sandbox.injectScript = function(script) {
|
sandbox.injectScript = function(script) {
|
||||||
var svc = Services;
|
let svc = Services;
|
||||||
// Sandbox appears void.
|
// Sandbox appears void.
|
||||||
// I've seen this happens, need to investigate why.
|
// I've seen this happens, need to investigate why.
|
||||||
if ( svc === undefined ) {
|
if ( svc === undefined ) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
svc.scriptloader.loadSubScript(script, sandbox);
|
svc.scriptloader.loadSubScript(script, sandbox);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
sandbox.injectCSS = function(sheetURI) {
|
||||||
|
try {
|
||||||
|
let wu = win.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIDOMWindowUtils);
|
||||||
|
wu.loadSheetUsingURIString(sheetURI, wu.USER_SHEET);
|
||||||
|
} catch(ex) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
sandbox.removeCSS = function(sheetURI) {
|
||||||
|
try {
|
||||||
|
let wu = win.QueryInterface(Ci.nsIInterfaceRequestor)
|
||||||
|
.getInterface(Ci.nsIDOMWindowUtils);
|
||||||
|
wu.removeSheetUsingURIString(sheetURI, wu.USER_SHEET);
|
||||||
|
} catch (ex) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// The goal is to have content scripts removed from web pages. This
|
// The goal is to have content scripts removed from web pages. This
|
||||||
// helps remove traces of uBlock from memory when disabling/removing
|
// helps remove traces of uBlock from memory when disabling/removing
|
||||||
// the addon.
|
// the addon.
|
||||||
@ -337,8 +353,10 @@ var contentObserver = {
|
|||||||
sandbox.outerShutdown = function() {
|
sandbox.outerShutdown = function() {
|
||||||
sandbox.removeMessageListener();
|
sandbox.removeMessageListener();
|
||||||
sandbox.addMessageListener =
|
sandbox.addMessageListener =
|
||||||
|
sandbox.injectCSS =
|
||||||
sandbox.injectScript =
|
sandbox.injectScript =
|
||||||
sandbox.outerShutdown =
|
sandbox.outerShutdown =
|
||||||
|
sandbox.removeCSS =
|
||||||
sandbox.removeMessageListener =
|
sandbox.removeMessageListener =
|
||||||
sandbox.rpc =
|
sandbox.rpc =
|
||||||
sandbox.sendAsyncMessage = function(){};
|
sandbox.sendAsyncMessage = function(){};
|
||||||
|
@ -437,6 +437,46 @@ vAPI.messaging.start();
|
|||||||
|
|
||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
|
vAPI.userCSS = (function() {
|
||||||
|
if ( !self.injectCSS ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var injectCSS = self.injectCSS,
|
||||||
|
removeCSS = self.removeCSS,
|
||||||
|
userCSS = '',
|
||||||
|
sheetURI = '';
|
||||||
|
var load = function() {
|
||||||
|
if ( userCSS === '' || sheetURI !== '' ) { return; }
|
||||||
|
sheetURI = 'data:text/css;charset=utf-8,' + encodeURIComponent(userCSS);
|
||||||
|
injectCSS(sheetURI);
|
||||||
|
};
|
||||||
|
var unload = function() {
|
||||||
|
if ( sheetURI === '' ) { return; }
|
||||||
|
removeCSS(sheetURI);
|
||||||
|
sheetURI = '';
|
||||||
|
};
|
||||||
|
var add = function(cssText) {
|
||||||
|
if ( cssText === '' ) { return; }
|
||||||
|
if ( userCSS !== '' ) { userCSS += '\n'; }
|
||||||
|
userCSS += cssText;
|
||||||
|
unload();
|
||||||
|
load();
|
||||||
|
};
|
||||||
|
var toggle = function(state) {
|
||||||
|
if ( userCSS === '' ) { return; }
|
||||||
|
if ( state === undefined ) {
|
||||||
|
state = sheetURI === '';
|
||||||
|
}
|
||||||
|
return state ? load() : unload();
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
add: add,
|
||||||
|
toggle: toggle
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
/******************************************************************************/
|
||||||
|
|
||||||
// No need to have vAPI client linger around after shutdown if
|
// No need to have vAPI client linger around after shutdown if
|
||||||
// we are not a top window (because element picker can still
|
// we are not a top window (because element picker can still
|
||||||
// be injected in top window).
|
// be injected in top window).
|
||||||
|
@ -163,7 +163,8 @@ var allExceptions = Object.create(null),
|
|||||||
allSelectors = Object.create(null),
|
allSelectors = Object.create(null),
|
||||||
commitTimer = null,
|
commitTimer = null,
|
||||||
stagedNodes = [],
|
stagedNodes = [],
|
||||||
matchesProp = vAPI.matchesProp;
|
matchesProp = vAPI.matchesProp,
|
||||||
|
userCSS = vAPI.userCSS;
|
||||||
|
|
||||||
// Complex selectors, due to their nature may need to be "de-committed". A
|
// Complex selectors, due to their nature may need to be "de-committed". A
|
||||||
// Set() is used to implement this functionality.
|
// Set() is used to implement this functionality.
|
||||||
@ -428,6 +429,9 @@ var domFilterer = {
|
|||||||
document.head.appendChild(styleTag);
|
document.head.appendChild(styleTag);
|
||||||
}
|
}
|
||||||
this.styleTags.push(styleTag);
|
this.styleTags.push(styleTag);
|
||||||
|
if ( userCSS ) {
|
||||||
|
userCSS.add(styleText);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simple selectors: incremental.
|
// Simple selectors: incremental.
|
||||||
@ -580,10 +584,16 @@ var domFilterer = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
toggleOff: function() {
|
toggleOff: function() {
|
||||||
|
if ( userCSS ) {
|
||||||
|
userCSS.toggle(false);
|
||||||
|
}
|
||||||
this.enabled = false;
|
this.enabled = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
toggleOn: function() {
|
toggleOn: function() {
|
||||||
|
if ( userCSS ) {
|
||||||
|
userCSS.toggle(true);
|
||||||
|
}
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user