For #6558 - change from modifying event to event listener

The initial design replaced the onload method, which was used by others such as Bing.
With listeners it's additive, we do not replace anything.
This commit is contained in:
Mihai Branescu 2020-04-23 23:19:17 +03:00 committed by Jeff Boek
parent 8e66e19dbb
commit 8a80fbe14c

View File

@ -25,18 +25,26 @@ function sendLinks() {
browser.runtime.sendNativeMessage("MozacBrowserAds", message);
}
const events = ["pageshow", "load", "unload"];
var timeout;
window.onload = function() {
const eventLogger = event => {
switch (event.type) {
case "load":
timeout = setTimeout(sendLinks, ADLINK_CHECK_TIMEOUT_MS);
};
window.onpageshow = function(event) {
break;
case "pageshow":
if (event.persisted) {
timeout = setTimeout(sendLinks, ADLINK_CHECK_TIMEOUT_MS);
}
break;
case "unload":
clearTimeout(timeout);
default:
console.log('Event:', event.type);
}
};
window.onunload = function() {
clearTimeout(timeout);
};
events.forEach(eventName =>
window.addEventListener(eventName, eventLogger)
);