本文介绍了如何在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 // @include example/* // @require ajax.googleapis/ajax/libs/jquery/1.9.1/jquery.min.js // @version 1 // @grant none // ==/UserScript== sound = new Audio("dl.dropbox/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 YOUR_SERVER.COM/YOUR_PATH/* // @grant none // ==/UserScript== var player = document.createElement('audio'); player.src = 'dl.dropbox/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脚本中播放声音?
发布评论