code review: further tuning filter list directives

This commit is contained in:
Raymond Hill 2018-04-11 06:34:13 -04:00
parent 53652a3e32
commit c34326cf4e
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
2 changed files with 55 additions and 46 deletions

View file

@ -43,59 +43,70 @@ vAPI.webextFlavor = {
(function() { (function() {
var ua = navigator.userAgent, var ua = navigator.userAgent,
match, reEx, flavor = vAPI.webextFlavor,
flavor = vAPI.webextFlavor; soup = flavor.soup;
var dispatch = function() { var dispatch = function() {
window.dispatchEvent(new CustomEvent('webextFlavor')); window.dispatchEvent(new CustomEvent('webextFlavor'));
}; };
// Order of tests is important! // This is always true.
soup.add('ublock');
if ( /\bMobile\b/.test(ua) ) { if ( /\bMobile\b/.test(ua) ) {
flavor.soup.add('mobile'); soup.add('mobile');
} }
// Asynchronous // Asynchronous
if ( var async = self.browser instanceof Object &&
self.browser instanceof Object && typeof self.browser.runtime.getBrowserInfo === 'function';
typeof self.browser.runtime.getBrowserInfo === 'function' if ( async ) {
) {
self.browser.runtime.getBrowserInfo().then(function(info) { self.browser.runtime.getBrowserInfo().then(function(info) {
flavor.major = parseInt(info.version, 10) || 0; flavor.major = parseInt(info.version, 10) || 0;
flavor.soup.add(info.vendor.toLowerCase()) soup.add(info.vendor.toLowerCase())
.add(info.name.toLowerCase()); .add(info.name.toLowerCase());
if ( flavor.major >= 53 ) { soup.add('user_stylesheet'); }
if ( flavor.major >= 57 ) { soup.add('html_filtering'); }
dispatch(); dispatch();
}); });
match = /Firefox\/([\d.]+)/.exec(ua);
if ( match !== null ) {
flavor.major = parseInt(match[1], 10) || 0;
flavor.soup.add('mozilla').add('firefox');
}
return;
} }
// Synchronous // Synchronous
/* Don't starve potential listeners: */ vAPI.setTimeout(dispatch, 97); var match = /Firefox\/([\d.]+)/.exec(ua);
if ( match !== null ) {
flavor.major = parseInt(match[1], 10) || 0;
soup.add('mozilla')
.add('firefox');
if ( flavor.major >= 53 ) { soup.add('user_stylesheet'); }
if ( flavor.major >= 57 ) { soup.add('html_filtering'); }
} else {
match = /OPR\/([\d.]+)/.exec(ua);
if ( match !== null ) {
var reEx = /Chrom(?:e|ium)\/([\d.]+)/;
if ( reEx.test(ua) ) { match = reEx.exec(ua); }
flavor.major = parseInt(match[1], 10) || 0;
soup.add('opera').add('chromium');
} else {
match = /Chromium\/([\d.]+)/.exec(ua);
if ( match !== null ) {
flavor.major = parseInt(match[1], 10) || 0;
soup.add('chromium');
} else {
match = /Chrome\/([\d.]+)/.exec(ua);
if ( match !== null ) {
flavor.major = parseInt(match[1], 10) || 0;
soup.add('google').add('chromium');
}
}
}
// https://github.com/gorhill/uBlock/issues/3588
if ( soup.has('chromium') && flavor.major >= 67 ) {
soup.add('user_stylesheet');
}
}
match = /OPR\/([\d.]+)/.exec(ua); // Don't starve potential listeners
if ( match !== null ) { if ( !async ) {
reEx = /Chrom(?:e|ium)\/([\d.]+)/; vAPI.setTimeout(dispatch, 97);
if ( reEx.test(ua) ) { match = reEx.exec(ua); }
flavor.major = parseInt(match[1], 10) || 0;
flavor.soup.add('opera').add('chromium');
return;
}
match = /Chromium\/([\d.]+)/.exec(ua);
if ( match !== null ) {
flavor.major = parseInt(match[1], 10) || 0;
flavor.soup.add('chromium');
return;
}
match = /Chrome\/([\d.]+)/.exec(ua);
if ( match !== null ) {
flavor.major = parseInt(match[1], 10) || 0;
flavor.soup.add('google').add('chromium');
return;
} }
})(); })();

View file

@ -912,16 +912,14 @@
}; };
µBlock.processDirectives.tokens = new Map([ µBlock.processDirectives.tokens = new Map([
[ 'ext_chromium', 'chromium' ], [ 'ext_ublock', 'ublock' ],
[ 'ext_edge', 'edge' ], [ 'env_chromium', 'chromium' ],
[ 'ext_firefox', 'firefox' ], [ 'env_edge', 'edge' ],
[ 'ext_mobile', 'mobile' ], [ 'env_firefox', 'firefox' ],
[ 'ext_safari', 'safari' ], [ 'env_mobile', 'mobile' ],
[ 'adguard_ext_chromium', 'chromium' ], [ 'env_safari', 'safari' ],
[ 'adguard_ext_edge', 'edge' ], [ 'cap_html_filtering', 'html_filtering' ],
[ 'adguard_ext_firefox', 'firefox' ], [ 'cap_user_stylesheet', 'user_stylesheet' ]
[ 'adguard_ext_mobile', 'mobile' ],
[ 'adguard_ext_safari', 'safari' ],
]); ]);
/******************************************************************************/ /******************************************************************************/