I'm trying to make a userscript for a website to add custom emotes.
(我正在尝试为网站制作用户脚本以添加自定义表达。)
However, I've been getting a lot of errors.(但是,我遇到了很多错误。)
Here is the function:
(这是功能:)
function saveEmotes() {
removeLineBreaks();
EmoteNameLines = EmoteName.value.split("
");
EmoteURLLines = EmoteURL.value.split("
");
EmoteUsageLines = EmoteUsage.value.split("
");
if (EmoteNameLines.length == EmoteURLLines.length && EmoteURLLines.length == EmoteUsageLines.length) {
for (i = 0; i < EmoteURLLines.length; i++) {
if (checkIMG(EmoteURLLines[i])) {
localStorage.setItem("nameEmotes", JSON.stringify(EmoteNameLines));
localStorage.setItem("urlEmotes", JSON.stringify(EmoteURLLines));
localStorage.setItem("usageEmotes", JSON.stringify(EmoteUsageLines));
if (i == 0) {
console.log(resetSlot());
}
emoteTab[2].innerHTML += '<span style="cursor:pointer;" onclick="appendEmote('' + EmoteUsageLines[i] + '')"><img src="' + EmoteURLLines[i] + '" /></span>';
} else {
alert("The maximum emote(" + EmoteNameLines[i] + ") size is (36x36)");
}
}
} else {
alert("You have an unbalanced amount of emote parameters.");
}
}
The span
tag's onclick
calls this function:
(span
标签的onclick
调用此函数:)
function appendEmote(em) {
shoutdata.value += em;
}
Every time I click a button that has an onclick
attribute, I get this error:
(每次我单击一个具有onclick
属性的按钮时,我都会收到此错误:)
Uncaught ReferenceError: function is not defined.
(未捕获的ReferenceError:未定义函数。)
Any help would be appreciated.
(任何帮助,将不胜感激。)
Thank you!
(谢谢!)
Update(更新)
I tried using:
(我试过用:)
emoteTab[2].innerHTML += '<span style="cursor:pointer;" id="'+ EmoteNameLines[i] +'"><img src="' + EmoteURLLines[i] + '" /></span>';
document.getElementById(EmoteNameLines[i]).addEventListener("click", appendEmote(EmoteUsageLines[i]), false);
But I got an undefined
error.
(但是我得到了一个undefined
错误。)
Here is the script .
(这是脚本 。)
I tried doing this to test if listeners work and they don't for me:
(我试着这样做来测试听众是否有效并且不适合我:)
emoteTab[2].innerHTML = '<td class="trow1" width="12%" align="center"><a id="togglemenu" style="cursor: pointer;">Custom Icons</a></br><a style="cursor: pointer;" id="smilies" onclick='window.open("misc.php?action=smilies&popup=true&editor=clickableEditor","Smilies","scrollbars=yes, menubar=no,width=460,height=360,toolbar=no");' original-title="">Smilies</a><br><a style="cursor: pointer;" onclick='window.open("shoutbox.php","Shoutbox","scrollbars=yes, menubar=no,width=825,height=449,toolbar=no");' original-title="">Popup</a></td></br>';
document.getElementById("togglemenu").addEventListener("click", changedisplay,false);
ask by ECMAScript translate from so