Greasy Fork is available in English.
Small script for a request http://greasyfork.icu/uk/forum/discussion/6631/change-facebook-notification-sound-convert-chrome-extension-to-userscript
当前为
// ==UserScript==
// @name Change Facebook Notification Sound
// @namespace cfs
// @description Small script for a request http://greasyfork.icu/uk/forum/discussion/6631/change-facebook-notification-sound-convert-chrome-extension-to-userscript
// @include https://facebook.com/*
// @version 0.1.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
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);
}());