如何在Greasemonkey脚本中播放声音? [英] How can I play a sound within a Greasemonkey script?
本文介绍了如何在Greasemonkey脚本中播放声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Greasemonkey脚本中播放声音?
How can I play a sound within a Greasemonkey script?
我目前正在尝试做的是在达到条件时播放声音,类似于:
What I'm trying to do currently is to play a sound whenever a condition is reached, something like:
// ==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 any way to do so? The code above isn't working!
推荐答案
好吧,看起来似乎要求提高找出问题的可能性问题的正确答案(呵呵呵)。
Well, it seems like asking improves the possibility of finding out the correct answer for a problem (hehehe).
这是我的解决方案:
// ==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!');
}
}
这篇关于如何在Greasemonkey脚本中播放声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文