0

I created this script, however the cache cleaning warning appears in the debug console which is not defined. How can I solve it?

I uploaded the code here https://codepen.io/stiac/pen/ExPjgwe

   class NotificationBanner {

  constructor(el) {  
    this.storageKey = 'notifications'
    this.el = el  
    this.id = this.el.dataset.id  
    this.el.querySelector(".closebutton").onclick = () => this.close()  
    this.showUnlessDismissed()
  }
  show() {
    this.el.hidden = false
  }
  close() {
    this.el.remove()
    this.updateLocalStorage()
  }
  showUnlessDismissed() {
    if(this.getLocalStorage().includes(this.id)) {
      this.close()
    }
    else {
      this.show()
    }
  }
  updateLocalStorage() {
    const dismissedNotifications = this.getLocalStorage()
    if(!dismissedNotifications.includes(this.id)) {
      dismissedNotifications.push(this.id)
      localStorage.setItem(this.storageKey, JSON.stringify(dismissedNotifications))
    }
  }
  getLocalStorage() {
    return JSON.parse(localStorage.getItem(this.storageKey)) || []
  }
}

class NotificationBanners {
  constructor() {
    const notifications = [...document.querySelectorAll(".notification-banner")];

    notifications.forEach(function(notification) {
      return new NotificationBanner(notification);
    })
  }
}

new NotificationBanners()



clearcache.onclick = e => localStorage.setItem('notifications', JSON.stringify([])) 

It is a script to hide a message. I wish I could set a deadline to make it appear after a few days.

0 Answers0