1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-04 08:37:11 +02:00

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() {
var ua = navigator.userAgent,
match, reEx,
flavor = vAPI.webextFlavor;
flavor = vAPI.webextFlavor,
soup = flavor.soup;
var dispatch = function() {
window.dispatchEvent(new CustomEvent('webextFlavor'));
};
// Order of tests is important!
// This is always true.
soup.add('ublock');
if ( /\bMobile\b/.test(ua) ) {
flavor.soup.add('mobile');
soup.add('mobile');
}
// Asynchronous
if (
self.browser instanceof Object &&
typeof self.browser.runtime.getBrowserInfo === 'function'
) {
var async = self.browser instanceof Object &&
typeof self.browser.runtime.getBrowserInfo === 'function';
if ( async ) {
self.browser.runtime.getBrowserInfo().then(function(info) {
flavor.major = parseInt(info.version, 10) || 0;
flavor.soup.add(info.vendor.toLowerCase())
.add(info.name.toLowerCase());
soup.add(info.vendor.toLowerCase())
.add(info.name.toLowerCase());
if ( flavor.major >= 53 ) { soup.add('user_stylesheet'); }
if ( flavor.major >= 57 ) { soup.add('html_filtering'); }
dispatch();
});
match = /Firefox\/([\d.]+)/.exec(ua);
if ( match !== null ) {
flavor.major = parseInt(match[1], 10) || 0;
flavor.soup.add('mozilla').add('firefox');
}
return;
}
// 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);
if ( match !== null ) {
reEx = /Chrom(?:e|ium)\/([\d.]+)/;
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;
// Don't starve potential listeners
if ( !async ) {
vAPI.setTimeout(dispatch, 97);
}
})();

View File

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