// ==UserScript== // @name Change Facebook Notification Sound // @namespace cfs // @description Small script for a request https://greasyfork.org/uk/forum/discussion/6631/change-facebook-notification-sound-convert-chrome-extension-to-userscript // @include https://facebook.com/* // @include https://www.facebook.com/* // @version 0.1.2 // @grant none // @noframes // @run-at document-end // @author Dexmaster // @date 2015-10-25 // @downloadURL none // ==/UserScript== (function () { "use strict"; var counter = 0, soundUri = 'https://instaud.io/_/djS.mp3', // input sound link here interval = 5, // number of seconds between checks 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, interval*1000); }; ready(init); }());