Skip to content

Commit 68ae847

Browse files
committed
Add support for AdGuard's mp4 filter option
Related discussion: - uBlockOrigin/uBlock-issues#701 (comment) The `mp4` filter option will be converted to `redirect=noopmp4-1s` internally, and `media` type will be assumed.
1 parent 40cdcea commit 68ae847

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/js/redirect-engine.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ const RedirectEngine = function() {
273273

274274
RedirectEngine.prototype.reset = function() {
275275
this.rules = new Map();
276-
this.ruleTypes = new Set();
277276
this.ruleSources = new Set();
278277
this.ruleDestinations = new Set();
279278
this.modifyTime = Date.now();
@@ -384,7 +383,6 @@ RedirectEngine.prototype.toURL = function(fctxt) {
384383
RedirectEngine.prototype.addRule = function(src, des, type, pattern, redirect) {
385384
this.ruleSources.add(src);
386385
this.ruleDestinations.add(des);
387-
this.ruleTypes.add(type);
388386
const key = `${src} ${des} ${type}`,
389387
entries = this.rules.get(key);
390388
if ( entries === undefined ) {
@@ -475,6 +473,10 @@ RedirectEngine.prototype.compileRuleFromStaticFilter = function(line) {
475473
redirect = 'empty';
476474
continue;
477475
}
476+
if ( option === 'mp4' ) {
477+
redirect = 'noopmp4-1s';
478+
continue;
479+
}
478480
if ( option.startsWith('domain=') ) {
479481
srchns = option.slice(7).split('|');
480482
continue;
@@ -496,8 +498,13 @@ RedirectEngine.prototype.compileRuleFromStaticFilter = function(line) {
496498

497499
// Need one single type -- not negated.
498500
if ( type === undefined ) {
499-
if ( redirect !== 'empty' ) { return; }
500-
type = '*';
501+
if ( redirect === 'empty' ) {
502+
type = '*';
503+
} else if ( redirect === 'noopmp4-1s' ) {
504+
type = 'media';
505+
} else {
506+
return;
507+
}
501508
}
502509

503510
if ( deshn === '' ) {
@@ -562,7 +569,6 @@ RedirectEngine.prototype.toSelfie = function(path) {
562569
`${path}/main`,
563570
JSON.stringify({
564571
rules: rules,
565-
ruleTypes: Array.from(this.ruleTypes),
566572
ruleSources: Array.from(this.ruleSources),
567573
ruleDestinations: Array.from(this.ruleDestinations)
568574
})
@@ -580,7 +586,6 @@ RedirectEngine.prototype.fromSelfie = function(path) {
580586
}
581587
if ( selfie instanceof Object === false ) { return false; }
582588
this.rules = new Map(selfie.rules);
583-
this.ruleTypes = new Set(selfie.ruleTypes);
584589
this.ruleSources = new Set(selfie.ruleSources);
585590
this.ruleDestinations = new Set(selfie.ruleDestinations);
586591
this.modifyTime = Date.now();

src/js/static-net-filtering.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2011,7 +2011,7 @@ FilterParser.prototype.parseOptions = function(s) {
20112011
continue;
20122012
}
20132013
// Used by Adguard, purpose is unclear -- just ignore for now.
2014-
if ( opt === 'empty' ) {
2014+
if ( opt === 'empty' || opt === 'mp4' ) {
20152015
if ( this.redirect !== 0 ) {
20162016
this.unsupported = true;
20172017
break;

0 commit comments

Comments
 (0)