Skip to content

Commit

Permalink
code review: further tuning filter list directives
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhill committed Apr 11, 2018
1 parent 53652a3 commit c34326c
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 44 deletions.
79 changes: 45 additions & 34 deletions platform/chromium/vapi-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

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);
var match = /Firefox\/([\d.]+)/.exec(ua);
if ( match !== null ) {
flavor.major = parseInt(match[1], 10) || 0;
flavor.soup.add('chromium');
return;
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 = /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);
}
})();

Expand Down
18 changes: 8 additions & 10 deletions src/js/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]
]);

/******************************************************************************/
Expand Down

0 comments on commit c34326c

Please sign in to comment.