Skip to content

Commit

Permalink
refactor: rename a var
Browse files Browse the repository at this point in the history
  • Loading branch information
WofWca committed Jul 21, 2023
1 parent 303b432 commit 9f778c7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions js/unload.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ window.addEventListener("load", () => {
let container = h("div", {class: "container"});
let events = ["unload", "beforeunload", "visibilitychange", "pagehide"];
let getInt = (key) => parseInt(window.localStorage.getItem(key) || 0);
events.forEach(key => {
events.forEach(eventName => {
container.append(
h("strong", {}, key), " triggered ", h("strong", {id: key + "-counter"}, getInt(`docEvent.${key}`)), " times",
h("strong", {}, eventName), " triggered ", h("strong", {id: eventName + "-counter"}, getInt(`docEvent.${eventName}`)), " times",
h("br"),
);
window.addEventListener(key, () => {
let storageKey = `docEvent.${key}`;
window.addEventListener(eventName, () => {
let storageKey = `docEvent.${eventName}`;
let count = getInt(storageKey) + 1;
window.localStorage.setItem(storageKey, count);
document.getElementById(key + "-counter").innerHTML = count;
document.getElementById(eventName + "-counter").innerHTML = count;
});
});

Expand Down

0 comments on commit 9f778c7

Please sign in to comment.