1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-08 12:57:57 +02:00

code review: cleaner user-stylesheets support as proposed in https://issues.adblockplus.org/ticket/5695

This commit is contained in:
gorhill 2017-09-16 10:55:28 -04:00
parent eceab1c23f
commit b1f04c79b0
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -47,22 +47,6 @@ var noopFunc = function(){};
/******************************************************************************/
if (
typeof browser === 'object' &&
browser !== null &&
browser.runtime instanceof Object &&
typeof browser.runtime.getBrowserInfo === 'function'
) {
browser.runtime.getBrowserInfo().then(function(info) {
vAPI.supportsUserStylesheets =
info.name === 'Firefox' &&
parseInt(info.version, 10) > 52;
});
}
/******************************************************************************/
vAPI.app = {
name: manifest.name,
version: manifest.version
@ -718,6 +702,13 @@ vAPI.messaging.onPortMessage = (function() {
var messaging = vAPI.messaging,
toAuxPending = {};
// https://issues.adblockplus.org/ticket/5695
// - Good idea, adopted: cleaner way to detect user-stylesheet support.
var supportsUserStylesheets =
chrome.extensionTypes instanceof Object &&
chrome.extensionTypes.CSSOrigin instanceof Object &&
'USER' in chrome.extensionTypes.CSSOrigin;
// Use a wrapper to avoid closure and to allow reuse.
var CallbackWrapper = function(port, request, timeout) {
this.callback = this.proxy.bind(this); // bind once
@ -831,7 +822,7 @@ vAPI.messaging.onPortMessage = (function() {
frameId: sender.frameId,
matchAboutBlank: true
};
if ( vAPI.supportsUserStylesheets === true ) {
if ( supportsUserStylesheets ) {
details.cssOrigin = 'user';
}
var fn;