Index: lib/notification.js |
=================================================================== |
--- a/lib/notification.js |
+++ b/lib/notification.js |
@@ -102,12 +102,25 @@ |
return -1; |
} |
+function initNotificationMatcher(notification) |
+{ |
+ if ("_matcher" in notification || !(notification.urlFilters instanceof Array)) |
+ return; |
+ |
+ let matcher = new Matcher(); |
+ for (let urlFilter of notification.urlFilters) |
+ matcher.add(Filter.fromText(urlFilter)); |
+ matcher.toJSON = () => {}; |
+ notification._matcher = matcher; |
+} |
+ |
/** |
* The object providing actual downloading functionality. |
* @type {Downloader} |
*/ |
let downloader = null; |
let localData = []; |
+let remoteData = []; |
/** |
* Regularly fetches notifications and decides which to show. |
@@ -120,6 +133,14 @@ |
*/ |
init() |
{ |
+ let notificationdata = Prefs.notificationdata.data; |
+ if (notificationdata) |
+ { |
+ for (let notification of notificationdata.notifications) |
+ initNotificationMatcher(notification); |
+ remoteData = notificationdata.notifications; |
+ } |
+ |
downloader = new Downloader(this._getDownloadables.bind(this), |
INITIAL_DELAY, CHECK_INTERVAL); |
downloader.onExpirationChange = this._onExpirationChange.bind(this); |
@@ -174,7 +195,9 @@ |
notification.type = notification.severity; |
delete notification.severity; |
} |
+ initNotificationMatcher(notification); |
} |
+ remoteData = data.notifications; |
Prefs.notificationdata.data = data; |
} |
catch (e) |
@@ -233,13 +256,6 @@ |
*/ |
_getNextToShow(url) |
{ |
- let remoteData = []; |
- if (typeof Prefs.notificationdata.data == "object" && |
- Prefs.notificationdata.data.notifications instanceof Array) |
- { |
- remoteData = Prefs.notificationdata.data.notifications; |
- } |
- |
let notifications = localData.concat(remoteData); |
if (notifications.length === 0) |
return null; |
@@ -298,10 +314,10 @@ |
} |
} |
- if (typeof url === "string" || notification.urlFilters instanceof Array) |
+ if (typeof url === "string" || "_matcher" in notification) |
Thomas Greiner
2018/01/29 15:39:20
This block contains relevant changes that were mad
|
{ |
if (Prefs.enabled && typeof url === "string" && |
- notification.urlFilters instanceof Array) |
+ "_matcher" in notification) |
{ |
let host; |
try |
@@ -319,14 +335,9 @@ |
if (exception instanceof WhitelistFilter) |
continue; |
- let matcher = new Matcher(); |
- for (let urlFilter of notification.urlFilters) |
- matcher.add(Filter.fromText(urlFilter)); |
- if (!matcher.matchesAny(url, RegExpFilter.typeMap.DOCUMENT, host, |
- false, null)) |
- { |
+ if (!notification._matcher.matchesAny(url, |
+ RegExpFilter.typeMap.DOCUMENT, host, false, null)) |
continue; |
- } |
} |
else |
continue; |
@@ -433,7 +444,10 @@ |
addNotification(notification) |
{ |
if (localData.indexOf(notification) == -1) |
+ { |
+ initNotificationMatcher(notification); |
localData.push(notification); |
+ } |
}, |
/** |