我的一个简单的反网络欺凌插件的代码在JSFiddle中完美运行,但在我的网站中不起作用,即使我添加document.ready并使用像jslint这样的c + p清理程序。我研究了几个SO问题,但没有一个答案适合我。
这是JSFiddle: The Code
以下是我在网站上使用的确切JS:
$(document).ready(function() {
var triggerWords = ["stupid",
"ugly",
"fat",
"kill",
"dumb",
"idiot",
"moron",
"no future",
"nerd",
"smelly",
"stinks",
"stink",
"fatso",
"freak",
"weirdo",
"crazy",
"ass",
"asshole",
"bitch",
"abortion",
"disgusting",
"loser",
"lame",
"failure",
"unlovable",
"shit",
"fuck",
"worthless",
"douchebag",
"douche",
"I hate you",
"retard",
"retarded",
"pervert",
"overdramatic",
"prick",
"hater",
"hate",
"disgrace",
"obese",
"lazy",
"unloved",
"geek",
"unwanted",
"emo",
"annoying",
"untalented",
"whore",
"obnoxious",
"slut",
"homo",
"useless",
"psycho",
"pathetic",
"selfish",
"monster",
"coward",
"naive",
"gullible",
"crybaby",
"unqualified",
"hopeless",
"sleazy",
];
$(document).on('keyup', 'textarea', function humhm {
for (var i = 0; i < triggerWords.length; i++) {
if ($(this).val().toLowerCase().indexOf(triggerWords[i]) != -1) {
document.getElementById("styled").className = "mystyle";
document.getElementById("shover").className = "mason";
const messages = ['<img src="https://lh3.googleusercontent.com/TzOBj6xt9unc8n41fMyUZ46FG4MRXBK6wkdOtzmKJPoLa9gBYNwZYQkRB8fsboqM1LHh3ahxOLOlyKsH1zG1qmGHgbS6IK-yZtv6Duo6_thwIKEVRY7BZNr2JJzAkYviyKp_q7SPWnp1"width="200px" class="floater" onclick="javascript:eraseText();">Words mean a lot. Their echoes can brighten someone\'s day. Or they can make a bad day worse. Consider the person behind the screen.', '<img src="https://lh3.googleusercontent.com/TzOBj6xt9unc8n41fMyUZ46FG4MRXBK6wkdOtzmKJPoLa9gBYNwZYQkRB8fsboqM1LHh3ahxOLOlyKsH1zG1qmGHgbS6IK-yZtv6Duo6_thwIKEVRY7BZNr2JJzAkYviyKp_q7SPWnp1"width="200px" class="floater" onclick="javascript:eraseText();">Your words can be a force for happiness or dejection. Choose carefully.', 'Be mindful of your words. Would you say this in real life?', 'Consider the impact your words may have. A couple insults slung casually can be much more significant to others.', 'Words that are insignificant to you can deeply hurt another. Be empathetic. Be nice.'];
const randomIndex = Math.round(Math.random(messages.length * 10 - 0.5));
document.getElementById("shover").innerHTML = messages[randomIndex];
document.getElementById("usual").className = "noshow";
document.getElementById("trigger").className = "norm";
}
}
});
});
'
没有控制台错误。