How can I play sound in Greasemonkey script?
How can I play sound in Greasemonkey script?
I am currently trying to play sound when some condition is reached, for example:
// ==UserScript==
// @name Sound Alert
// @namespace example.com
// @include example.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @version 1
// @grant none
// ==/UserScript==
sound = new Audio("https://dl.dropbox.com/u/7079101/coin.mp3");
for (var i = 0; i <= 10; i++) {
if (i === 10) {
// Play a sound when i === 10
sound.play();
} else {
console.log('Not yet!');
}
}
How can i do this? Is there a way to do this? The code above doesn't work!
+3
source to share
3 answers
Well, it looks like asking improves the ability to figure out the correct answer to the problem (hehehe).
Here's my solution:
// ==UserScript==
// @name Sound Alert
// @include http://YOUR_SERVER.COM/YOUR_PATH/*
// @grant none
// ==/UserScript==
var player = document.createElement('audio');
player.src = 'https://dl.dropbox.com/u/7079101/coin.mp3';
player.preload = 'auto';
for (var i = 0; i <= 10; i++) {
if (i === 10) {
// Play a sound when i === 10
player.play();
} else {
console.log('Not yet!');
}
}
+3
source to share
To record audio in a GreaseMonkey script, you need to follow these basic steps:
Step 1: Create an item of type "Audio"
Step 2. Assign the source property to the location of the file.
var audio = document.createElement("audio");
audio.src = "https://dl.dropbox.com/u/7079101/coin.mp3";
0
source to share
Here's the solution
var audioformsg = new Audio();
audioformsg.src = 'http://www.podst.ru/pix/user_files/2/5564/Click_08.mp3';
audioformsg.autoplay = true;
from code https://greasyfork.org/zh-CN/scripts/8149-sound-for-message/code
0
source to share