How to stop javascript notification from showing after clicking ok

I want to show a warning if I have something in my Facebook inbox. I think this can be easily done with custom scripts ... this is what I have so far (thanks to the guys on the userscripts forums):

document.addEventListener("DOMNodeInserted", function() {
  var count;
  if ((count=parseInt(document.getElementById("fb_menu_inbox_unread_count").textContent)) > 0)
  alert("You have "+count+" new message"+(count==1 ? "" : "s")+".");
}, true);

This works fine, except that the message gets stuck in the loop after clicking OK and continues to appear. Is there a way to stop the message after clicking the "Warning" button?

+3
source share
2 answers

, , , , .

- :

document.addEventListener(
  "DOMNodeInserted", 
  function() { 
    var count = parseInt(document.getElementById("fb_menu_inbox_unread_count").textContent);
    if (count > 0 && count != lastCount) {
      alert("You have "+count+" new message"+(count==1 ? "" : "s")+"."); }, true);
    }
    lastCount = count;  // Remember count to avoid continuous alerts.

, , . , .

+3

cookie document.cookie, ,

0

Source: https://habr.com/ru/post/1707371/


All Articles