Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将数组附加到wordfilter(greasemonkey+;jquery)中?_Jquery_Arrays_Greasemonkey - Fatal编程技术网

如何将数组附加到wordfilter(greasemonkey+;jquery)中?

如何将数组附加到wordfilter(greasemonkey+;jquery)中?,jquery,arrays,greasemonkey,Jquery,Arrays,Greasemonkey,我想制作一个单词过滤器,它将把自己选择的单词替换给其他人,例如“ball”->“circle”和“orange”->“yellow” 到目前为止,我的剧本是: <textarea id="banwords">ball:circle, orange:yellow</textarea> 这是旧的替换脚本,但现在我想从GM_getValue(“banwords”)获取单词: 我正在更新答案,希望这能帮助你 $(".t").each(function(){ var e1

我想制作一个单词过滤器,它将把自己选择的单词替换给其他人,例如“ball”->“circle”和“orange”->“yellow”

到目前为止,我的剧本是:

<textarea id="banwords">ball:circle, orange:yellow</textarea>
这是旧的替换脚本,但现在我想从GM_getValue(“banwords”)获取单词:


我正在更新答案,希望这能帮助你

$(".t").each(function(){
   var e1 = $(this).find('#banwords');
    var values = e1.text().split(", ");
    $.each(values, function(i,value){
        var val = value.split(":");
        e1.text(e1.text().replace(val[0],val[1]));
     });
});

fiddle:

但这并不能抓住文本区域中的单词,因为如果文本区域中有其他内容,它将不会被替换,但如果其他用户在文本区域中编写:nice:cool,sweet:roll,那么你的脚本将无法正常工作我已经更新了代码和fiddle,希望这次它能帮助你。
$(".t").each(function(i,el) {  
    el = $(el);
    el.find(":contains('ball')").replaceWith("circle");
    el.find(":contains('orange')").replaceWith("yellow");
    });
$(".t").each(function(){
   var e1 = $(this).find('#banwords');
    var values = e1.text().split(", ");
    $.each(values, function(i,value){
        var val = value.split(":");
        e1.text(e1.text().replace(val[0],val[1]));
     });
});