m.facebook.com sound notification

Play sound and show notification when a mess comes.

当前为 2017-11-06 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         m.facebook.com sound notification
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Play sound and show notification when a mess comes.
// @author       Psyblade
// @match        https://m.facebook.com/*
// @grant        none
// ==/UserScript==

//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.
Object.defineProperties(document.wrappedJSObject,{ 'hidden': {value: false}, 'visibilityState': {value: 'visible'} });
window.addEventListener( 'visibilitychange', evt => evt.stopImmediatePropagation(), true);

//For some reason, the procedure is must to make Yandex use this script stably.
var initialization = new Audio('https://raw.githubusercontent.com/psyblade12/Notification-in-m.facebook.com/master/Initialization.mp3');
initialization.play();

//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.  
document.getElementsByClassName("_59tg")[2].addEventListener("DOMNodeInserted", function(){
        var b =  document.getElementsByClassName("_59tg");
    //If there is a mess, then its inner HTML of this element will be something, like "1","2" or "3".... except "0"
        if(b[2].innerHTML != "0")
        {
                //Play the notification sound. If you want, then change the link. Replace my link by any sound you want to hear.
                var audio = new Audio('https://raw.githubusercontent.com/psyblade12/mycv/master/CasioChime.mp3');
                audio.play();
        }
});