1
0
Fork 0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-07-04 20:46:39 +02:00

Only display 250 notifications for one type

More will be counted but not rendered.

Fixes #234.
This commit is contained in:
kkapsner 2018-08-27 22:09:51 +02:00
parent 9a7d3d4230
commit 40677bd2c6
5 changed files with 46 additions and 22 deletions

View file

@ -13,6 +13,7 @@
const addToContainer = function(){
const container = document.getElementById("prints");
container.querySelector("li").textContent = browser.i18n.getMessage("pleaseWait");
var first = true;
return function addToContainer(domainNotification){
@ -27,6 +28,7 @@
const DomainNotification = function DomainNotification(domain, messageId){
this.domain = domain;
this.messageId = messageId;
this.extraNotifications = 0;
addToContainer(this);
this.update();
};
@ -40,10 +42,23 @@
};
DomainNotification.prototype.addNotification = function addNotification(notification){
this.notifications().push(notification);
this.notificationsNode().appendChild(notification.node());
if (this.notifications().length > 250){
this.addMore();
}
else {
this.notifications().push(notification);
this.notificationsNode().appendChild(notification.node());
}
this.update();
};
DomainNotification.prototype.addMore = function addMore(){
this.notificationsNode().appendChild(document.createTextNode("..."));
this.extraNotifications += 1;
this.addMore = function addMore(){
this.extraNotifications += 1;
};
};
// DOM node creation functions
@ -100,16 +115,16 @@
}).filter(function(url, i, urls){
return urls.indexOf(url) === i;
}).join("\n");
node.querySelectorAll(".url").forEach(function(urlSpan){
urlSpan.title = urls;
node.querySelectorAll(".url").forEach((urlSpan) => {
urlSpan.title = urls + (this.extraNotifications? "\n...": "");
});
node.title = notifications.map(function(notification){
return notification.timestamp + ": " + notification.functionName;
}).join("\n");
}).join("\n") + this.extraNotifications? "\n...": "";
node.querySelectorAll(".count").forEach(function(countSpan){
countSpan.textContent = notifications.length;
node.querySelectorAll(".count").forEach((countSpan) => {
countSpan.textContent = notifications.length + this.extraNotifications;
});
};