This commit is contained in:
gorhill 2017-11-09 12:53:05 -05:00
parent d523d64511
commit 386e8bee9c
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
3 changed files with 38 additions and 15 deletions

View file

@ -114,6 +114,7 @@
"group": "ads",
"off": true,
"title": "Adguard Mobile Filters",
"ua": "mobile",
"contentURL": "https://filters.adtidy.org/extension/ublock/filters/11.txt",
"supportURL": "https://github.com/AdguardTeam/AdguardFilters#adguard-filters",
"instructionURL": "https://kb.adguard.com/en/general/adguard-ad-filters"

View file

@ -295,7 +295,7 @@
return haystack.replace(
new RegExp(
'(^|\\n)' +
needle.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') +
this.escapeRegex(needle) +
'(\\n|$)', 'g'),
'\n'
).trim();
@ -439,7 +439,7 @@
selectedListKeys.push(key);
continue;
}
if ( this.matchCurrentLanguage(list.lang) ) {
if ( this.listMatchesEnvironment(list) ) {
selectedListKeys.push(key);
list.off = false;
}
@ -1069,6 +1069,32 @@
/******************************************************************************/
// https://github.com/gorhill/uBlock/issues/2344
// Support mutliple locales per filter list.
// https://github.com/gorhill/uBlock/issues/3210
// Support ability to auto-enable a filter list based on user agent.
µBlock.listMatchesEnvironment = function(details) {
var re;
// Matches language?
if ( typeof details.lang === 'string' ) {
if ( this.listMatchesEnvironment.reLang === undefined ) {
re = new RegExp('\\b' + self.navigator.language.slice(0, 2) + '\\b');
this.listMatchesEnvironment.reLang = re;
}
if ( re.test(details.lang) ) { return true; }
}
// Matches user agent?
if ( typeof details.ua === 'string' ) {
re = new RegExp('\\b' + this.escapeRegex(details.ua) + '\\b', 'i');
if ( re.test(self.navigator.userAgent) ) { return true; }
}
return false;
};
/******************************************************************************/
µBlock.scheduleAssetUpdater = (function() {
var timer, next = 0;
return function(updateDelay) {
@ -1196,7 +1222,7 @@
if ( details.entry.content === 'filters' ) {
if (
details.entry.off !== true ||
this.matchCurrentLanguage(details.entry.lang)
this.listMatchesEnvironment(details.entry)
) {
this.saveSelectedFilterLists([ details.assetKey ], true);
}

View file

@ -347,18 +347,6 @@
/******************************************************************************/
// https://github.com/gorhill/uBlock/issues/2344
µBlock.matchCurrentLanguage = function(s) {
if ( typeof s !== 'string' ) { return false; }
if ( this.matchCurrentLanguage.reLang === undefined ) {
this.matchCurrentLanguage.reLang = new RegExp('\\b' + self.navigator.language.slice(0, 2) + '\\b');
}
return this.matchCurrentLanguage.reLang.test(s);
};
/******************************************************************************/
µBlock.MRUCache = function(size) {
this.size = size;
this.array = [];
@ -396,3 +384,11 @@
};
/******************************************************************************/
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
µBlock.escapeRegex = function(s) {
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
};
/******************************************************************************/