// ==UserScript== // @name 万能验证码自动输入 // @namespace https://www.like996.icu:1205/ // @version 1.6 // @description 在将来的时间里将会在后台默默的为你自动识别页面是否存在验证码并填入。对于一些书写不规整的验证码页面请手动配置规则。 // @author crab // @match http://*/* // @match https://*/* // @require https://cdn.bootcss.com/jquery/3.4.1/jquery.js // @require https://cdn.bootcss.com/blueimp-md5/1.1.0/js/md5.js // @grant GM_setValue // @grant GM_getValue // @grant GM_listValues // @grant GM_openInTab // @grant GM_registerMenuCommand // @nocompat Chrome // @downloadURL none // ==/UserScript== class CaptchaWrite { IdCard() { return "输入您的key,无key用户一小时仅能识别一次"; } getCaptchaServerUrl(){ return "https://www.like996.icu:1205/"; } constructor() { this.Tip = this.AddTip(); if (GM_listValues().indexOf("set") == -1) { GM_setValue("set", { "ApiKey": "" }); var WhetherHelp = confirm("万能验证码填入\n初始化完毕!\n在将来的时间里将会在后台默默的为你\n自动识别页面是否存在验证码并填入。\n对于一些书写不规整的验证码页面请手动配置规则。\n查看添加方法请点击确定。"); if (WhetherHelp == true) { GM_openInTab(this.getCaptchaServerUrl(), 'active') } } Set = GM_getValue("set"); } //手动添加规则 PickUp() { var that = this; var AddRule = {}; var IdentifyResult = ''; that.Hint('请对验证码图片点击右键!') $("img").each(function() { $(this).on("contextmenu", function() { that.Hint('等待识别') var img = that.Aimed($(this)); console.log('PickUp_Img:' + img); IdentifyResult = that.Identify(img,function ManualRule(img,IdentifyResult){ if (img && IdentifyResult) { console.log('记录信息' + img + IdentifyResult); AddRule['img'] = img; $("img").each(function() { $(this).off("click"); $(this).off("on"); $(this).off("load"); }); that.Hint('接下来请点击验证码输入框') $("input").each(function() { $(this).click(function() { var input = that.Aimed($(this)); // console.log('PickUp_input' + input); AddRule['input'] = input; AddRule['path'] = window.location.href; AddRule['title'] = document.title; AddRule['host'] = window.location.host; AddRule['idcard'] = that.IdCard(); that.Write(IdentifyResult,input); //that.WriteResults(AddRule['img'], AddRule['input']) that.Hint('完成') //移除事件 $("input").each(function() { $(this).off("click"); }); //添加信息 that.Query({ "method": "captchaHostAdd", "data": AddRule },function(data){}); that.delCapFoowwLocalStorage(window.location.host); }); }); } }); }); }); } //创建提示元素 AddTip() { var TipHtml = $("
").text("Text."); TipHtml.css({ "background-color": "rgba(211,211,211,0.86)", "align-items": "center", "justify-content": "center", "position": "fixed", "color": "black", "top": "-2em", "height": "2em", "margin": "0em", "padding": "0em", "font-size": "1.2em", "width": "100%", "left": "0", "right": "0", "text-align": "center", "z-index": "9999999999999", "padding-top": "3px", }); $("body").prepend(TipHtml); return TipHtml; } //展示提醒 Hint(Content, Duration) { var that = this; that.Tip.stop(true, false).animate({ top: '-2em' }, 300, function() { that.Tip.html(Content+"X"); }); that.Tip.animate({ top: '0em' }, 500).animate({ top: '0em' }, Duration ? Duration : 3000).animate({ top: '-2em' }, 500) return; } //查询规则 Query(Json,callback) { var that = this; var QueryRule = ''; var LocalStorageData=this.getCapFoowwLocalStorage(Json.method + "_" + Json.data.host); if(Json.method=='captchaHostAdd'){ that.delCapFoowwLocalStorage("captchaHostQuery_"+Json.data.host); LocalStorageData=null; } if(LocalStorageData!=null){ console.log("存在本地缓存的验证码识别规则直接使用。") if(callback!=null){ callback(LocalStorageData); return; }else{ return LocalStorageData; } } $.ajax({ url: that.getCaptchaServerUrl() + Json.method, type: "POST", dateType: 'json', cache: false, async: callback!=null, contentType: "application/json; charset=utf-8", data: JSON.stringify(Json.data), success: function(data) { if (data.info) { that.Hint(data.info); } QueryRule = data; that.setCapFoowwLocalStorage(Json.method + "_" + Json.data.host,data,new Date().getTime()+1000*60) if(callback!=null){ callback(QueryRule); } }, error: function(data) { console.log("error"); } }); return QueryRule; } //开始识别 Start() { //检查配置中是否有此网站 var that = this; var Pathname = window.location.href; var Card = that.IdCard() that.Query({ "method": "captchaHostQuery", "data": { "host": window.location.host, "path": Pathname, "idcard": Card } },function(Rule){ if (Rule.code ==531 || Rule.code ==532) { console.log('有规则执行规则' + Pathname); var data=Rule.data; for(var i=0;i