×

jquery使用ajax实现微信自动回复插件

作者:Terry2017.02.08来源:Web前端之家浏览:10045评论:0
关键词:JQueryJS

myscript.js

复制代码 代码如下:

var _autorun;
var str = new Array('转发什么','分享什么','已转发','已轉發','己转发','继续申请','在不','已发送','以转发','以分享','已分享','yv','bv','gv','pv','rv','你好','美女','索要','代码','我要','要v','要加v');
var isrun = false;
var i=0;
function start(){
    console.log('第'+(++i)+'次刷新');
    var chatListColumn =$(".chatListColumn");
    chatListColumn.each(function(){
        var _this = this;
        var _me = $(this);
        var attr = $(this).attr('un');
        if((attr!='')&&(attr!='filehelper')&&(attr!='weixin')&&(attr!='newsapp')&&(attr!='fmessage')){
            //console.log($(this).attr('un'));
            var disp =  _me.find('p.desc').html();
            disp = disp.toLowerCase();
            disp = disp.trim();
            for (var i = 0; i < str.length; i++){
                if(disp.indexOf(str[i])!=-1){
                    isrun=true;break;
                }
            };
           if(disp.indexOf('你已添加了')!=-1||disp.indexOf('通过了你的好友验证请求')!=-1||disp.indexOf('你添加到通讯录')!=-1){
                _this.click();
                var _input = $("#textInput");
                var  message = _ajax('你已添加了',attr);
                _input.val(message);
                var _click = document.getElementsByClassName("chatSend");
                _click[0].click();
                isrun=false;
            }
            else if((disp.indexOf('发送好友验证请求')!=-1)&&disp!=''){
                isrun=false;
            }
            else if((disp.indexOf('仔细阅读上述消息')!=-1)&&disp!=''){
                isrun=false;
            }
            else if(disp!=''){
               isrun=false;
           }
            //console.log(disp);
            /*if(isrun){
                _this.click();
                var _input = $("#textInput");
                var  message = _ajax(disp,attr);
                _input.val(message);
                var _click = document.getElementsByClassName("chatSend");
                _click[0].click();
                isrun=false;
            }
            else if(disp.indexOf('你添加到通讯录')!=-1){
                _this.click();
                var _input = $("#textInput");
                var  message = _ajax('你添加到通讯录',attr);
                _input.val(message);
                var _click = document.getElementsByClassName("chatSend");
                _click[0].click();
                isrun=false;
            }
            else if(disp.indexOf('你已添加了')!=-1||disp.indexOf('通过了你的好友验证请求')!=-1){
                _this.click();
                var _input = $("#textInput");
                var  message = _ajax('你已添加了',attr);
                _input.val(message);
                var _click = document.getElementsByClassName("chatSend");
                _click[0].click();
                isrun=false;
            }
            else if((disp.indexOf('发送好友验证请求')!=-1)&&disp!=''){
                isrun=false;
            }
            else if((disp.indexOf('仔细阅读上述消息')==-1)&&disp!=''){
                _this.click();
                var _input = $("#textInput");
                var  message = _ajax('other',attr);
                _input.val(message);
                var _click = document.getElementsByClassName("chatSend");
                _click[0].click();
                isrun=false;
            }*/

        }
    })
}
function _ajax(disp,attr){
    var message='';
    $.ajax({
        url:'http://112.124.97.72/Auto_Server/autoserver.php',
        async:false,
        type:'GET',
        data:"message="+disp+"&id="+attr,
        success:function(e){
            if(e){
                message = e;
            }
            else{

            }
        }
    })
    return message;
}
var time='3500';
 function run(){
    _autorun = setInterval('start()',time);
}

//alert(1);
var button = "<div id='plugin'><p id='message'>注意待左侧会话列表完全加载完毕之后再点击以下按钮 V1.4.4 只回复第一条版本</p>";
    button+="<button id='weixin_button'>执行脚本</button>";
    button+="<button id='stop'>停止脚本</button>"
    button+="<span>脚本刷新一次时间调整:</span><input type='number' id='frequ' value='3.5'><span>秒</span><button id='sub'>确定</button></div>";
$("body").prepend(button);
$("#weixin_button").click(function(){
    $(this).css({'background':'#30DA59','color':'rgb(253, 248, 248)'});
    $("#stop").css({'background':'#BEC7C0','color':'rgb(14, 9, 9)'})
    run();
})
$("#stop").click(function(){
    $(this).css({'background':'#30DA59','color':'rgb(253, 248, 248)'});
    $("#weixin_button").css({'background':'#BEC7C0','color':'rgb(14, 9, 9)'})
    window.clearInterval(_autorun);
})
$("#sub").click(function(){
    var _second = parseFloat($("#frequ").val());
    if(_second<2){
        alert('刷新时间过短,人数增加较多时可能出现脚本崩溃!请重新设置!');
        $("#frequ").val('3.5');
        time = 3500+"";
    }
    else if(_second>6){
        var is_true = confirm('刷新时间过长,用户可能很长时间接收不到消息,确定需要这样设置吗?');
        if(is_true){
            time = _second*1000+"";
            alert('修改刷新时间后请停止脚本之后再点击执行脚本才能生效.');
        }
        else{
            $("#frequ").val('3.5');
            time = 3500+"";
        }
    }
    else{
        time = _second*1000+"";
        alert('修改刷新时间后请停止脚本之后再点击执行脚本才能生效.');
    }
    console.log("时间修改为:"+time+"毫秒");
})

 

您的支持是我们创作的动力!
温馨提示:本文作者系Terry ,经Web前端之家编辑修改或补充,转载请注明出处和本文链接:
https://jiangweishan.com/article/svg1486483200858.html

网友评论文明上网理性发言已有0人参与

发表评论: