我只是在尝试Tampermonkey中的代码,当聊天中出现某种类型的消息时发出声音。Tampermonkey脚本只能在第一个新节点上工作
问题是,此脚本只适用于第一条消息,我希望每次都能使其工作。
我一直在寻找通过互联网,我发现可能是因为一些叫'iFrames'?
脚本:
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Sound when chat message
// @author You
// @include *
// @grant none
// ==/UserScript==
var exist = false;
var notified = false;
mCoinSound = new Audio("https://dl.dropbox.com/u/7079101/coin.mp3");
setInterval(getRain, 2000);
function getRain() {
var rain = document.getElementsByClassName('rain-message');
exist = rain.length === 0 ? false : true;
notified = (exist && notified);
if (exist && !notified) {
mCoinSound.play();
notified = true;
}
}
你认为'setInterval'在这里做什么? – jmargolisvt
@jmargolisvt 我已经使用它来重复代码,并且如果消息已经出现,每2秒检查一次 – Prodx9