Skip to content

Commit c34326c

Browse files
committed
code review: further tuning filter list directives
1 parent 53652a3 commit c34326c

2 files changed

Lines changed: 53 additions & 44 deletions

File tree

platform/chromium/vapi-common.js

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -43,59 +43,70 @@ vAPI.webextFlavor = {
4343

4444
(function() {
4545
var ua = navigator.userAgent,
46-
match, reEx,
47-
flavor = vAPI.webextFlavor;
46+
flavor = vAPI.webextFlavor,
47+
soup = flavor.soup;
4848
var dispatch = function() {
4949
window.dispatchEvent(new CustomEvent('webextFlavor'));
5050
};
5151

52-
// Order of tests is important!
52+
// This is always true.
53+
soup.add('ublock');
5354

5455
if ( /\bMobile\b/.test(ua) ) {
55-
flavor.soup.add('mobile');
56+
soup.add('mobile');
5657
}
5758

5859
// Asynchronous
59-
if (
60-
self.browser instanceof Object &&
61-
typeof self.browser.runtime.getBrowserInfo === 'function'
62-
) {
60+
var async = self.browser instanceof Object &&
61+
typeof self.browser.runtime.getBrowserInfo === 'function';
62+
if ( async ) {
6363
self.browser.runtime.getBrowserInfo().then(function(info) {
6464
flavor.major = parseInt(info.version, 10) || 0;
65-
flavor.soup.add(info.vendor.toLowerCase())
66-
.add(info.name.toLowerCase());
65+
soup.add(info.vendor.toLowerCase())
66+
.add(info.name.toLowerCase());
67+
if ( flavor.major >= 53 ) { soup.add('user_stylesheet'); }
68+
if ( flavor.major >= 57 ) { soup.add('html_filtering'); }
6769
dispatch();
6870
});
69-
match = /Firefox\/([\d.]+)/.exec(ua);
70-
if ( match !== null ) {
71-
flavor.major = parseInt(match[1], 10) || 0;
72-
flavor.soup.add('mozilla').add('firefox');
73-
}
74-
return;
7571
}
7672

7773
// Synchronous
78-
/* Don't starve potential listeners: */ vAPI.setTimeout(dispatch, 97);
79-
80-
match = /OPR\/([\d.]+)/.exec(ua);
81-
if ( match !== null ) {
82-
reEx = /Chrom(?:e|ium)\/([\d.]+)/;
83-
if ( reEx.test(ua) ) { match = reEx.exec(ua); }
84-
flavor.major = parseInt(match[1], 10) || 0;
85-
flavor.soup.add('opera').add('chromium');
86-
return;
87-
}
88-
match = /Chromium\/([\d.]+)/.exec(ua);
74+
var match = /Firefox\/([\d.]+)/.exec(ua);
8975
if ( match !== null ) {
9076
flavor.major = parseInt(match[1], 10) || 0;
91-
flavor.soup.add('chromium');
92-
return;
77+
soup.add('mozilla')
78+
.add('firefox');
79+
if ( flavor.major >= 53 ) { soup.add('user_stylesheet'); }
80+
if ( flavor.major >= 57 ) { soup.add('html_filtering'); }
81+
} else {
82+
match = /OPR\/([\d.]+)/.exec(ua);
83+
if ( match !== null ) {
84+
var reEx = /Chrom(?:e|ium)\/([\d.]+)/;
85+
if ( reEx.test(ua) ) { match = reEx.exec(ua); }
86+
flavor.major = parseInt(match[1], 10) || 0;
87+
soup.add('opera').add('chromium');
88+
} else {
89+
match = /Chromium\/([\d.]+)/.exec(ua);
90+
if ( match !== null ) {
91+
flavor.major = parseInt(match[1], 10) || 0;
92+
soup.add('chromium');
93+
} else {
94+
match = /Chrome\/([\d.]+)/.exec(ua);
95+
if ( match !== null ) {
96+
flavor.major = parseInt(match[1], 10) || 0;
97+
soup.add('google').add('chromium');
98+
}
99+
}
100+
}
101+
// https://github.com/gorhill/uBlock/issues/3588
102+
if ( soup.has('chromium') && flavor.major >= 67 ) {
103+
soup.add('user_stylesheet');
104+
}
93105
}
94-
match = /Chrome\/([\d.]+)/.exec(ua);
95-
if ( match !== null ) {
96-
flavor.major = parseInt(match[1], 10) || 0;
97-
flavor.soup.add('google').add('chromium');
98-
return;
106+
107+
// Don't starve potential listeners
108+
if ( !async ) {
109+
vAPI.setTimeout(dispatch, 97);
99110
}
100111
})();
101112

src/js/storage.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -912,16 +912,14 @@
912912
};
913913

914914
µBlock.processDirectives.tokens = new Map([
915-
[ 'ext_chromium', 'chromium' ],
916-
[ 'ext_edge', 'edge' ],
917-
[ 'ext_firefox', 'firefox' ],
918-
[ 'ext_mobile', 'mobile' ],
919-
[ 'ext_safari', 'safari' ],
920-
[ 'adguard_ext_chromium', 'chromium' ],
921-
[ 'adguard_ext_edge', 'edge' ],
922-
[ 'adguard_ext_firefox', 'firefox' ],
923-
[ 'adguard_ext_mobile', 'mobile' ],
924-
[ 'adguard_ext_safari', 'safari' ],
915+
[ 'ext_ublock', 'ublock' ],
916+
[ 'env_chromium', 'chromium' ],
917+
[ 'env_edge', 'edge' ],
918+
[ 'env_firefox', 'firefox' ],
919+
[ 'env_mobile', 'mobile' ],
920+
[ 'env_safari', 'safari' ],
921+
[ 'cap_html_filtering', 'html_filtering' ],
922+
[ 'cap_user_stylesheet', 'user_stylesheet' ]
925923
]);
926924

927925
/******************************************************************************/

0 commit comments

Comments
 (0)