1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-06 09:37:12 +02:00

code review: not a fan of deep indentation; detect Edge, Safari

This commit is contained in:
Raymond Hill 2018-04-12 07:29:14 -04:00
parent ae6b376a75
commit 7ca6e8bfb3
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -70,38 +70,35 @@ vAPI.webextFlavor = {
}); });
} }
// Synchronous // Synchronous -- order of tests is important
var match = /Firefox\/([\d.]+)/.exec(ua); var match;
if ( match !== null ) { if ( (match = /\bFirefox\/(\d+)/.exec(ua)) !== null ) {
flavor.major = parseInt(match[1], 10) || 0; flavor.major = parseInt(match[1], 10) || 0;
soup.add('mozilla') soup.add('mozilla').add('firefox');
.add('firefox');
if ( flavor.major >= 53 ) { soup.add('user_stylesheet'); } if ( flavor.major >= 53 ) { soup.add('user_stylesheet'); }
if ( flavor.major >= 57 ) { soup.add('html_filtering'); } if ( flavor.major >= 57 ) { soup.add('html_filtering'); }
} else { } else if ( (match = /\bEdge\/(\d+)/.exec(ua)) !== null ) {
match = /OPR\/([\d.]+)/.exec(ua); flavor.major = parseInt(match[1], 10) || 0;
if ( match !== null ) { soup.add('microsoft').add('edge');
var reEx = /Chrom(?:e|ium)\/([\d.]+)/; } else if ( (match = /\bOPR\/(\d+)/.exec(ua)) !== null ) {
if ( reEx.test(ua) ) { match = reEx.exec(ua); } var reEx = /\bChrom(?:e|ium)\/([\d.]+)/;
flavor.major = parseInt(match[1], 10) || 0; if ( reEx.test(ua) ) { match = reEx.exec(ua); }
soup.add('opera').add('chromium'); flavor.major = parseInt(match[1], 10) || 0;
} else { soup.add('opera').add('chromium');
match = /Chromium\/([\d.]+)/.exec(ua); } else if ( (match = /\bChromium\/(\d+)/.exec(ua)) !== null ) {
if ( match !== null ) { flavor.major = parseInt(match[1], 10) || 0;
flavor.major = parseInt(match[1], 10) || 0; soup.add('chromium');
soup.add('chromium'); } else if ( (match = /\bChrome\/(\d+)/.exec(ua)) !== null ) {
} else { flavor.major = parseInt(match[1], 10) || 0;
match = /Chrome\/([\d.]+)/.exec(ua); soup.add('google').add('chromium');
if ( match !== null ) { } else if ( (match = /\bSafari\/(\d+)/.exec(ua)) !== null ) {
flavor.major = parseInt(match[1], 10) || 0; flavor.major = parseInt(match[1], 10) || 0;
soup.add('google').add('chromium'); soup.add('apple').add('safari');
} }
}
} // https://github.com/gorhill/uBlock/issues/3588
// https://github.com/gorhill/uBlock/issues/3588 if ( soup.has('chromium') && flavor.major >= 66 ) {
if ( soup.has('chromium') && flavor.major >= 67 ) { soup.add('user_stylesheet');
soup.add('user_stylesheet');
}
} }
// Don't starve potential listeners // Don't starve potential listeners