Change Facebook Notification Sound

Small script for a request https://gf.qytechs.cn/uk/forum/discussion/6631/change-facebook-notification-sound-convert-chrome-extension-to-userscript

目前為 2015-10-25 提交的版本,檢視 最新版本

// ==UserScript==
// @name        Change Facebook Notification Sound
// @namespace   cfs
// @description Small script for a request https://gf.qytechs.cn/uk/forum/discussion/6631/change-facebook-notification-sound-convert-chrome-extension-to-userscript
// @include     https://facebook.com/*
// @version     0.1
// @grant       none
// @noframes
// @run-at document-end
// @author      Dexmaster
// @date        2015-10-25
// ==/UserScript==

(function () {
    "use strict";

    var counter = 0,
        soundUri = 'https://instaud.io/_/djS.mp3', // input sound link here
        audio;

    var ready = function (fn) {
        if (document.readyState !== 'loading') {
            fn();
        } else {
            document.addEventListener('DOMContentLoaded', fn);
        }
    };

    var countUnread = function () {
        var els = document.querySelectorAll("._51jx"),
            sum = Array.prototype.map.call(els, function (el) {
                return parseInt(el.innerHTML) || 0;
            }).reduce(function (a, b) {
                return a + b;
            }, 0);
        return sum;
    };

    var numberChange = function () {
        var num = countUnread();
        if (counter !== num) {
            counter = num;
            audio.play();
        }
    };

    var init = function () {
        audio = document.createElement('audio');
        audio.setAttribute('src', soundUri);
        audio.setAttribute('autoplay', 'autoplay');
        setInterval(numberChange, 1000);
    };

    ready(init);

}());

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址