WordPress系博客验证码 自动填表

支持“胡萝卜周”、“殁漂遥”,理论上是支持 WordPress.com 模板的网站,但是需要自行添加 include

目前為 2020-06-02 提交的版本,檢視 最新版本

// ==UserScript==
// @name             WordPress系博客验证码 自动填表
// @author           极品小猫
// @version          1.0.0
// @description      支持“胡萝卜周”、“殁漂遥”,理论上是支持 WordPress.com 模板的网站,但是需要自行添加 include
// @namespace        https://greasyfork.org/zh-CN/users/3128
// @grant            GM_setValue
// @grant            GM_getValue
// @grant            GM_addStyle
// @grant            GM_xmlhttpRequest
// @grant            unsafeWindow
// @include          http://www.carrotchou.blog/*.html
// @include          https://www.mpyit.com/*.html
// @require          http://cdn.staticfile.org/jquery/2.1.4/jquery.min.js
// @exclude          http*://mail.*
// @run-at           document-idle
// ==/UserScript==

let u=unsafeWindow,
    urls=location.href,
    host=location.hostname,
    hosts=location.hostname.replace(/^www\./i,''),
    paths=location.pathname,
    searchs=location.search.replace(/^\?/,''),
    ToDay=getDate(),
    CodeData={};

if(typeof(GM_getValue('CodeData'))=='undefined') GM_setValue('CodeData', {});
else CodeData=GM_getValue('CodeData');

let WordPress = ['carrotchou.blog', 'mpyit.com']; //WordPress 模板网站清单

let HostList={
    'WordPress':{//WordPress 模板博客通用规则
        'id':'#gogogo, #verifycode',
        'val': '',//默认密码
        'btn':'#verifybtn',
        callback: function(conf, e){

        },
        pre : function(conf, e){
            let config=CodeData[hosts]||{date:"", verifycode:""};

            /*
            //密码检测阶段1,日期不符
            if(!config.date||config.date!==ToDay) {
                config.verifycode=prompt('填写今天的暗号:', config.verifycode);
            }
            */

            //密码检测阶段2,暗号出错
            $('script:not([src]):not([type="text/javascript"])').each(function(){
                if(/暗号出错|验证码错误/.test(this.textContent)) {
                    config.verifycode=prompt('验证码错误,请重写:', config.verifycode);
                }
            });

            //密码检测阶段3,无效密码
            while(!config.verifycode||config.verifycode=='null') config.verifycode=prompt('没有写入暗号,请重写:', config.verifycode);

            config.date=ToDay;
            CodeData[hosts]=config;
            GM_setValue('CodeData', CodeData);

            conf.val=config.verifycode;
            document.body.oncopy=function(){return null;};
            return conf;a
        }
    }
}
for(let i in WordPress) HostList[WordPress[i]]=HostList['WordPress']; //生成 HostList

if(HostList[hosts]) {
    let conf=HostList[hosts];

    if(conf['pre']) conf=conf['pre'](conf);

    $(document).ready(function(){
        //用户名填表
        var t=setInterval(function(){
            if($('#username,[name="username"], #password,[name="password"]').length>0) {
                setTimeout(function(){
                    $('#username,[name="username"]').val(conf.username).keydown();
                    $('#password,[name="password"]').val(conf.password).keydown();
                },100)
                clearInterval(t);
            }
        },1000);

        if(conf['callback']) conf['callback'](conf);
        $(conf['id']).val(conf['val']);
        $(conf['btn']).click();
    });
}


function getDate(type) {
    var myDate = new Date();

    var year=myDate.getFullYear();   //获取当前年
    var month=myDate.getMonth()+1;   //获取当前月
    var day=myDate.getDate();     //获取当前日

    switch(type) {
        case '/': return year+type+month+type+day;
            break;
        default :
            return year+'-'+month+'-'+day;
    }
}