Commit e86b9848 authored by Jonathon Gomez-Sonesen's avatar Jonathon Gomez-Sonesen 💬 Committed by Thomas Greiner

Issue 7401 - Adapt filter objects to text per changes to Subscription.prototype.filterText

parent 0eda1bd7
Pipeline #57101565 passed with stages
in 3 minutes and 48 seconds
......@@ -165,7 +165,7 @@
const subscriptionDetails = {
[easyListGermany]: {
title: "EasyList Germany+EasyList",
filters: ["-ad-banner.", "-ad-big.", "-ad-bottom-", "-ad-button-"],
filterText: ["-ad-banner.", "-ad-big.", "-ad-bottom-", "-ad-button-"],
installed: true
},
[acceptableAds]: {
......@@ -200,7 +200,7 @@
this.url = url;
this._disabled = false;
this._lastDownload = 1234;
this._filters = [];
this._filterText = [];
this.homepage = "https://easylist.adblockplus.org/";
this.downloadStatus = params.downloadStatus;
......@@ -209,9 +209,9 @@
{
this.disabled = !!details.disabled;
this.title = details.title || "";
if (details.filters)
if (details.filterText)
{
this._filters.push(...details.filters);
this._filterText = details.filterText.slice();
}
}
}
......@@ -236,9 +236,9 @@
modules.filterNotifier.filterNotifier.emit("subscription.lastDownload",
this);
},
*filters()
*filterText()
{
yield* this._filters;
yield* this._filterText;
}
};
Subscription.fromURL = function(url)
......@@ -255,34 +255,34 @@
{
this.url = url;
this.disabled = false;
this._filters = knownFilters.slice();
this._filterText = knownFilterText.slice();
}
SpecialSubscription.prototype = {
get filterCount()
{
return this._filters.length;
return this._filterText.length;
},
*filters()
*filterText()
{
yield* this._filters;
yield* this._filterText;
},
addFilter(filter)
addFilterText(filterText)
{
this._filters.push(filter);
this._filterText.push(filterText);
},
filterAt(idx)
filterTextAt(idx)
{
return this._filters[idx];
return this._filterText[idx];
},
removeFilter(filter)
removeFilter(filterText)
{
for (let i = 0; i < this._filters.length; i++)
for (let i = 0; i < this._filterText.length; i++)
{
if (this._filters[i].text == filter.text)
if (this._filterText[i] == filterText)
{
this._filters.splice(i, 1);
this._filterText.splice(i, 1);
modules.filterNotifier.filterNotifier.emit("filter.removed",
filter);
filterText);
return;
}
}
......@@ -331,18 +331,18 @@
addFilter(filter)
{
for (const customFilter of customSubscription.filters())
for (const text of customSubscription.filterText())
{
if (customFilter.text == filter.text)
if (text == filter.text)
return;
}
customSubscription.addFilter(filter);
customSubscription.addFilterText(filter.text);
modules.filterNotifier.filterNotifier.emit("filter.added", filter);
},
removeFilter(filter)
{
customSubscription.removeFilter(filter);
customSubscription.removeFilter(filter.text);
}
}
};
......@@ -506,7 +506,7 @@
}
});
const filters = [
const knownFilterText = [
"@@||alternate.de^$document",
"@@||der.postillion.com^$document",
"@@||taz.de^$document",
......@@ -528,7 +528,6 @@
"###ad-bereich2-08",
"###ad-bereich2-skyscrapper"
];
const knownFilters = filters.map(modules.filterClasses.Filter.fromText);
const knownSubscriptions = new Map();
for (const url in subscriptionDetails)
......
......@@ -18,7 +18,7 @@
"use strict";
const {Prefs} = require("prefs");
const {ActiveFilter} = require("filterClasses");
const {Filter, ActiveFilter} = require("filterClasses");
const {filterStorage} = require("filterStorage");
const {filterNotifier} = require("filterNotifier");
const {Subscription} = require("subscriptionClasses");
......@@ -45,8 +45,9 @@ exports.initAntiAdblockNotification = function initAntiAdblockNotification()
function addAntiAdblockNotification(subscription)
{
const urlFilters = [];
for (const filter of subscription.filters())
for (const text of subscription.filterText())
{
const filter = Filter.fromText(text);
if (filter instanceof ActiveFilter && filter.domains)
{
for (const [domain, included] of filter.domains)
......
......@@ -72,12 +72,14 @@
"softExpiration", "expires", "title",
"url"], subscription);
if (subscription instanceof SpecialSubscription)
obj.filters = Array.from(subscription.filters(), convertFilter);
obj.filters = Array.from(subscription.filterText(), convertFilterText);
obj.isDownloading = Synchronizer.isExecuting(subscription.url);
return obj;
}
const convertFilter = convertObject.bind(null, ["text"]);
const convertFilterText = (text) => convertFilter({text});
const uiPorts = new Map();
const listenedPreferences = Object.create(null);
......@@ -319,7 +321,7 @@
if (!subscription)
return [];
return Array.from(subscription.filters(), convertFilter);
return Array.from(subscription.filterText(), convertFilterText);
});
port.on("filters.importRaw", (message, sender) =>
......@@ -370,10 +372,12 @@
// https://issues.adblockplus.org/ticket/7152
for (let i = subscription.filterCount; i--;)
{
const filter = subscription.filterAt(i);
if (!/^@@\|\|([^/:]+)\^\$document$/.test(filter.text) &&
!addedFilters.has(filter.text))
filterStorage.removeFilter(filter);
const text = subscription.filterTextAt(i);
if (!/^@@\|\|([^/:]+)\^\$document$/.test(text) &&
!addedFilters.has(text))
{
filterStorage.removeFilter(Filter.fromText(text));
}
}
}
......@@ -471,7 +475,8 @@
const subscription = convertSubscription(s);
if (message.disabledFilters)
{
subscription.disabledFilters = Array.from(s.filters())
subscription.disabledFilters =
Array.from(subscription.filterText(), Filter.fromText)
.filter((f) => f instanceof ActiveFilter && f.disabled)
.map((f) => f.text);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment