Greasy Fork 还支持 简体中文。

m.facebook.com sound notification

Play sound and show notification when a mess comes.

目前為 2017-11-06 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name m.facebook.com sound notification
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Play sound and show notification when a mess comes.
  6. // @author Psyblade
  7. // @match https://m.facebook.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. //Disable page visibility api to make browser play sound even when browser is off to the bottom, or when the active web tab is not Facebook.
  12. Object.defineProperties(document.wrappedJSObject,{ 'hidden': {value: false}, 'visibilityState': {value: 'visible'} });
  13. window.addEventListener( 'visibilitychange', evt => evt.stopImmediatePropagation(), true);
  14.  
  15. //For some reason, the procedure is must to make Yandex use this script stably.
  16. var initialization = new Audio('https://raw.githubusercontent.com/psyblade12/Notification-in-m.facebook.com/master/Initialization.mp3');
  17. initialization.play();
  18.  
  19. //Add event listener to element #2 of classes named "_59tg". Event will fire if the web browser detects changes in inner HTML of that element.
  20. document.getElementsByClassName("_59tg")[2].addEventListener("DOMNodeInserted", function(){
  21. var b = document.getElementsByClassName("_59tg");
  22. //If there is a mess, then its inner HTML of this element will be something, like "1","2" or "3".... except "0"
  23. if(b[2].innerHTML != "0")
  24. {
  25. //Play the notification sound. If you want, then change the link. Replace my link by any sound you want to hear.
  26. var audio = new Audio('https://raw.githubusercontent.com/psyblade12/mycv/master/CasioChime.mp3');
  27. audio.play();
  28. }
  29. });