如何在Greasemonkey脚本中播放声音?

编程入门 行业动态 更新时间:2024-10-19 02:23:53
本文介绍了如何在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脚本中播放声音?

本文发布于:2023-11-14 15:16:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1587764.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   声音   如何在   Greasemonkey

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!