Skip to content

Instantly share code, notes, and snippets.

@alexdresko
Created March 25, 2014 03:19
Show Gist options
  • Save alexdresko/9754645 to your computer and use it in GitHub Desktop.
Save alexdresko/9754645 to your computer and use it in GitHub Desktop.
Greasemonkey/tampermonkey script that plays a sound whenever a matched page is finished loading.
// ==UserScript==
// @name Soundy
// @namespace http://www.alexdresko.com/
// @version 0.1
// @description Plays some kind of noise whenever a matched page finishes loading
// @match https://localhost:44300/*
// @match https://gist.github.com/*
// @copyright 2014+, Alex Dresko
// ==/UserScript==
var beep = (function () {
var ctx = new(window.audioContext || window.webkitAudioContext);
return function (duration, type, finishedCallback) {
duration = +duration;
// Only 0-4 are valid types.
type = (type % 5) || 0;
if (typeof finishedCallback != "function") {
finishedCallback = function () {};
}
var osc = ctx.createOscillator();
osc.type = type;
osc.connect(ctx.destination);
osc.noteOn(0);
setTimeout(function () {
osc.noteOff(0);
finishedCallback();
}, duration);
};
})();
setTimeout(function(){beep()},1000);
@asgh
Copy link

asgh commented Jan 28, 2018

Typo: window.audioContext should be window.AudioContext

Edit: Type is wrong also, you need to send it a string not a number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment