我无法在 tampermonkey 的特定事件上播放声音
I could not manage to play sound on specific event at tampermonkey
我想在使用脚本不断刷新的网页上的特定区域发生文本更改时播放声音。
我希望该代码在与我输入的文本不匹配时刷新并播放声音。
// ==UserScript==
// @name Audio Script
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://x
// @match https://x
// @match https://x
// @grant none
// ==/UserScript==
(function() {
'use strict';
var audio = document.createElement("audio");
audio.src = "http://y/vuvuzela-trumpet.mp3";
function reload()
{ location.reload();};
var x = document.getElementsByClassName("sl-nm")[0].firstChild.attributes[0].nodeValue;
console.log(x)
if ( x != "/a/b" ); // text i entered
audio.play;
var interval = Math.random()*5000
var interval2 = Math.random()*5000
var gecikme = (interval+interval2)*2.3
console.log(gecikme/60000)
var myVar = setInterval(() => reload(), gecikme)
// Your code here...
})();
问题是,如果有人像我一样遇到同样的错误;
if ( x != "/a/b" ); // text i entered
audio.play;
一定要改成这样
if ( x != "/a/b" ); // text i entered
audio.play() ;
使用 JavaScript 时请不要依赖缩进 - 只需使用括号来创建条件语句:
(function() {
'use strict';
var audio = document.createElement("audio");
audio.src = "http://y/vuvuzela-trumpet.mp3";
function reload() {
location.reload();
}
var x = document.getElementsByClassName("sl-nm")[0].firstChild.attributes[0].nodeValue;
console.log(x);
if ( x != "/a/b" ) { // text i entered
audio.play;
}
var interval = Math.random()*5000;
var interval2 = Math.random()*5000;
var gecikme = (interval+interval2)*2.3;
console.log(gecikme/60000);
var myVar = setInterval(() => reload(), gecikme);
// Your code here...
})();
我想在使用脚本不断刷新的网页上的特定区域发生文本更改时播放声音。
我希望该代码在与我输入的文本不匹配时刷新并播放声音。
// ==UserScript==
// @name Audio Script
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://x
// @match https://x
// @match https://x
// @grant none
// ==/UserScript==
(function() {
'use strict';
var audio = document.createElement("audio");
audio.src = "http://y/vuvuzela-trumpet.mp3";
function reload()
{ location.reload();};
var x = document.getElementsByClassName("sl-nm")[0].firstChild.attributes[0].nodeValue;
console.log(x)
if ( x != "/a/b" ); // text i entered
audio.play;
var interval = Math.random()*5000
var interval2 = Math.random()*5000
var gecikme = (interval+interval2)*2.3
console.log(gecikme/60000)
var myVar = setInterval(() => reload(), gecikme)
// Your code here...
})();
问题是,如果有人像我一样遇到同样的错误;
if ( x != "/a/b" ); // text i entered
audio.play;
一定要改成这样
if ( x != "/a/b" ); // text i entered
audio.play() ;
使用 JavaScript 时请不要依赖缩进 - 只需使用括号来创建条件语句:
(function() {
'use strict';
var audio = document.createElement("audio");
audio.src = "http://y/vuvuzela-trumpet.mp3";
function reload() {
location.reload();
}
var x = document.getElementsByClassName("sl-nm")[0].firstChild.attributes[0].nodeValue;
console.log(x);
if ( x != "/a/b" ) { // text i entered
audio.play;
}
var interval = Math.random()*5000;
var interval2 = Math.random()*5000;
var gecikme = (interval+interval2)*2.3;
console.log(gecikme/60000);
var myVar = setInterval(() => reload(), gecikme);
// Your code here...
})();