Autoverify-mod

autoverify captcha

当前为 2023-07-12 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.gf.qytechs.cn/scripts/464752/1218738/Autoverify-mod.js

  1. // ==UserScript==
  2. // @name Autoverify-mod
  3. // @license No License
  4. // @namespace https://www.like996.icu:1205/
  5. // @version 6.69
  6. // @description autoverify captcha
  7. // @author crab
  8. // @match http://*/*
  9. // @match https://*/*
  10. // @connect like996.icu
  11. // @connect *
  12. // @require http://libs.baidu.com/jquery/2.0.0/jquery.min.js
  13. // @require http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.0.0.min.js
  14. // @resource cktools https://like996.icu:1205/statics/js/CKTools.js
  15. // @grant GM_setValue
  16. // @grant GM_getValue
  17. // @grant GM_listValues
  18. // @grant GM_openInTab
  19. // @grant GM_registerMenuCommand
  20. // @grant GM_unregisterMenuCommand
  21. // @grant GM_xmlhttpRequest
  22. // @grant GM_getResourceText
  23. // @nocompat Chrome
  24. // ==/UserScript==
  25. class CaptchaWrite {
  26. IdCard() {
  27. return Set["idCard"] == undefined ? "" : Set["idCard"];
  28. }
  29.  
  30. getCaptchaServerUrl() {
  31. return "https://ddd.112114.xyz/";
  32. //return "https://www.like996.icu:1205/";
  33. }
  34.  
  35. constructor() {
  36. this.Tip = this.AddTip();
  37. if (GM_listValues().indexOf("set") == -1) {
  38. var WhetherHelp = confirm("万能验证码填入\n初始化完毕!\n在将来的时间里将会在后台默默的为你\n自动识别页面是否存在验证码并填入。\n对于一些书写不规整的验证码页面请手动添加规则。\n如需查看使用帮助请点击确认。");
  39. }
  40. Set = GM_getValue("set");
  41. Set = Set == undefined ? {} : Set;
  42. // 设置自动识别初始值(注意:此处包含您的识别码,请勿随意发送给他人,否则将会造成泄漏!)
  43. var configSetKeys = {
  44. "autoIdentification": "true",
  45. "showHintCheck": "true",
  46. "warningTone": "false",
  47. "autoBlackList": "false",
  48. "hotKeyToImgResult": "false",
  49. "idCard": undefined
  50. };
  51. $.each(configSetKeys, function (key, val) {
  52. if (Set[key] == undefined) {
  53. Set[key] = val;
  54. GM_setValue("set", Set);
  55. }
  56. });
  57. }
  58.  
  59. // 恢复出厂设置
  60. clearSet() {
  61. var that = this;
  62. let res = confirm('您确认要恢复出厂设置吗?注意:清除后所有内容均需重新设置!');
  63. if (res == true) {
  64. GM_setValue("set", {"idCard": ""});
  65. }
  66. return res;
  67. }
  68.  
  69. // 打开帮助页面
  70. openHelp() {
  71. return GM_openInTab("https://www.like996.icu:1205/help.html", 'active');
  72. }
  73.  
  74. //手动添加英数规则
  75. LetterPickUp() {
  76. let that = this;
  77. let AddRule = {};
  78. let IdentifyResult = '';
  79. that.Hint('请对验证码图片点击右键!', 1000 * 50);
  80. $("canvas,img,input[type='image']").each(function () {
  81. $(this).on("contextmenu mousedown", function (e) {// 为了避免某些hook的拦截
  82. if (e.button != 2) {//不为右键则返回
  83. return;
  84. }
  85. if (that.getCapFoowwLocalStorage("crabAddRuleLock") != null) {
  86. return;
  87. }
  88. that.setCapFoowwLocalStorage("crabAddRuleLock", "lock", new Date().getTime() + 100);//100毫秒内只能1次
  89. let img = that.Aimed($(this));
  90. console.log('[手动添加规则]验证码图片规则为:' + img);
  91. if ($(img).length != 1) {
  92. that.Hint('验证码选择错误,该图片实际对应多个元素。')
  93. return;
  94. }
  95.  
  96. that.Hint('等待识别')
  97. IdentifyResult = that.ImgPathToResult(img, function ManualRule(img, IdentifyResult) {
  98. if (img && IdentifyResult) {
  99. console.log('记录信息' + img + IdentifyResult);
  100. AddRule['img'] = img;
  101. $("img").each(function () {
  102. $(this).off("click");
  103. $(this).off("on");
  104. $(this).off("load");
  105. });
  106. that.Hint('接下来请点击验证码输入框', 1000 * 50);
  107. $("input").each(function () {
  108. $(this).click(function () {
  109. var input = that.Aimed($(this));
  110. // console.log('LetterPickUp_input' + input);
  111. AddRule['input'] = input;
  112. AddRule['path'] = window.location.href;
  113. AddRule['title'] = document.title;
  114. AddRule['host'] = window.location.host;
  115. AddRule['ocr_type'] = 1;
  116. AddRule['idcard'] = that.IdCard();
  117. that.WriteImgCodeResult(IdentifyResult, input);
  118. that.Hint('完成')
  119. //移除事件
  120. $("input").each(function () {
  121. $(this).off("click");
  122. });
  123. //添加信息
  124. that.Query({
  125. "method": "captchaHostAdd", "data": AddRule
  126. }, function (data) {
  127. //////console.log(data);
  128. writeResultIntervals[writeResultIntervals.length] = {"img": img, "input": input}
  129. });
  130. ////////console.log(AddRule);
  131. that.delCapFoowwLocalStorage(window.location.href);
  132. });
  133. });
  134. }
  135. });
  136. });
  137. });
  138. that.sendPostMessage("LetterPickUp")
  139. }
  140.  
  141. //手动添加滑动拼图规则
  142. SlidePickUp() {
  143. crabCaptcha.Hint('请依次点击滑动拼图验证码的大图、小图、滑块(若无法区分请前往官网查看帮助文档)。', 1000 * 50)
  144. $("canvas,img,div,button").each(function () {
  145. $(this).on("contextmenu mousedown click", function (e) {// 为了避免某些hook的拦截
  146. if (e.type != 'click' && e.button != 2) {//不为右键则返回
  147. return;
  148. }
  149. crabCaptcha.onSlideTagClick(e);
  150. });
  151. });
  152.  
  153. crabCaptcha.sendPostMessage("SlidePickUp");
  154. }
  155.  
  156. //递归发送postMessage给iframe中得脚本
  157. sendPostMessage(funName) {
  158. const iframes = document.querySelectorAll("iframe");
  159. iframes.forEach((iframe) => {
  160. iframe.contentWindow.postMessage({
  161. sign: "crab",
  162. action: funName,
  163. }, "*");
  164. });
  165. }
  166.  
  167. // 添加滑动拼图规则
  168. onSlideTagClick(e) {
  169. var that = this;
  170. let el = e.target;
  171. let tagName = el.tagName.toLowerCase();
  172. let eleWidth = Number(that.getNumber(that.getElementStyle(el).width)) || 0;
  173. let eleHeight = Number(that.getNumber(that.getElementStyle(el).height)) || 0;
  174. let eleTop = Number($(el).offset().top) || 0;
  175. let storagePathCache = that.getCapFoowwLocalStorage("slidePathCache");
  176. let ruleCache = (storagePathCache && storagePathCache) || {ocr_type: 4};
  177.  
  178. if (tagName === "img") {
  179. if (eleWidth >= eleHeight && eleWidth > 150) {
  180. ruleCache['big_image'] = that.Aimed(el);
  181. that.setCapFoowwLocalStorage("slidePathCache", ruleCache, new Date().getTime() + 1000 * 60);
  182. that.Hint('您已成功选择大图片。', 5000);
  183. that.checkTargetNeedZIndex(ruleCache, el);
  184. } else if (eleWidth < 100 && eleWidth > 15 && eleHeight >= eleWidth - 5) {
  185. ruleCache['small_image'] = that.Aimed(el);
  186. that.setCapFoowwLocalStorage("slidePathCache", ruleCache, new Date().getTime() + 1000 * 60);
  187. that.Hint('您已成功选择小图片。', 5000);
  188. that.checkTargetNeedZIndex(ruleCache, el);
  189. }
  190. } else {
  191. let curEl = el;
  192. for (let i = 0; i < 3; i++) {
  193. if (!curEl || curEl === Window) {
  194. break;
  195. }
  196. let position = that.getElementStyle(curEl).position;
  197. let bgUrl = that.getElementStyle(curEl)["backgroundImage"];
  198. eleWidth = Number(that.getNumber(that.getElementStyle(curEl).width)) || 0;
  199. eleHeight = Number(that.getNumber(that.getElementStyle(curEl).height)) || 0;
  200.  
  201. if (position === "absolute" && eleWidth < 100 && eleHeight < 100) {
  202. //如果是绝对定位,并且宽高小于100,基本上就是滑块了
  203. var smallImgRule = null;
  204. if (storagePathCache != null && (smallImgRule = storagePathCache['small_image']) != null) {
  205. //检查一下滑块是否比小图低
  206. if ($(smallImgRule).offset().top < eleTop) {
  207. ruleCache['move_item'] = that.Aimed(curEl);
  208. that.setCapFoowwLocalStorage("slidePathCache", ruleCache, new Date().getTime() + 1000 * 60);
  209. that.Hint('您已成功选择滑块。', 5000);
  210. break;
  211. }
  212. }
  213. }
  214. let reg = /url\("(.+)"\)/im;
  215. if (bgUrl && bgUrl.match(reg)) {
  216. // 根据背景图去做操作
  217. if (eleWidth >= eleHeight && eleWidth > 150) {
  218. ruleCache['big_image'] = that.Aimed(el);
  219. that.Hint('您已成功选择大图片。', 5000);
  220. that.setCapFoowwLocalStorage("slidePathCache", ruleCache, new Date().getTime() + 1000 * 60);
  221. that.checkTargetNeedZIndex(ruleCache, curEl);
  222. break;
  223. } else if (eleWidth < 100 && eleWidth > 15 && eleHeight >= eleWidth - 5) {
  224. ruleCache['small_image'] = that.Aimed(el);
  225. that.Hint('您已成功选择小图片。', 5000);
  226. that.setCapFoowwLocalStorage("slidePathCache", ruleCache, new Date().getTime() + 1000 * 60);
  227. that.checkTargetNeedZIndex(ruleCache, curEl);
  228. break;
  229. }
  230. }
  231. if (tagName === "canvas") {
  232. // 如果是canvas 直接寻找class中特定样式
  233. if (that.checkClassName(curEl, "canvas_bg") || that.checkClassName(curEl.parentNode, "captcha_basic_bg")) {
  234. ruleCache['big_image'] = that.Aimed(el);
  235. that.Hint('您已成功选择大图片。', 5000);
  236. that.setCapFoowwLocalStorage("slidePathCache", ruleCache, new Date().getTime() + 1000 * 60);
  237. that.checkTargetNeedZIndex(ruleCache, curEl);
  238. break;
  239. } else if (that.checkClassName(curEl, "canvas_slice")) {
  240. ruleCache['small_image'] = that.Aimed(el);
  241. that.Hint('您已成功选择小图片。', 5000);
  242. that.setCapFoowwLocalStorage("slidePathCache", ruleCache, new Date().getTime() + 1000 * 60);
  243. that.checkTargetNeedZIndex(ruleCache, curEl);
  244. break;
  245. }
  246. }
  247.  
  248. curEl = curEl.parentNode;
  249. }
  250.  
  251. curEl = el;
  252. const firstImg = curEl.querySelector("img");
  253. firstImg && that.onSlideTagClick({target: firstImg});
  254. }
  255. const finish = Object.keys(ruleCache).filter((item) => item).length == 4;
  256. if (finish) {
  257. $("canvas,img,div").each(function () {
  258. $(this).off("click");
  259. });
  260.  
  261. var AddRule = {};
  262. AddRule['path'] = window.location.href;
  263. AddRule['title'] = document.title;
  264. AddRule['host'] = window.location.host;
  265. AddRule['idcard'] = that.IdCard();
  266.  
  267. for (var key in ruleCache) {
  268. AddRule[key] = ruleCache[key];
  269. }
  270.  
  271. //添加规则
  272. ////console.log("AddRule:" + AddRule);
  273. that.Query({"method": "captchaHostAdd", "data": AddRule});
  274.  
  275. that.Hint('规则添加完毕,开始识别中。', 5000);
  276. ruleCache.ocrType = 4;
  277. writeResultIntervals[writeResultIntervals.length] = ruleCache;
  278. that.checkSlideCaptcha(ruleCache);
  279. that.delCapFoowwLocalStorage("slidePathCache")
  280. }
  281. }
  282.  
  283. /**
  284. * 判断是否存在指定className
  285. * @param curEl
  286. * @param Name
  287. * @returns {boolean}
  288. */
  289. checkClassName(curEl, Name) {
  290. var a = curEl.classList;
  291. for (var i = 0; i < a.length; i++) {
  292. if (a[i].indexOf(Name) != -1) {
  293. return true;
  294. }
  295. }
  296. return false;
  297. }
  298.  
  299. /**
  300. * 判断判断滑块元素是否需要降级
  301. * @param curEl
  302. * @param Name
  303. * @returns {boolean}
  304. */
  305. checkTargetNeedZIndex(ruleCache, curEl) {
  306. if (ruleCache['big_image'] != null && ruleCache['small_image'] != null) {
  307. $(ruleCache['big_image']).css("z-index", "9998");
  308. $(ruleCache['small_image']).css("z-index", "9999");
  309. } else {
  310. $(curEl).css("z-index", "-1");
  311. }
  312. return false;
  313. }
  314.  
  315. // 检查滑动拼图验证码并识别
  316. checkSlideCaptcha(slideCache) {
  317. var that = this;
  318. const {big_image, small_image, move_item} = slideCache;
  319.  
  320. document.querySelector(big_image).onload = function () {
  321. that.checkSlideCaptcha(slideCache);
  322. }
  323.  
  324. //判断验证码是否存在并可见
  325. if (!big_image || !small_image || !move_item || document.querySelector(small_image) == null
  326. || document.querySelector(big_image) == null || document.querySelector(move_item) == null
  327. || !$(small_image).is(":visible") || !$(big_image).is(":visible") || !$(move_item).is(":visible")) {
  328. console.log("滑动拼图验证码不可见,本次不识别");
  329. return;
  330. }
  331.  
  332.  
  333. const check = async () => {
  334. var Results = that.getCapFoowwLocalStorage("验证码滑动整体超时锁");
  335. if (Results != null) {
  336. return;
  337. }
  338. console.log("滑动拼图验证码出现,准备开始识别");
  339. var bigImgElem = document.querySelector(big_image);
  340. var smallImgElem = document.querySelector(small_image);
  341. var moveItemElem = document.querySelector(move_item);
  342.  
  343. const big_base64 = await that.ImgElemToBase64(bigImgElem);
  344. const small_base64 = await that.ImgElemToBase64(smallImgElem);
  345. if (small_base64 == null || big_base64 == null) {
  346. console.log("滑动拼图验证码为null");
  347. return;
  348. }
  349.  
  350. var big_base64Hash = that.strHash(big_base64);
  351. if (that.getCapFoowwLocalStorage("滑块识别缓存:" + big_base64Hash) != null) {
  352. return;
  353. }
  354. that.setCapFoowwLocalStorage("滑块识别缓存:" + big_base64Hash, "同一个滑块仅识别一次", new Date().getTime() + (1000 * 60 * 60));//同一个滑块1小时内仅识别一次
  355. this.Hint("开始滑动, 在下一条提示之前,请勿操作鼠标!", 5000)
  356.  
  357. let bigWidth = that.getNumber(that.getElementStyle(bigImgElem)['width']);
  358. let smallWidth = that.getNumber(that.getElementStyle(smallImgElem)['width']);
  359.  
  360. var postData = {
  361. big_image: big_base64,
  362. small_image: small_base64,
  363. big_image_width: bigWidth,
  364. small_image_width: smallWidth,
  365. ocr_type: 4
  366. }
  367. var img_json = {"target_img": small_base64,'bg_img':big_base64}
  368. var imgjson_str = JSON.stringify(img_json);
  369. var postData_dddd = {
  370. img: btoa(imgjson_str),
  371. ocr_type: 4
  372. }
  373. //console.log("postData: "+postData_dddd);
  374.  
  375. //that.Identify_Crab(null, postData, function Slide(data) {
  376. that.Identify_Crab(null, postData_dddd, function Slide(data) {
  377. //console.log("等待滑动距离:" + "20")
  378. console.log("等待滑动距离:" + data.data)
  379. that.moveSideCaptcha(smallImgElem, moveItemElem, data);
  380. });
  381. };
  382. check();
  383. }
  384.  
  385. //手动添加滑块行为规则
  386. slideBehaviorRule() {
  387. crabCaptcha.Hint('请点击一次滑块。注意:滑块行为类验证码仅有一个滑块!', 1000 * 50)
  388. $("canvas,img,div,button,span").each(function () {
  389. $(this).on("contextmenu mousedown click", function (e) {// 为了避免某些hook的拦截
  390. if (e.type != 'click' && e.button != 2) {//不为右键则返回
  391. return;
  392. }
  393. crabCaptcha.onSlideBehaviorClick(e);
  394. });
  395. });
  396.  
  397. crabCaptcha.sendPostMessage("slideBehaviorRule");
  398. }
  399.  
  400. // 添加滑块行为规则
  401. onSlideBehaviorClick(e) {
  402. var that = this;
  403. let el = e.target;
  404. let eleWidth = Number(that.getNumber(that.getElementStyle(el).width)) || 0;
  405. let eleHeight = Number(that.getNumber(that.getElementStyle(el).height)) || 0;
  406. let storagePathCache = that.getCapFoowwLocalStorage("slidePathCache");
  407.  
  408.  
  409. let curEl = el;
  410. for (let i = 0; i < 3; i++) {
  411. if (!curEl || curEl === Window) {
  412. break;
  413. }
  414. let position = that.getElementStyle(curEl).position;
  415. eleWidth = Number(that.getNumber(that.getElementStyle(curEl).width)) || 0;
  416. eleHeight = Number(that.getNumber(that.getElementStyle(curEl).height)) || 0;
  417.  
  418. if (position === "absolute" && eleWidth < 100 && eleHeight < 100) {
  419. //如果是绝对定位,并且宽高小于100,基本上就是滑块了
  420. $("canvas,img,div").each(function () {
  421. $(this).off("click");
  422. });
  423. let AddRule = (storagePathCache && storagePathCache) || {ocr_type: 5};
  424. AddRule['path'] = window.location.href;
  425. AddRule['title'] = document.title;
  426. AddRule['host'] = window.location.host;
  427. AddRule['move_item'] = that.Aimed(curEl);
  428. AddRule['idcard'] = that.IdCard();
  429.  
  430. //添加规则
  431. //console.log('Addrule:');
  432. //console.log(AddRule);
  433. that.Query({"method": "captchaHostAdd", "data": AddRule});
  434.  
  435. that.Hint('规则添加完毕,开始识别中。', 5000);
  436. AddRule.ocrType = 5;
  437. writeResultIntervals[writeResultIntervals.length] = AddRule;
  438. that.checkSlideBehaviorCaptcha(AddRule);
  439. that.delCapFoowwLocalStorage("slidePathCache")
  440. that.Hint('您已成功选择滑块。', 5000);
  441. break;
  442. }
  443. curEl = curEl.parentNode;
  444. }
  445. }
  446.  
  447. // 检查滑块行为验证码并识别
  448. checkSlideBehaviorCaptcha(slideCache) {
  449. var that = this;
  450. const {move_item} = slideCache;
  451.  
  452. //判断验证码是否存在并可见
  453. if (!move_item || document.querySelector(move_item) == null || !$(move_item).is(":visible")) {
  454. // console.log("滑块行为验证码不可见,本次不识别");
  455. return;
  456. }
  457.  
  458. const check = async () => {
  459. var Results = that.getCapFoowwLocalStorage("验证码滑动整体超时锁");
  460. if (Results != null) {
  461. return;
  462. }
  463. console.log("滑块行为验证码出现,准备开始识别");
  464. var moveItemElem = document.querySelector(move_item);
  465.  
  466. let moveItemParentElemStyles = that.getElementStyle(moveItemElem.parentNode);
  467. let moveItemElemStyles = that.getElementStyle(moveItemElem);
  468. let left = that.getNumber(moveItemElemStyles.left);
  469. let small_image_width = that.getNumber(moveItemParentElemStyles.width);
  470. if (left != 0) {
  471. return;
  472. }
  473. if (that.getCapFoowwLocalStorage("滑块行为识别缓存:" + small_image_width) != null) {
  474. return;
  475. }
  476. that.setCapFoowwLocalStorage("滑块行为识别缓存:" + small_image_width, "同一个滑块仅识别一次", new Date().getTime() + (1000 * 60));
  477. this.Hint("开始滑动, 在下一条提示之前,请勿操作鼠标!", 5000)
  478.  
  479. var postData = {
  480. small_image: "5oqx5q2J77yM5Li65LqG56iL5bqP55qE5Y+R5bGV5Y+v5o6n77yM5q2k5aSE5b+F6aG75Lyg5Y+C5Yiw5LqR56uv44CC",
  481. small_image_width: small_image_width,
  482. salt: new Date().getTime(),
  483. ocr_type: 5
  484. }
  485.  
  486. //that.Identify_Crab_origin(null, postData, function Slide(data) {
  487. that.Identify_Crab(null, postData, function Slide(data) {
  488. console.log("等待滑动距离:" + data.data)
  489. that.moveSideCaptcha(moveItemElem, moveItemElem, data);
  490. that.delCapFoowwLocalStorage("滑块行为识别缓存:" + small_image_width);
  491. });
  492. };
  493. check();
  494. }
  495.  
  496. /**
  497. * 滑动事件
  498. * @param targetImg 小图片
  499. * @param moveItem 按钮
  500. * @param distance 滑动距离
  501. */
  502. moveSideCaptcha(targetImg, moveItem, data) {
  503. var that = this;
  504. //var distance = 20
  505. var distance = data.data
  506. if (distance === 0) {
  507. console.log("滑动距离不可为0", distance);
  508. return;
  509. }
  510. var btn = moveItem;
  511. let target = targetImg;
  512.  
  513. // 剩余滑动距离
  514. let varible = null;
  515. // 上次剩余滑动距离(可能存在识别错误滑到头了滑不动的情况)
  516. let oldVarible = null;
  517. // 获得初始滑块左侧距离
  518. let targetLeft = that.getNumber(that.getElementStyle(target).left) || 0;
  519. let targetMargin = that.getNumber(that.getElementStyle(target).marginLeft) || 0;
  520. let targetParentLeft = that.getNumber(that.getElementStyle(target.parentNode).left) || 0;
  521. let targetTransform = that.getNumber(that.getEleTransform(target)) || 0;
  522. let targetParentTransform = that.getNumber(that.getEleTransform(target.parentNode)) || 0;
  523. // 两个元素距离屏幕左侧的差距(用于后期取不到滑动距离切换参照物的差值)
  524. let eledifference=moveItem.getBoundingClientRect().x-targetImg.getBoundingClientRect().x;
  525.  
  526.  
  527. var rect = btn.getBoundingClientRect();
  528. //鼠标指针在屏幕上的坐标;
  529. var screenX = rect.x;
  530. var screenY = rect.y;
  531. //鼠标指针在浏览器窗口内的坐标;
  532. //var clientX = rect.width / 2 - 2;
  533. //var clientY = rect.height / 2 - 2;
  534. var clientX = screenX+rect.width / 2 - 2;
  535. var clientY = screenY+rect.height / 2 - 2;
  536.  
  537. // 初始化 MouseEvent 对象
  538. const mousedown = new MouseEvent("mousedown", {
  539. bubbles: true,
  540. cancelable: true,
  541. view: document.defaultView,
  542. detail: 0,
  543. screenX: screenX,
  544. screenY: screenY,
  545. clientX: clientX,
  546. clientY: clientY,
  547. });
  548. btn.dispatchEvent(mousedown);
  549.  
  550. var dx = 0;
  551. var dy = 0;
  552. // 总滑动次数
  553. var sideCount = 0;
  554. // 滑不动了的次数
  555. var sideMaxCount = 0;
  556.  
  557. //持续滑动
  558. function continueSide() {
  559. setTimeout(function () {
  560. var intervalLock = that.getCapFoowwLocalStorage("验证码滑动整体超时锁");
  561. if (intervalLock == null) {
  562. that.setCapFoowwLocalStorage("验证码滑动整体超时锁", {time: new Date().getTime()}, new Date().getTime() + (1000 * 10));
  563. } else {
  564. // 采用自解开锁模式
  565. if (intervalLock.time + 1000 * 3 < new Date().getTime()) {
  566. that.Hint("本次滑动超时请刷新验证码后重试,若该页面多次出现此问题请联系群内志愿者处理。", 2000);
  567. that.finishSide(btn, distance, 0, distance, 0);
  568. return;
  569. }
  570. }
  571.  
  572. //鼠标指针在屏幕上的坐标
  573. var _screenX = screenX + dx;
  574. var _screenY = screenY + dy;
  575. //鼠标指针在浏览器窗口内的坐标
  576. var _clientX = clientX + dx;
  577. var _clientY = clientY + dy;
  578. sideCount += 1;
  579.  
  580. const mousemove = new MouseEvent('mousemove', {
  581. bubbles: true,
  582. cancelable: true,
  583. view: document.defaultView,
  584. screenX: _screenX,
  585. screenY: _screenY,
  586. clientX: _clientX,
  587. clientY: _clientY
  588. });
  589. btn.dispatchEvent(mousemove);
  590.  
  591. if (sideCount > 3 && varible == null && btn != null) {
  592. //如果3次循环了已滑动的距离还是null,则使用按钮的距离
  593. console.log("使用按钮得距离计算剩余")
  594. let targetWidth = that.getNumber(that.getElementStyle(target).width);
  595. let btnWidth = that.getNumber(that.getElementStyle(btn).width);
  596. //正常来说,小图片应该比滑块的宽度小,此处做*2加权判断
  597. if (targetWidth < btnWidth * 2) {
  598. // 滑块一般贴近左边,而小图可能稍稍向右,所以总滑动距离-滑块得差
  599. //distance = that.getNumber(distance) + (targetWidth - btnWidth);
  600. distance = that.getNumber(distance) + eledifference;
  601. }else{
  602. distance=distance-2.5;
  603. }
  604. target = btn;
  605. }
  606. let newTargetLeft = that.getNumber(that.getElementStyle(target).left) || 0;
  607. let newTargetMargin = that.getNumber(that.getElementStyle(target).marginLeft) || 0;
  608. let newTargetParentLeft = that.getNumber(that.getElementStyle(target.parentNode).left) || 0;
  609. let newTargetTransform = that.getNumber(that.getEleTransform(target)) || 0;
  610. let newTargetParentTransform = that.getNumber(that.getEleTransform(target.parentNode)) || 0;
  611.  
  612. if (newTargetLeft !== targetLeft) {
  613. varible = newTargetLeft;
  614. targetLeft = newTargetLeft;
  615. } else if (newTargetParentLeft !== targetParentLeft) {
  616. varible = newTargetParentLeft;
  617. targetParentLeft = newTargetParentLeft;
  618. } else if (newTargetTransform !== targetTransform) {
  619. varible = newTargetTransform;
  620. targetTransform = newTargetTransform;
  621. } else if (newTargetParentTransform != targetParentTransform) {
  622. varible = newTargetParentTransform;
  623. targetParentTransform = varible;
  624. } else if (newTargetMargin != targetMargin) {
  625. varible = newTargetMargin;
  626. targetMargin = newTargetMargin;
  627. }
  628.  
  629. if (varible != null && varible != 0) {
  630. if (varible == oldVarible) {
  631. //发现滑不动了
  632. sideMaxCount += 1;
  633. } else {
  634. sideMaxCount = 0;
  635. }
  636. }
  637. // 容错值
  638. var fault = 1;
  639. //判断剩余距离是否大于要滑动得距离(1像素误差),或者滑不动了
  640. if (varible != null && (sideMaxCount > 5 || (varible == distance || (varible > distance && varible - fault <= distance) || (varible < distance && varible + fault >= distance)))) {
  641. console.log("滑动完毕,等待清除事件");
  642. that.finishSide(btn, _screenX, _screenY, _clientX, _clientY);
  643. //that.Hint(data.description, data.showTime)
  644. that.Hint(data.description)
  645. } else {
  646. oldVarible = varible;
  647. //本次需要滑出去得距离
  648. var tempDistance = 0;
  649. // 剩余距离(总距离-已滑动距离)
  650. var residue = distance - varible;
  651. var avg = distance / 10;
  652.  
  653. // 判断距离,计算速度
  654. if (residue > distance / 2) {//距离有一半时,距离较较远,可以高速
  655. tempDistance = Math.ceil((Math.random() * (6 - 10) + 10) * 2);
  656. } else if (residue > distance / 4) {//距离有四分之一时,距离较近了,开始减速
  657. tempDistance = Math.ceil((Math.random() * (4 - 5) + 5));
  658. } else if (residue > avg) {//四分之一到十分之一
  659. tempDistance = Math.ceil((Math.random() * (1 - 2) + 1));
  660. } else if (residue < avg) {//最后十分之一
  661. tempDistance = 0.5;
  662. }
  663.  
  664. // 作者在叨叨:如果这段代码能够帮到你,如果你愿意,可以请我喝杯咖啡么?
  665. // 总滑动距离较近,慢点滑动
  666. if (avg <= 12) {
  667. tempDistance = tempDistance / 1.5;
  668. }
  669.  
  670. //超过了就让他倒着走
  671. if (residue <= 0) {
  672. tempDistance = tempDistance * -1;
  673. }
  674.  
  675. dx += tempDistance;
  676.  
  677. // 随机定义y得偏差
  678. let sign = Math.random() > 0.5 ? -1 : 1;
  679. dy += Math.ceil(Math.random() * 2 * sign);
  680.  
  681. //再次执行
  682. continueSide();
  683. }
  684. }, Math.floor(Math.random() * 15) + 10);
  685. }
  686.  
  687. continueSide();
  688. }
  689.  
  690. // 完成滑动
  691. finishSide(btn, _screenX, _screenY, _clientX, _clientY) {
  692. var that = this;
  693. var mouseup = new MouseEvent("mouseup", {
  694. bubbles: true,
  695. cancelable: true,
  696. view: document.defaultView,
  697. clientX: _clientX,
  698. clientY: _clientY,
  699. screenX: _screenX,
  700. screenY: _screenY
  701. });
  702. setTimeout(() => {
  703. btn.dispatchEvent(mouseup);
  704. console.log("滑动完毕,释放鼠标");
  705. }, Math.ceil(Math.random() * 500));
  706. //1秒后解除全局锁,避免网速慢导致验证码刷新不出来
  707. setTimeout(() => {
  708. that.delCapFoowwLocalStorage("验证码滑动整体超时锁");
  709. }, 1000);
  710.  
  711. }
  712.  
  713. getEleTransform(el) {
  714. const style = window.getComputedStyle(el, null);
  715. var transform = style.getPropertyValue("-webkit-transform") || style.getPropertyValue("-moz-transform") || style.getPropertyValue("-ms-transform") || style.getPropertyValue("-o-transform") || style.getPropertyValue("transform") || "null";
  716. return transform && transform.split(",")[4];
  717. }
  718.  
  719. // 字符串转数字
  720. getNumber(str) {
  721. try {
  722. return Number(str.split(".")[0].replace(/[^0-9]/gi, ""));
  723. } catch (e) {
  724. return 0;
  725. }
  726. }
  727.  
  728.  
  729. //创建提示元素
  730. AddTip() {
  731. var TipHtml = $("<div id='like996_identification'></div>").text("Text.");
  732. TipHtml.css({
  733. "background-color": "rgba(211,211,211,0.86)",
  734. "align-items": "center",
  735. "justify-content": "center",
  736. "position": "fixed",
  737. "color": "black",
  738. "top": "-5em",
  739. "height": "2em",
  740. "margin": "0em",
  741. "padding": "0em",
  742. "font-size": "20px",
  743. "width": "100%",
  744. "left": "0",
  745. "right": "0",
  746. "text-align": "center",
  747. "z-index": "9999999999999",
  748. "padding-top": "3px",
  749. display: 'none'
  750.  
  751. });
  752. $("body").prepend(TipHtml);
  753. return TipHtml;
  754. }
  755.  
  756. //展示提醒
  757. Hint(Content, Duration) {
  758. if (Set["showHintCheck"] != "true") {
  759. return;
  760. }
  761. if (self != top) {
  762. // 如果当前在iframe中,则让父页面去提示
  763. window.parent.postMessage({
  764. sign: "crab",
  765. action: "Hint",
  766. postData: {Content: Content, Duration: Duration}
  767. }, "*");
  768. return;
  769. }
  770. // 处理一下对象传值(很奇怪,这玩意传到最后回出来两层,谁研究透了麻烦告诉我一下)
  771. while (Content?.constructor === Object) {
  772. Content = Content.Content;
  773. Duration = Content.Duration;
  774. }
  775.  
  776. var that = crabCaptcha;
  777.  
  778. that.Tip.stop(true, false).animate({
  779. top: '-5em'
  780. }, 300, function () {
  781. if (Set["warningTone"] == "true") {
  782. Content += that.doWarningTone(Content)
  783. }
  784. Content += "<span style='color:red;float: right;margin-right: 20px;' onclick='document.getElementById(\"like996_identification\").remove()'>X</span>";
  785. that.Tip.show();
  786. that.Tip.html(Content);
  787.  
  788. });
  789. that.Tip.animate({
  790. top: '0em'
  791. }, 500).animate({
  792. top: '0em'
  793. }, Duration ? Duration : 3000).animate({
  794. top: '-5em'
  795. }, 500, function () {
  796. that.Tip.hide();
  797. });
  798. return;
  799. }
  800.  
  801. //查询规则
  802. Query(Json, callback) {
  803. var that = this;
  804. var QueryRule = '';
  805. var LocalStorageData = this.getCapFoowwLocalStorage(Json.method + "_" + Json.data.href);
  806. if (Json.method == 'captchaHostAdd') {
  807. //that.delCapFoowwLocalStorage("captchaHostQuery_" + Json.data.host);
  808. that.delCapFoowwLocalStorage("captchaHostQuery_" + Json.data.href);
  809. LocalStorageData = null;
  810. //清除自动查找验证码功能
  811. clearInterval(this.getCapFoowwLocalStorage("autoRulesIntervalID"));
  812. }
  813. if (LocalStorageData != null) {
  814. console.log("存在本地缓存的验证码识别规则直接使用。")
  815. if (callback != null) {
  816. callback(LocalStorageData);
  817. return;
  818. } else {
  819. return LocalStorageData;
  820. }
  821. }
  822. //////////////////////////console.log(JSON.stringify(Json));
  823. GM_xmlhttpRequest({
  824. url: that.getCaptchaServerUrl() + Json.method,
  825. method: 'POST',
  826. headers: {'Content-Type': 'application/json; charset=utf-8', 'path': window.location.href},
  827. data: JSON.stringify(Json.data),
  828. responseType: "json",
  829. onload: obj => {
  830. var data = obj.response;
  831. ////console.log('captchaHostQuery_查询返回的结果 ' + data.data[0]);
  832. //////////if (data.description != undefined) {
  833. ////////// that.Hint(data.description)
  834. //////////}
  835. QueryRule = data;
  836. that.setCapFoowwLocalStorage(Json.method + "_" + Json.data.path, data, new Date().getTime() + 1000 * 60)
  837. if (callback != null) {
  838. callback(QueryRule);
  839. }
  840.  
  841. },
  842. onerror: err => {
  843. console.log(err)
  844. }
  845. });
  846.  
  847.  
  848. return QueryRule;
  849. }
  850.  
  851. //开始识别
  852. Start() {
  853. //检查配置中是否有此网站
  854. var that = this;
  855. var Pathname = window.location.href;
  856. var Card = that.IdCard();
  857. if (Set["hotKeyToImgResult"] != "true") {
  858. writeResultInterval = setInterval(function () {
  859. that.WriteResultsInterval();
  860. }, 500);
  861. } else {
  862. crabCaptcha.crabFacebook()
  863. }
  864. //console.log(Card);
  865. that.Query({
  866. "method": "captchaHostQuery", "data": {
  867. "host": window.location.host, "path": Pathname, "idcard": Card
  868. }
  869. }, function (Rule) {
  870. ///////////////////////////////////////console.log("captchaHostQuery查询返回的规则: " + JSON.stringify(Rule))
  871. if (Rule.code == 531 || Rule.code == 532) {
  872. console.log('有规则执行规则' + Pathname);
  873. var data = Rule.data;
  874. //data[0]['img'] = data[0]['img'].replace("'&'",'\\"&\\"');
  875. ////////////////////////////////////console.log(data);
  876. for (var i = 0; i < data.length; i++) {
  877. writeResultIntervals[i] = data[i];
  878. }
  879. ////////////////////////////////////////console.log(writeResultIntervals);
  880. console.log('等待验证码图片出现');
  881. } else if (Rule.code == 530) {
  882. console.log('黑名单' + Pathname);
  883. if (that.getCapFoowwLocalStorage("网站黑名单提示锁") == null) {
  884. that.setCapFoowwLocalStorage("网站黑名单提示锁", "lock", new Date().getTime() + 9999999 * 9999999);//网页黑名单单位时间内仅提示一次
  885. that.Hint('该网站在黑名单中,无法识别。', 5000);
  886. }
  887. return
  888. } else if (Rule.code == 533 && Set["autoIdentification"] == "true") {
  889. //如果当前网页无规则,则启动自动查找验证码功能(无法一直执行否则将大量错误识别!)
  890. console.log('新网站开始自动化验证码查找' + Pathname);
  891. const autoRulesIntervalID = setInterval(function () {
  892. var MatchList = that.AutoRules();
  893. if (MatchList.length) {
  894. //改为定时器绑定,解决快捷键失效问题
  895. writeResultIntervals.splice(0);
  896. console.log('检测到新规则,开始绑定元素');
  897. for (i in MatchList) {
  898. writeResultIntervals[i] = MatchList[i];
  899. }
  900. }
  901. }, 1000);
  902. that.setCapFoowwLocalStorage("autoRulesIntervalID", autoRulesIntervalID, new Date().getTime() + (99999 * 99999));
  903. }
  904. });
  905.  
  906.  
  907. const actions = {
  908. SlidePickUp: that.SlidePickUp,
  909. LetterPickUp: that.LetterPickUp,
  910. slideBehaviorRule: that.slideBehaviorRule,
  911. Hint: that.Hint,
  912. };
  913.  
  914. window.addEventListener(
  915. "message",
  916. (event) => {
  917. const {data = {}} = event || {};
  918. const {sign, action, postData} = data;
  919. if (sign === "crab") {
  920. if (action && actions[action]) {
  921. actions[action](postData);
  922. }
  923. }
  924. },
  925. false
  926. );
  927.  
  928. }
  929.  
  930. // 定时执行绑定验证码img操作
  931. WriteResultsInterval() {
  932. for (var i = 0; i < writeResultIntervals.length; i++) {
  933. var ocrType = writeResultIntervals[i].ocrType;
  934. if (!ocrType) {ocrType = writeResultIntervals[i].ocr_type;}
  935. //console.log(ocrType);
  936. if (!ocrType || ocrType == 1) {
  937. // 英数验证码
  938. var imgAddr = writeResultIntervals[i].img;
  939. if (imgAddr && imgAddr.indexOf('this.src') !=-1) {imgAddr = writeResultIntervals[i].img.replaceAll("'",'"').replace('"&"',"'&'").replace('"?"',"'?'");}
  940. //console.log(imgAddr);
  941. var inputAddr = writeResultIntervals[i].input;
  942. if (document.querySelector(imgAddr) == null || document.querySelector(inputAddr) == null) {
  943. continue;
  944. }
  945. try {
  946. if (this.getCapFoowwLocalStorage("err_" + writeResultIntervals[i].img) == null) {// 写入识别规则之前,先判断她是否有错误
  947. this.RuleBindingElement(imgAddr, inputAddr);
  948. }
  949. } catch (e) {
  950. window.clearInterval(writeResultInterval);
  951. this.addBadWeb(imgAddr, inputAddr);
  952. return;
  953. }
  954. } else if (ocrType == 4) {
  955. //滑动拼图验证码
  956. var big_image = writeResultIntervals[i].big_image;
  957. var small_image = writeResultIntervals[i].small_image;
  958. if (document.querySelector(big_image) == null) {
  959. continue;
  960. }
  961. if (document.querySelector(small_image) == null) {
  962. continue;
  963. }
  964.  
  965. this.checkSlideCaptcha(writeResultIntervals[i]);
  966. } else if (ocrType == 5) {
  967. //滑块行为验证码
  968. var move_item = writeResultIntervals[i].move_item;
  969. if (document.querySelector(move_item) == null) {
  970. continue;
  971. }
  972. this.checkSlideBehaviorCaptcha(writeResultIntervals[i]);
  973. }
  974. }
  975. }
  976.  
  977.  
  978.  
  979. //调用识别接口
  980. Identify_Crab(img, postData, callback) {
  981. var that = this;
  982. var postDataHash = that.strHash(JSON.stringify(postData));
  983. var Results = that.getCapFoowwLocalStorage("识别结果缓存:" + postDataHash);
  984. if (Results != null) {
  985. if (callback.name != 'ManualRule') {// 不为手动直接返回结果
  986. return Results.data;
  987. }
  988. }
  989. postData["idCard"] = that.IdCard();
  990. postData["version"] = "5.1";
  991. var duration = postData["small_image_width"]
  992. that.setCapFoowwLocalStorage("识别结果缓存:" + postDataHash, "识别中..", new Date().getTime() + (9999999 * 9999999));//同一个验证码只识别一次
  993. ////////////////////////////////////////console.log("调用接口提交的data: " + postData);
  994. var url = that.getCaptchaServerUrl() + "ocr/b64/json";
  995. if (postData['ocr_type'] == 4) {url = that.getCaptchaServerUrl() + "slide/match/b64/json"}
  996. ///////////////////////////////////////////console.log(url);
  997. //var url = that.getCaptchaServerUrl() + "ocr/b64/json";
  998. //var url = that.getCaptchaServerUrl() + "/hello";
  999. console.log("验证码变动,开始识别");
  1000. var imgb64 = postData['img'];
  1001. //console.log(imgb64);
  1002. GM_xmlhttpRequest({
  1003. url: url,
  1004. method: 'POST',
  1005. //headers: {'Content-Type': 'application/json; charset=UTF-8', 'path': window.location.href},
  1006. data: imgb64,
  1007. timeout: 5000,
  1008. //data: JSON.stringify(postData),
  1009. responseType: "json",
  1010. onload: obj => {
  1011. var data = obj.response;
  1012. var Results = JSON.stringify(data.result);
  1013. /////////////////////////////////////console.log("调用接口获取的结果: " + Results);
  1014. if (postData['ocr_type'] == 4) {Results = JSON.stringify(data.result.target);data['data'] = data['result']['target'][0];data["description"] = "识别完成";}
  1015. if (postData['ocr_type'] == 5) {data['data'] = duration + 20 ;data['result'] = 'slide';data['msg'] = null;data["description"] = "识别完成";}
  1016. //console.log("data: " + data.data);
  1017. //var Results_dddd = Results;
  1018. //console.log('hello的返回' + JSON.stringify(data.result));
  1019. //if (postData['ocr_type'] == 4) {console.log('hello的返回' + JSON.stringify(data.result.target));}
  1020. //if (!data.valid) {
  1021. if (data.msg) {
  1022. //if (data.description != undefined) {
  1023. that.Hint('识别请求发生错误: ' + data.msg, 5000);
  1024. //}
  1025. that.setCapFoowwLocalStorage("识别结果缓存:" + postDataHash, data.result, new Date().getTime() + (9999999 * 9999999))
  1026.  
  1027. } else {
  1028.  
  1029. that.setCapFoowwLocalStorage("识别结果缓存:" + postDataHash, data.result, new Date().getTime() + (9999999 * 9999999))
  1030. //var Results = JSON.stringify(data.result);
  1031. //if (postData['ocr_type'] == 4) {Results = JSON.stringify(data.result.target);data['data'] = 20;}
  1032. //var Results_dd = Results
  1033. //console.log("Results1111111: " + Results );
  1034. if (callback != null) {
  1035. if (callback.name == 'Slide') {
  1036. //滑动识别
  1037. callback(data);
  1038. } else {
  1039. //var Results = data.result;
  1040. //var Results = data.data;
  1041. if (Results.length < 0) {
  1042. that.Hint('验证码识别结果可能错误,请刷新验证码尝试', 5000)
  1043. } else if (data.msg != '' && data.msg != null) {
  1044. that.Hint(data.msg, data.showTime)
  1045. } else {
  1046. that.Hint('验证码识别完成', 500)
  1047. }
  1048. if (callback.name == 'WriteRule') {
  1049. // 自动识别
  1050. callback(data.result);
  1051. //callback(JSON.stringify(data.result.target))
  1052. } else if (callback.name == 'ManualRule') {
  1053. // 手动添加规则
  1054. //callback(img, data.data);
  1055. callback(img, data.result);
  1056. }
  1057. }
  1058. }
  1059. }
  1060. },
  1061. onerror: err => {
  1062. console.log(err)
  1063. }
  1064. });
  1065. //console.log("Results2222222: " + Results_dddd );
  1066. //return Results_dddd;
  1067. return Results;
  1068. }
  1069.  
  1070. //根据规则提取验证码base64并识别
  1071. async ImgPathToResult(imgElement, callback) {
  1072. var that = this;
  1073. var imgObj = $(imgElement);
  1074. if (!imgObj.is(":visible")) {
  1075. console.log("验证码不可见,本次不识别");
  1076. return;
  1077. }
  1078. try {
  1079. var imgBase64 = await that.ImgElemToBase64(imgObj[0], imgElement);
  1080.  
  1081. if (imgBase64.length < 255) {
  1082. throw new Error("图片大小异常");
  1083. }
  1084. } catch (e) {
  1085. if (callback.name == 'ManualRule') {
  1086. that.Hint('跨域策略,请重新右键点击图片');
  1087. }
  1088. return;
  1089. }
  1090.  
  1091. var postData = {img: imgBase64, ocr_type: 1};
  1092. that.Identify_Crab(imgElement, postData, callback);
  1093. }
  1094.  
  1095. // 图片对象转Base64
  1096. ImgElemToBase64(imgObj) {
  1097. return new Promise((resolve, reject) => {
  1098. var that = this;
  1099. var imgBase64, imgSrc;
  1100. try {
  1101. var elementTagName = imgObj.tagName.toLowerCase();
  1102. if (elementTagName === "img" || elementTagName === "input") {
  1103. imgSrc = $(imgObj).attr("src");
  1104. } else if (elementTagName === "div") {
  1105. imgSrc = that.getElementStyle(imgObj)["backgroundImage"]
  1106. if (imgSrc.trim().indexOf("data:image/") != -1) {
  1107. // 是base64格式的
  1108. imgSrc = imgSrc.match("(data:image/.*?;base64,.*?)[\"']")[1]
  1109. } else {
  1110. // 是url格式的
  1111. imgSrc = imgSrc.split('"')[1];
  1112. }
  1113. }
  1114.  
  1115. if (imgSrc != undefined && imgSrc.indexOf("data:") == 0) {
  1116. // 使用base64页面直显
  1117. imgBase64 = imgSrc;
  1118. // 兼容部分浏览器中replaceAll不存在
  1119. while (imgBase64.indexOf("\n") != -1) {
  1120. imgBase64 = imgBase64.replace("\n", "");
  1121. }
  1122. // 解决存在url编码的换行问题
  1123. while (imgBase64.indexOf("%0D%0A") != -1) {
  1124. imgBase64 = imgBase64.replace("%0D%0A", "");
  1125. }
  1126. } else if (imgSrc != undefined && (((imgSrc.indexOf("http") == 0 || imgSrc.indexOf("//") == 0) && imgSrc.indexOf(window.location.protocol + "//" + window.location.host + "/") == -1) || $(imgObj).attr("crab_err") != undefined)) {
  1127. // 跨域模式下单独获取src进行转base64
  1128. var Results = that.getCapFoowwLocalStorage("验证码跨域识别锁:" + imgSrc);
  1129. if (Results != null) {
  1130. reject("验证码跨域识别锁住");
  1131. return;
  1132. }
  1133. that.setCapFoowwLocalStorage("验证码跨域识别锁:" + imgSrc, "避免逻辑错误多次识别", new Date().getTime() + (9999999 * 9999999));//同一个url仅识别一次
  1134.  
  1135. GM_xmlhttpRequest({
  1136. url: imgSrc, method: 'GET', responseType: "blob", onload: obj => {
  1137. if (obj.status == 200) {
  1138. let blob = obj.response;
  1139. let fileReader = new FileReader();
  1140. fileReader.onloadend = (e) => {
  1141. let base64 = e.target.result;
  1142. if (elementTagName == "div") {
  1143. that.setDivImg(base64, imgObj);
  1144. } else {
  1145. $(imgObj).attr("src", base64);
  1146. }
  1147.  
  1148. };
  1149. fileReader.readAsDataURL(blob)
  1150. }
  1151. }, onerror: err => {
  1152. that.Hint('请求跨域图片异常,请联系群内志愿者操作。');
  1153. reject("请求跨域图片异常");
  1154. }
  1155. });
  1156. } else {
  1157. // 使用canvas进行图片转换
  1158. imgBase64 = that.ConversionBase(imgObj).toDataURL("image/png");
  1159. }
  1160.  
  1161. var transform = that.getElementStyle(imgObj)['transform'];
  1162. if (transform != 'none' && transform != 'matrix(1, 0, 0, 1, 0, 0)') {
  1163. //图片可能存在旋转
  1164. let rotationBase64 = that.rotationImg(imgObj);
  1165. if (rotationBase64 != null) {
  1166. imgBase64 = rotationBase64;
  1167. }
  1168. }
  1169.  
  1170. resolve(imgBase64.replace(/.*,/, "").trim());
  1171. } catch (e) {
  1172. $(imgObj).attr("crab_err", 1);
  1173. reject("图片转换异常");
  1174. }
  1175.  
  1176. });
  1177. }
  1178.  
  1179. //重新设置div的背景图验证码
  1180. setDivImg(imgBase64, imgObj) {
  1181. var that = this;
  1182. // 创建一个临时的 Image 对象,并设置它的 src 属性为背景图片 URL
  1183. var img = new Image();
  1184. // 创建一个 Canvas 元素
  1185. var canvas = document.createElement('canvas');
  1186. canvas.width = that.getNumber(that.getElementStyle(imgObj)["width"]);
  1187. canvas.height = that.getNumber(that.getElementStyle(imgObj)["height"]);
  1188.  
  1189. // 在 Canvas 上绘制背景图片
  1190. var ctx = canvas.getContext('2d');
  1191.  
  1192. var position = imgObj.style.backgroundPosition;
  1193. var parts = position.split(' ');
  1194. var bgPartsX = 0;
  1195. var bgPartsY = 0;
  1196. if (parts.length == 2) {
  1197. bgPartsX = parseFloat(parts[0].replace(/[^-\d\.]/g, ''));
  1198. bgPartsY = parseFloat(parts[1].replace(/[^-\d\.]/g, ''));
  1199. }
  1200.  
  1201.  
  1202. // 当图片加载完成后执行
  1203. img.onload = function () {
  1204. var position = imgObj.style.backgroundSize;
  1205. var bgSize = position.split(' ');
  1206. var bgSizeW = canvas.width;
  1207. var bgSizeH = canvas.width / img.width * img.height;//有时候页面上的不准,按比例缩放即可
  1208. if (canvas.height == 0) {
  1209. canvas.height = bgSizeH;
  1210. }
  1211. if (bgSize.length == 2) {
  1212. bgSizeW = parseFloat(bgSize[0].replace(/[^-\d\.]/g, ''));
  1213. bgSizeH = parseFloat(bgSize[1].replace(/[^-\d\.]/g, ''));
  1214. }
  1215. if (parts.length == 2 || bgSize.length == 2) {
  1216. ctx.drawImage(img, bgPartsX, bgPartsY, bgSizeW, bgSizeH);
  1217. $(imgObj).css('background-position', '');
  1218. $(imgObj).css('background-size', '');
  1219. } else {
  1220. ctx.drawImage(img, 0, 0);
  1221. }
  1222. // 将截取的图像作为新的背景图片设置到 div 元素中
  1223. $(imgObj).css('background-image', 'url(' + canvas.toDataURL() + ')');
  1224. };
  1225. img.src = imgBase64;
  1226. }
  1227.  
  1228. //绑定规则到元素,并尝试识别
  1229. RuleBindingElement(img, input) {
  1230. var that = this;
  1231. //创建一个触发操作
  1232. if (document.querySelector(img) == null) {
  1233. return;
  1234. }
  1235.  
  1236. document.querySelector(img).onload = function () {
  1237. that.RuleBindingElement(img, input)
  1238. }
  1239.  
  1240. this.ImgPathToResult(img, function WriteRule(vcode) {
  1241. that.WriteImgCodeResult(vcode, input)
  1242. })
  1243.  
  1244. }
  1245.  
  1246. //写入操作
  1247. WriteImgCodeResult(ImgCodeResult, WriteInput) {
  1248. var that = this;
  1249. WriteInput = document.querySelector(WriteInput);
  1250. WriteInput.value = ImgCodeResult;
  1251. if (typeof (InputEvent) !== 'undefined') {
  1252. //使用 InputEvent 方法,主流浏览器兼容
  1253. WriteInput.value = ImgCodeResult;
  1254. WriteInput.dispatchEvent(new InputEvent("input")); //模拟事件
  1255. let eventNames = ["change", "blur", "focus", "keypress", "keydown", "input", "keydown", "keyup", "select"];
  1256. for (var i = 0; i < eventNames.length; i++) {
  1257. that.Fire(WriteInput, eventNames[i]);
  1258. }
  1259. that.FireForReact(WriteInput, "change");
  1260. WriteInput.value = ImgCodeResult;
  1261. } else if (KeyboardEvent) {
  1262. //使用 KeyboardEvent 方法,ES6以下的浏览器方法
  1263. WriteInput.dispatchEvent(new KeyboardEvent("input"));
  1264. }
  1265. }
  1266.  
  1267. // 各类原生事件
  1268. Fire(element, eventName) {
  1269. var event = document.createEvent("HTMLEvents");
  1270. event.initEvent(eventName, true, true);
  1271. element.dispatchEvent(event);
  1272. }
  1273.  
  1274. // 各类react事件
  1275. FireForReact(element, eventName) {
  1276. try {
  1277. let env = new Event(eventName);
  1278. element.dispatchEvent(env);
  1279. var funName = Object.keys(element).find(p => Object.keys(element[p]).find(f => f.toLowerCase().endsWith(eventName)));
  1280. if (funName != undefined) {
  1281. element[funName].onChange(env)
  1282. }
  1283. } catch (e) {
  1284. // console.log("各类react事件调用出错!")
  1285. }
  1286.  
  1287. }
  1288.  
  1289. //转换图片为:canvas
  1290. ConversionBase(img) {
  1291. var canvas = document.createElement("canvas");
  1292. canvas.width = img.width;
  1293. canvas.height = img.height;
  1294. var ctx = canvas.getContext("2d");
  1295. ctx.drawImage(img, 0, 0, img.width, img.height);
  1296. return canvas;
  1297. }
  1298.  
  1299. // 部分滑动图片可能存在旋转,需要修正
  1300. rotationImg(img) {
  1301. let style = window.getComputedStyle(img); // 获取元素的样式
  1302. let matrix = new DOMMatrixReadOnly(style.transform); // 将样式中的 transform 属性值转换成 DOMMatrix 对象
  1303. var angle = Math.round(Math.atan2(matrix.b, matrix.a) * (180 / Math.PI)); // 通过 DOMMatrix 对象计算旋转角度
  1304. if (angle != 0) {
  1305. let canvas = document.createElement("canvas");
  1306. let ctx = canvas.getContext('2d');
  1307. let width = img.naturalWidth;
  1308. let height = img.naturalHeight;
  1309. canvas.width = width;
  1310. canvas.height = canvas.width * width / height;
  1311. ctx.translate(canvas.width * 0.5, canvas.height * 0.5);
  1312. ctx.rotate(angle * Math.PI / 180);
  1313. ctx.drawImage(img, -canvas.height / 2, -canvas.width / 2, canvas.height, canvas.width);
  1314. return canvas.toDataURL("image/png");
  1315. }
  1316. return null;
  1317.  
  1318. }
  1319.  
  1320. //自动规则
  1321. AutoRules() {
  1322. var that = this;
  1323. // 最终规则
  1324. var MatchList = [];
  1325. //验证码元素
  1326. let captchaMap = [];
  1327. $("canvas,img,input[type='image'],div").each(function () {
  1328. let img = this;
  1329. if (!$(img).is(":visible")) {
  1330. return true;
  1331. }
  1332. let checkList = [...that.getCaptchaFeature(img), ...that.getCaptchaFeature(img.parentNode),];
  1333. checkList = checkList.filter((item) => item);
  1334. for (let i = 0; i < checkList.length; i++) {
  1335. if (checkList[i].toString().toLowerCase().indexOf("logo") != -1 || checkList[i].toString().toLowerCase().indexOf("btn") != -1 ) {
  1336. //如果元素内包含logo字符串,则直接跳过
  1337. checkList.splice(i, 1);
  1338. i--; // 因为删除了一个元素,所以需要将 i 减 1,以便继续遍历
  1339. //return true;
  1340. //break;
  1341. }
  1342. }
  1343.  
  1344. checkList = checkList.filter(item => item.toString().toLowerCase().indexOf("logo") == -1 && item.toString().toLowerCase().indexOf("btnlogin") == -1) ;
  1345. //console.log(checkList);
  1346. //let isInvalid = ["#", "about:blank"].includes(img.getAttribute("src")) || !img.getAttribute("src");
  1347. let isInvalid = ["#", "about:blank"].includes(img.getAttribute("src")) || !img.getAttribute("src") || img.getAttribute("src").indexOf("data:")==0;
  1348. let imgRules = "code,captcha,yzm,check,random,veri,vcodeimg,验证码,看不清,换一张,login,点击,verify,yanzhengma,idpicture".split(",");
  1349. let isHave = false;
  1350. for (let i = 0; i < checkList.length && !isHave; i++) {
  1351. let elemAttributeData = checkList[i].toLowerCase();
  1352. let imgStyles = that.getElementStyle(img);
  1353. let imgWidth = that.getNumber(imgStyles["width"]);
  1354. let imgHeight = that.getNumber(imgStyles["height"]);
  1355. let imgTagName = img.tagName.toLowerCase();
  1356.  
  1357. // 验证码得相关属性需要满足特定字符串,并且宽高及图片属性不能太过分
  1358. for (let j = 0; j < imgRules.length; j++) {
  1359. if (checkList[i] != undefined) {
  1360. if (elemAttributeData.indexOf(imgRules[j]) != -1
  1361. && ((imgTagName == "img" && !isInvalid) || imgTagName != "img") && imgWidth > 29 && imgWidth < 161
  1362. && ((imgTagName == "div" && imgStyles['backgroundImage'] != 'none') || imgTagName != "div")
  1363. && imgHeight < 80 && imgHeight != imgWidth) {
  1364. captchaMap.push({"img": img, "input": null})
  1365. isHave = true;
  1366. break;
  1367. }
  1368. }
  1369. }
  1370. }
  1371.  
  1372. });
  1373. //captchaMap = captchaMap.filter(item => !item.img.toLowerCase().includes("btn")) ;
  1374. ////console.log(captchaMap);
  1375. captchaMap.forEach((item) => {
  1376. let imgEle = item.img;
  1377. ////console.log(imgEle);
  1378. let parentNode = imgEle.parentNode;
  1379. for (let i = 0; i < 4; i++) {
  1380. // 以当前可能是验证码的图片为基点,向上遍历四层查找可能的Input输入框
  1381. if (!parentNode) {
  1382. return;
  1383. }
  1384. let inputTags = [...parentNode.querySelectorAll("input")];
  1385. if (inputTags.length) {
  1386. let input = inputTags.pop();
  1387. let type = input.getAttribute("type");
  1388. while (type !== "text" && inputTags.length) {
  1389. if (type === "password") {
  1390. break;
  1391. }
  1392. input = inputTags.pop();
  1393. type = input.getAttribute("type");
  1394. }
  1395.  
  1396. let inputWidth = that.getNumber(that.getElementStyle(input).width);
  1397. if (!type || (type === "text" && inputWidth > 29)) {
  1398. // 给目标元素添加边框,证明自动规则选中得
  1399. $(imgEle).css("borderStyle", "solid").css("borderColor", "red").css("border-width", "2px").css("box-sizing", "border-box");
  1400. $(input).css("borderStyle", "solid").css("borderColor", "red").css("border-width", "1px").css("box-sizing", "border-box");
  1401. MatchList.push({"img": that.Aimed(imgEle), "input": that.Aimed(input)})
  1402. break;
  1403. }
  1404. if (type === "password") {
  1405. // 验证码一般在密码框后面,遍历到密码框了就大概率说明没有验证码
  1406. break;
  1407. }
  1408. }
  1409. parentNode = parentNode.parentNode;
  1410. }
  1411. });
  1412. MatchList = MatchList.filter(item => JSON.stringify(item).toLowerCase().indexOf("logo") == -1 && JSON.stringify(item).toLowerCase().indexOf("btn") == -1) ;
  1413. return MatchList;
  1414. }
  1415.  
  1416. // 获取验证码特征
  1417. getCaptchaFeature(el) {
  1418. let checkList = [];
  1419. checkList.push(el.getAttribute("id"));
  1420. checkList.push(el.className);
  1421. checkList.push(el.getAttribute("alt"));
  1422. checkList.push(el.getAttribute("src"));
  1423. checkList.push(el.getAttribute("name"));
  1424. checkList.push(el.getAttribute("title"));
  1425.  
  1426. return checkList;
  1427. }
  1428.  
  1429. //根据元素生成JsPath
  1430. Aimed(Element) {
  1431. // console.log('---根据元素创建配置信息---');
  1432. if (Element.length > 0) {
  1433. Element = Element[0]
  1434. }
  1435. var that = this;
  1436. var ElementLocalName = Element.localName;
  1437. var result;
  1438. // 如果有vue的id,则直接返回
  1439. var vueId = that.getDataV(Element);
  1440. if (vueId != null) {
  1441. result = ElementLocalName + "[" + vueId + "]";
  1442. if ($(result).length == 1) {
  1443. return result;
  1444. }
  1445. }
  1446. // 如果有placeholder,则直接返回
  1447. var placeholder = that.getPlaceholder(Element);
  1448. if (placeholder != null) {
  1449. result = ElementLocalName + "[" + placeholder + "]";
  1450. if ($(result).length == 1) {
  1451. return result;
  1452. }
  1453. }
  1454. // 如果有alt,则直接返回
  1455. var alt = that.getAlt(Element);
  1456. if (alt != null) {
  1457. result = ElementLocalName + "[" + alt + "]";
  1458. if ($(result).length == 1) {
  1459. return result;
  1460. }
  1461. }
  1462.  
  1463. // 如果有name且只有一个,则直接返回
  1464. var selectElement = that.getElementName(Element); var test = that.getElementId
  1465. if (selectElement != null) {
  1466. return selectElement;
  1467. }
  1468.  
  1469. // 如果有id且只有一个,则直接返回
  1470. //var selectElement = that.getElementId(Element);
  1471. //if (selectElement != null) {
  1472. // return selectElement;
  1473. //}
  1474.  
  1475. // 如果有src,且src后面无参数则直接返回
  1476. var src = that.getSrc(Element);
  1477. /////////////////////////////console.log(src);
  1478. if (src != null && src.length < 200) {
  1479. result = ElementLocalName + "[" + src + "]";
  1480. if ($(result).length == 1) {
  1481. return result;
  1482. }
  1483. }
  1484. // 如果有onClick则直接返回
  1485. var onClick = that.getOnClick(Element);
  1486. if (onClick != null && onClick.length < 200) {
  1487. result = ElementLocalName + "[" + onClick + "]";
  1488. if ($(result).length == 1) {
  1489. return result;
  1490. }
  1491. }
  1492. var cssPath = that.geElementCssPath(Element);
  1493. if (cssPath != null && cssPath != "") {
  1494. try {
  1495. //避免样式选择器有时候选到错的无法使用问题
  1496. if ($(cssPath).length > 0) {
  1497. return cssPath;
  1498. }
  1499. } catch (e) {
  1500. }
  1501. }
  1502.  
  1503. var Symbol = (this.getElementId(Element) ? "#" : Element.className ? "." : false);
  1504. var locationAddr;
  1505. if (!Symbol) {
  1506. locationAddr = that.Climb(Element.parentNode, ElementLocalName);
  1507. } else {
  1508. locationAddr = that.Climb(Element, ElementLocalName);
  1509. }
  1510. if ($(locationAddr).length == 1) {
  1511. return locationAddr.trim();
  1512. }
  1513.  
  1514. // if (confirm("当前元素无法自动选中,是否手动指定JsPath?\n(该功能为熟悉JavaScript的用户使用,若您不知道,请点击取消。)\n注意:如果该提示影响到您得操作了,关闭'自动查找验证码'功能即可!")) {
  1515. // result = prompt("请输入待选择元素的JsPath,例如:\n#app > div:nth-child(3) > div > input");
  1516. // try {
  1517. // if ($(result).length == 1) {
  1518. // return result;
  1519. // }
  1520. // } catch (e) {
  1521. // }
  1522. // }
  1523.  
  1524. that.Hint('该网站非标准web结构,暂时无法添加规则,请联系群内志愿者添加。')
  1525. return null;
  1526.  
  1527. }
  1528.  
  1529. //判断元素id是否可信
  1530. getElementId(element) {
  1531. var id = element.id;
  1532. if (id) {
  1533. if (id.indexOf("exifviewer-img-") == -1) {// 对抗类似vue这种无意义id
  1534. if (id.length < 40) {// 对抗某些会自动变换id的验证码
  1535. return true;
  1536. }
  1537. }
  1538. }
  1539. return false;
  1540. }
  1541.  
  1542. //爬层级
  1543. Climb(Element, ElementLocalName, Joint = '') {
  1544. var ElementType = (this.getElementId(Element) ? Element.id : Element.className ? Element.className.replace(/\s/g, ".") : false);
  1545. var Symbol = (this.getElementId(Element) ? "#" : Element.className ? "." : false);
  1546. var Address;
  1547. if (ElementType && ElementLocalName == Element.localName) {
  1548. Address = ElementLocalName + Symbol + ElementType;
  1549. } else {
  1550. Address = "";
  1551. if (Symbol != false) {
  1552. Address = Address + Symbol;
  1553. }
  1554. if (ElementType != false) {
  1555. Address = Address + ElementType;
  1556. }
  1557. Address = ' ' + ElementLocalName
  1558. }
  1559. if ($(Address).length == 1) {
  1560. return Address + ' ' + Joint;
  1561. } else {
  1562. Joint = this.Climb($(Element).parent()[0], $(Element).parent()[0].localName, Address + ' ' + Joint)
  1563. return Joint;
  1564. }
  1565. }
  1566.  
  1567. // 获取vue的data-v-xxxx
  1568. getDataV(element) {
  1569. var elementKeys = element.attributes;
  1570. if (elementKeys == null) {
  1571. return null;
  1572. }
  1573. for (var i = 0; i < elementKeys.length; i++) {
  1574. var key = elementKeys[i].name;
  1575. if (key.indexOf("data-v-") != -1) {
  1576. return key;
  1577. }
  1578. }
  1579. return null;
  1580. }
  1581.  
  1582. // 获取placeholder="验证码"
  1583. getPlaceholder(element) {
  1584. var elementKeys = element.attributes;
  1585. if (elementKeys == null) {
  1586. return null;
  1587. }
  1588. for (var i = 0; i < elementKeys.length; i++) {
  1589. var key = elementKeys[i].name.toLowerCase();
  1590. if (key == "placeholder" && elementKeys[i].value != "") {
  1591. return elementKeys[i].name + "='" + elementKeys[i].value + "'";
  1592. }
  1593. }
  1594. return null;
  1595. }
  1596.  
  1597. // 获取alt="kaptcha"
  1598. getAlt(element) {
  1599. var elementKeys = element.attributes;
  1600. if (elementKeys == null) {
  1601. return null;
  1602. }
  1603. for (var i = 0; i < elementKeys.length; i++) {
  1604. var key = elementKeys[i].name.toLowerCase();
  1605. if (key == "alt") {
  1606. return elementKeys[i].name + "='" + elementKeys[i].value + "'";
  1607. }
  1608. }
  1609. return null;
  1610. }
  1611.  
  1612. // 获取src="http://xxx.com"
  1613. getSrc(element) {
  1614. var elementKeys = element.attributes;
  1615. if (elementKeys == null) {
  1616. return null;
  1617. }
  1618. for (var i = 0; i < elementKeys.length; i++) {
  1619. var key = elementKeys[i].name.toLowerCase();
  1620. var value = elementKeys[i].value;
  1621. if (key == "src" && value.indexOf("data:image") != 0) {
  1622. var idenIndex = value.indexOf("?");
  1623. if (idenIndex != -1) {
  1624. value = value.substring(0, idenIndex + 1);
  1625. }
  1626.  
  1627. // 从 URL 中提取文件名
  1628. const filename = value.substring(value.lastIndexOf('/') + 1);
  1629. // 从文件名中提取后缀部分
  1630. const fileExtension = filename.substring(filename.lastIndexOf('.') + 1);
  1631. if (fileExtension == "jpg" || fileExtension == "png" || fileExtension == "gif") {
  1632. // 直接是静态文件,无法作为规则
  1633. return null;
  1634. }
  1635. if (/\d/.test(value)) {
  1636. // 存在数字则可能是时间戳之类得,直接抛弃
  1637. return null;
  1638. }
  1639. return elementKeys[i].name + "^='" + value + "'";
  1640. }
  1641. }
  1642. return null;
  1643. }
  1644.  
  1645. // 判断name是否只有一个
  1646. getElementName(element) {
  1647. var elementName = element.name;
  1648. if (elementName == null || elementName == "") {
  1649. return null;
  1650. }
  1651. var selectElement = element.localName + "[name='" + elementName + "']";
  1652. if ($(selectElement).length == 1) {
  1653. return selectElement;
  1654. }
  1655. return null;
  1656. }
  1657.  
  1658. // 判断OnClick是否只有一个
  1659. getOnClick(element) {
  1660. var elementKeys = element.attributes;
  1661. if (elementKeys == null) {
  1662. return null;
  1663. }
  1664. for (var i = 0; i < elementKeys.length; i++) {
  1665. var key = elementKeys[i].name.toLowerCase();
  1666. var value = elementKeys[i].value;
  1667. if (key == "onclick") {
  1668. var idenIndex = value.indexOf("(");
  1669. if (idenIndex != -1) {
  1670. value = value.substring(0, idenIndex + 1);
  1671. }
  1672. return elementKeys[i].name + "^='" + value + "'";
  1673. }
  1674. }
  1675. return null;
  1676. }
  1677.  
  1678. // 操作webStorage 增加缓存,减少对服务端的请求
  1679. setCapFoowwLocalStorage(key, value, ttl_ms) {
  1680. var data = {value: value, expirse: new Date(ttl_ms).getTime()};
  1681. sessionStorage.setItem(key, JSON.stringify(data));
  1682. }
  1683.  
  1684. getCapFoowwLocalStorage(key) {
  1685. var data = JSON.parse(sessionStorage.getItem(key));
  1686. if (data !== null) {
  1687. if (data.expirse != null && data.expirse < new Date().getTime()) {
  1688. sessionStorage.removeItem(key);
  1689. } else {
  1690. return data.value;
  1691. }
  1692. }
  1693. return null;
  1694. }
  1695.  
  1696. delCapFoowwLocalStorage(key) {
  1697. window.sessionStorage.removeItem(key);
  1698. }
  1699.  
  1700. // 自动添加识别错误黑名单
  1701. addBadWeb(img, input) {
  1702. if (Set["autoBlackList"] == "false") {
  1703. return;
  1704. }
  1705. this.Hint("识别过程中发生错误,已停止识别此网站!(若验证码消失请刷新网站,需再次启用识别请在'更多设置'中删除所有规则)", 15000);
  1706. this.captchaHostBad(img, input);
  1707. }
  1708.  
  1709. // 手动添加识别错误黑名单
  1710. captchaHostBad(img, input) {
  1711. this.setCapFoowwLocalStorage("err_" + img, "可能存在跨域等问题停止操作它", new Date().getTime() + (1000 * 1000));
  1712. this.delCapFoowwLocalStorage("captchaHostQuery_" + window.location.href);
  1713. this.Query({
  1714. "method": "captchaHostAdd", "data": {
  1715. "host": window.location.host,
  1716. "path": window.location.href,
  1717. "img": img,
  1718. "input": input,
  1719. "title": document.title,
  1720. "type": 0,
  1721. "idcard": this.IdCard()
  1722. }
  1723. }, null);
  1724. }
  1725.  
  1726.  
  1727. // 删除规则
  1728. captchaHostDel() {
  1729. if (!confirm("该操作会导致清除‘" + window.location.host + "’网站下含黑名单在内的所有规则,删除后您需要重新手动添加规则,是否继续?")) {
  1730. return;
  1731. }
  1732. this.delCapFoowwLocalStorage("captchaHostQuery_" + window.location.href);
  1733. this.Query({
  1734. "method": "captchaHostDel", "data": {
  1735. "host": window.location.host,
  1736. "path": window.location.href,
  1737. "idcard": this.IdCard()
  1738. }
  1739. }, null);
  1740. }
  1741.  
  1742. // 设置识别识别码
  1743. SetIdCard() {
  1744. var that = this;
  1745. let gmGetValue = GM_getValue("set");
  1746. var idCard = gmGetValue["idCard"];
  1747. if (idCard != null && idCard.length == 32) {
  1748. return;
  1749. }
  1750.  
  1751. idCard = prompt("申请地址https://like996.icu:1205\n设置后如需修改可在更多设置中“恢复出厂设置”后重试。\n请输入您的识别码:");
  1752. if (idCard == null || idCard == "") {
  1753. that.Hint('取消设置');
  1754. } else {
  1755. if (idCard.length != 32) {
  1756. //if (idCard.length != 32) {
  1757. that.Hint('识别码应为32位,请参考设置中的“查看帮助”进行自行注册(不可用)!');
  1758. } else {
  1759. GM_setValue("set", {
  1760. "idCard": idCard
  1761. });
  1762. that.Hint('识别码设置完成刷新页面生效。');
  1763. }
  1764.  
  1765. }
  1766. return;
  1767. }
  1768.  
  1769. // 播放音频朗读
  1770. doWarningTone(body) {
  1771. if (body.indexOf(",")) {
  1772. body = body.split(",")[0];
  1773. }
  1774. if (body.indexOf(",")) {
  1775. body = body.split(",")[0];
  1776. }
  1777. if (body.indexOf("!")) {
  1778. body = body.split("!")[0];
  1779. }
  1780. var zhText = encodeURI(body);
  1781. var text = "<audio autoplay='autoplay'>" + "<source src='https://dict.youdao.com/dictvoice?le=zh&audio=" + zhText + "' type='audio/mpeg'>" + "<embed height='0' width='0' src='https://dict.youdao.com/dictvoice?le=zh&audio=" + zhText + "'>" + "</audio>";
  1782. return text;
  1783. }
  1784.  
  1785. // 获取元素的全部样式
  1786. getElementStyle(element) {
  1787. if (window.getComputedStyle) {
  1788. return window.getComputedStyle(element, null);
  1789. } else {
  1790. return element.currentStyle;
  1791. }
  1792. }
  1793.  
  1794. // 获取元素的cssPath选择器
  1795. geElementCssPath(element) {
  1796. if (!(element instanceof Element)) return;
  1797. var path = [];
  1798. while (element.nodeType === Node.ELEMENT_NODE) {
  1799. var selector = element.nodeName.toLowerCase();
  1800. if (element.id && element.id.indexOf("exifviewer-img-") == -1) {
  1801. selector += "#" + element.id;
  1802. path.unshift(selector);
  1803. break;
  1804. } else {
  1805. var sib = element, nth = 1;
  1806. while ((sib = sib.previousElementSibling)) {
  1807. if (sib.nodeName.toLowerCase() == selector) nth++;
  1808. }
  1809. if (nth != 1) selector += ":nth-of-type(" + nth + ")";
  1810. }
  1811. path.unshift(selector);
  1812. element = element.parentNode;
  1813. }
  1814. return path.join(" > ");
  1815. }
  1816.  
  1817. // 获取指定字符串hash
  1818. strHash(input) {
  1819. var I64BIT_TABLE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-'.split('');
  1820. var hash = 5381;
  1821. var i = input.length - 1;
  1822.  
  1823. if (typeof input == 'string') {
  1824. for (; i > -1; i--) hash += (hash << 5) + input.charCodeAt(i);
  1825. } else {
  1826. for (; i > -1; i--) hash += (hash << 5) + input[i];
  1827. }
  1828. var value = hash & 0x7FFFFFFF;
  1829.  
  1830. var retValue = '';
  1831. do {
  1832. retValue += I64BIT_TABLE[value & 0x3F];
  1833. } while (value >>= 6);
  1834.  
  1835. return retValue;
  1836. }
  1837.  
  1838. // 监控热键
  1839. crabFacebook() {
  1840. document.onkeydown = function () {
  1841. if (Set["hotKeyToImgResult"] == "false") {
  1842. return;
  1843. }
  1844. var keyCodeName = {
  1845. "91": "command",
  1846. "96": "0",
  1847. "97": "1",
  1848. "98": "2",
  1849. "99": "3",
  1850. "100": "4",
  1851. "101": "5",
  1852. "102": "6",
  1853. "103": "7"
  1854. ,
  1855. "104": "8",
  1856. "105": "9",
  1857. "106": "*",
  1858. "107": "+",
  1859. "108": "回车",
  1860. "109": "-",
  1861. "110": ".",
  1862. "111": "/",
  1863. "112": "F1",
  1864. "113": "F2"
  1865. ,
  1866. "114": "F3",
  1867. "115": "F4",
  1868. "116": "F5",
  1869. "117": "F6",
  1870. "118": "F7",
  1871. "119": "F8",
  1872. "120": "F9",
  1873. "121": "F10",
  1874. "122": "F11"
  1875. ,
  1876. "123": "F12",
  1877. "8": "BackSpace",
  1878. "9": "Tab",
  1879. "12": "Clear",
  1880. "13": "回车",
  1881. "16": "Shift",
  1882. "17": "Control",
  1883. "18": "Alt"
  1884. ,
  1885. "20": "Cape Lock",
  1886. "27": "Esc",
  1887. "32": "空格",
  1888. "33": "Page Up",
  1889. "34": "Page Down",
  1890. "35": "End",
  1891. "36": "Home",
  1892. "37": "←"
  1893. ,
  1894. "38": "↑",
  1895. "39": "→",
  1896. "40": "↓",
  1897. "45": "Insert",
  1898. "46": "Delete",
  1899. "144": "Num Lock",
  1900. "186": ";",
  1901. "187": "=",
  1902. "188": ","
  1903. ,
  1904. "189": "-",
  1905. "190": ".",
  1906. "191": "/",
  1907. "192": "`",
  1908. "219": "[",
  1909. "220": "\\",
  1910. "221": "]",
  1911. "222": "'",
  1912. "65": "A",
  1913. "66": "B"
  1914. ,
  1915. "67": "C",
  1916. "68": "D",
  1917. "69": "E",
  1918. "70": "F",
  1919. "71": "G",
  1920. "72": "H",
  1921. "73": "I",
  1922. "74": "J",
  1923. "75": "K",
  1924. "76": "L",
  1925. "77": "M"
  1926. ,
  1927. "78": "N",
  1928. "79": "O",
  1929. "80": "P",
  1930. "81": "Q",
  1931. "82": "R",
  1932. "83": "S",
  1933. "84": "T",
  1934. "85": "U",
  1935. "86": "V",
  1936. "87": "W",
  1937. "88": "X"
  1938. ,
  1939. "89": "Y",
  1940. "90": "Z",
  1941. "48": "0",
  1942. "49": "1",
  1943. "50": "2",
  1944. "51": "3",
  1945. "52": "4",
  1946. "53": "5",
  1947. "54": "6",
  1948. "55": "7",
  1949. "56": "8",
  1950. "57": "9"
  1951. };
  1952. var a = window.event.keyCode;
  1953. if (Set["hotKeyToImgResult"] == "wait" && a != undefined) {
  1954. var keyName = keyCodeName[a + ""] == undefined ? a : keyCodeName[a + ""];
  1955. crabCaptcha.Hint('快捷键设置成功当前快捷键为:' + keyName + ",重新打开页面生效!");
  1956. Set["hotKeyToImgResult"] = "true";
  1957. Set["hotKey"] = a;
  1958. GM_setValue("set", Set);
  1959. clearInterval(writeResultInterval);
  1960. } else {
  1961. if (a == Set["hotKey"]) {
  1962. crabCaptcha.WriteResultsInterval();
  1963. crabCaptcha.Hint("开始快捷键识别验证码,在当前页面刷新之前新的验证码将自动识别!");
  1964. }
  1965. }
  1966. }
  1967. }
  1968. }
  1969.  
  1970. //所有验证码img的对象数组
  1971. var writeResultIntervals = [];
  1972.  
  1973. //定时执行验证码绑定操作定时器
  1974. var writeResultInterval;
  1975.  
  1976.  
  1977. function closeButton() {
  1978. const closebtn = document.createElement("div");
  1979. closebtn.innerHTML = " × ";
  1980. closebtn.style.position = "absolute";
  1981. closebtn.style.top = "10px";
  1982. closebtn.style.right = "10px";
  1983. closebtn.style.cursor = "pointer";
  1984. closebtn.style.fontWeight = 900;
  1985. closebtn.style.fontSize = "larger";
  1986. closebtn.setAttribute("onclick", "CKTools.modal.hideModal()");
  1987. return closebtn;
  1988. }
  1989.  
  1990. async function GUISettings() {
  1991. if (CKTools.modal.isModalShowing()) {
  1992. CKTools.modal.hideModal();
  1993. }
  1994. const menuList = [{
  1995. name: 'autoIdentification',
  1996. title: '自动查找无规则验证码',
  1997. hintOpen: '已开启自动查找验证码功能,请刷新网页',
  1998. hintClose: '已关闭自动查找验证码功能,遇到新网站请自行手动添加规则!',
  1999. desc: '对于未添加规则的页面,将自动查找页面上的验证码,有找错的可能。',
  2000. openVul: 'true',
  2001. closeVul: 'false'
  2002. }, {
  2003. name: 'showHintCheck',
  2004. title: '提示信息',
  2005. hintOpen: '提示功能已开启!',
  2006. hintClose: '提示功能已关闭,再次开启前将无任何提示!',
  2007. desc: '关闭前请确保已知晓插件的使用流程!',
  2008. openVul: 'true',
  2009. closeVul: 'false'
  2010. }, {
  2011. name: 'warningTone',
  2012. title: '提示音',
  2013. hintOpen: '提示音功能已开启!',
  2014. hintClose: '提示音功能已关闭!',
  2015. desc: '自动朗读提示信息中的文字!',
  2016. openVul: 'true',
  2017. closeVul: 'false'
  2018. }, {
  2019. name: 'autoBlackList',
  2020. title: '识别崩溃自动拉黑网站',
  2021. hintOpen: '崩溃自动拉黑网站功能已开启!',
  2022. hintClose: '崩溃自动拉黑网站功能已关闭!',
  2023. desc: '遇到跨域或其他错误导致验证码无法加载时自动将网站加到黑名单中。',
  2024. openVul: 'true',
  2025. closeVul: 'false'
  2026. }, {
  2027. name: 'hotKeyToImgResult',
  2028. title: '快捷键查找验证码',
  2029. hintOpen: '请直接按下您需要设置的快捷键!设置快捷键前请确保当前页面能够自动识别否则先手动添加规则!',
  2030. hintClose: '快捷键查找验证码已关闭!',
  2031. desc: '先手动添加规则后再开启,开启后将停止自动识别,仅由快捷键识别!',
  2032. openVul: 'wait',
  2033. closeVul: 'false',
  2034. doWork: 'crabCaptcha.crabFacebook()'
  2035. }, {
  2036. name: 'openHelp',
  2037. type: 'button',
  2038. title: '查看使用帮助',
  2039. desc: '如果您使用上遇到问题或障碍,请仔细阅读该内容!',
  2040. hintOpen: '使用帮助说明网页已打开,若遇到您无法解决的问题,可加群联系群内志愿者!',
  2041. doWork: 'crabCaptcha.openHelp()'
  2042. }, {
  2043. name: 'clearSet',
  2044. type: 'button',
  2045. title: '恢复出厂设置',
  2046. hintOpen: '已成功恢复出厂设置刷新页面即可生效',
  2047. desc: '清除所有设置,包括识别码!',
  2048. doWork: 'crabCaptcha.clearSet()'
  2049. },]
  2050. CKTools.modal.openModal("万能验证码自动输入-更多设置(点击切换)", await CKTools.domHelper("div", async container => {
  2051. container.appendChild(closeButton());
  2052. container.style.alignItems = "stretch";
  2053. for (var i = 0; i < menuList.length; i++) {
  2054. container.appendChild(await CKTools.domHelper("li", async list => {
  2055. list.classList.add("showav_menuitem");
  2056. if (menuList[i].type == 'button') {
  2057. list.appendChild(await CKTools.domHelper("label", label => {
  2058. label.id = menuList[i].name + "Tip";
  2059. label.value = i;
  2060. label.setAttribute('doWork', menuList[i].doWork);
  2061. label.addEventListener("click", e => {
  2062. if (eval($(e.target).attr("doWork"))) {
  2063. crabCaptcha.Hint(menuList[e.target.value].hintOpen);
  2064. }
  2065. })
  2066. label.innerHTML = menuList[i].title;
  2067. }));
  2068. } else {
  2069. list.appendChild(await CKTools.domHelper("input", input => {
  2070. input.type = "checkbox";
  2071. input.id = menuList[i].name;
  2072. input.name = menuList[i].name;
  2073. input.value = i;
  2074. input.style.display = "none";
  2075. input.checked = Set[menuList[i].name] == 'true';
  2076. input.setAttribute('doWork', menuList[i].doWork);
  2077. input.addEventListener("change", e => {
  2078. var i = e.target.value;
  2079. const label = document.querySelector("#" + menuList[i].name + "Tip");
  2080. if (!label) return;
  2081. if (input.checked) {
  2082. label.innerHTML = "<b>[已开启]</b> " + menuList[i].title;
  2083. Set[menuList[i].name] = menuList[i].openVul;
  2084. GM_setValue("set", Set);
  2085. crabCaptcha.Hint(menuList[i].hintOpen);
  2086. let doWork = $(e.target).attr("doWork");
  2087. if (doWork != null) {
  2088. eval(doWork)
  2089. }
  2090. } else {
  2091. label.innerHTML = "<span>[已关闭]</span>" + menuList[i].title;
  2092. Set[menuList[i].name] = menuList[i].closeVul;
  2093. GM_setValue("set", Set);
  2094. crabCaptcha.Hint(menuList[i].hintClose);
  2095. }
  2096. })
  2097. }));
  2098. list.appendChild(await CKTools.domHelper("label", label => {
  2099. label.id = menuList[i].name + "Tip";
  2100. label.setAttribute('for', menuList[i].name);
  2101. if (Set[menuList[i].name] == 'true') {
  2102. label.innerHTML = "<b>[已开启]</b>" + menuList[i].title;
  2103. } else {
  2104. label.innerHTML = "<span>[已关闭]</span>" + menuList[i].title;
  2105. }
  2106. }));
  2107. }
  2108. list.appendChild(await CKTools.domHelper("div", div => {
  2109. div.style.paddingLeft = "20px";
  2110. div.style.color = "#919191";
  2111. div.innerHTML = "说明:" + menuList[i].desc;
  2112. }));
  2113. list.style.lineHeight = "2em";
  2114. }))
  2115. }
  2116. container.appendChild(await CKTools.domHelper("div", async btns => {
  2117. btns.style.display = "flex";
  2118. btns.style.alignItems = "flex-end";
  2119. btns.appendChild(await CKTools.domHelper("button", btn => {
  2120. btn.className = "CKTOOLS-toolbar-btns";
  2121. btn.innerHTML = "关闭";
  2122. btn.style.background = "#ececec";
  2123. btn.style.color = "black";
  2124. btn.onclick = e => {
  2125. CKTools.addStyle(``, "showav_lengthpreviewcss", "update");
  2126. CKTools.modal.hideModal();
  2127. }
  2128. }))
  2129. }))
  2130. }));
  2131. //强制设置置顶,避免被占用
  2132. $("#CKTOOLS-modal").css("z-index", "99999999999");
  2133. //强制设置置顶,避免被占用
  2134. $("#CKTOOLS-modal").height("600px");
  2135. }
  2136.  
  2137. async function GUIAddRule() {
  2138. if (CKTools.modal.isModalShowing()) {
  2139. CKTools.modal.hideModal();
  2140. }
  2141. const menuList = [{
  2142. name: 'letterRule',
  2143. title: '添加数字、字母验证码规则',
  2144. type: 'button',
  2145. desc: '请根据网站顶部提示:先右键验证码,再左键点击输入框!',
  2146. doWork: 'crabCaptcha.LetterPickUp()'
  2147. }, {
  2148. name: 'slideRule',
  2149. title: '添加滑动拼图验证码规则',
  2150. type: 'button',
  2151. desc: '请根据网站顶部提示,依次点击(左键右键均可):大图、小图、滑块!',
  2152. doWork: 'crabCaptcha.SlidePickUp()'
  2153. }, {
  2154. name: 'slideBehaviorRule',
  2155. title: '添加滑块行为验证码规则',
  2156. type: 'button',
  2157. desc: '注意:该类验证码仅有一个滑块,请根据网站顶部提示点击滑块!',
  2158. doWork: 'crabCaptcha.slideBehaviorRule()'
  2159. }, {
  2160. name: 'captchaHostBad',
  2161. title: '停止识别该网站',
  2162. type: 'button',
  2163. desc: '停止后该网站将不再识别,如需继续识别点击下方“删除该网站全部规则”。',
  2164. doWork: 'crabCaptcha.captchaHostBad("bad","bad")'
  2165. }, {
  2166. name: 'captchaHostDel',
  2167. title: '删除该网站全部规则',
  2168. type: 'button',
  2169. desc: '删除当前网站用户手动添加的全部规则,含黑名单。',
  2170. doWork: 'crabCaptcha.captchaHostDel()'
  2171. },]
  2172. CKTools.modal.openModal("万能验证码自动输入-规则管理(请点击您要执行的操作)", await CKTools.domHelper("div", async container => {
  2173. container.appendChild(closeButton());
  2174. container.style.alignItems = "stretch";
  2175. for (var i = 0; i < menuList.length; i++) {
  2176. container.appendChild(await CKTools.domHelper("li", async list => {
  2177. list.classList.add("showav_menuitem");
  2178. if (menuList[i].type == 'button') {
  2179. list.appendChild(await CKTools.domHelper("label", label => {
  2180. label.id = menuList[i].name + "Tip";
  2181. label.value = i;
  2182. label.setAttribute('doWork', menuList[i].doWork);
  2183. label.setAttribute('style', "color:blue");
  2184. label.addEventListener("click", e => {
  2185. CKTools.modal.hideModal();
  2186. eval($(e.target).attr("doWork"));
  2187. })
  2188. label.innerHTML = menuList[i].title;
  2189. }));
  2190. }
  2191. list.appendChild(await CKTools.domHelper("div", div => {
  2192. div.style.paddingLeft = "20px";
  2193. div.style.color = "#919191";
  2194. div.innerHTML = "说明:" + menuList[i].desc;
  2195. }));
  2196. list.style.lineHeight = "2em";
  2197. }))
  2198. }
  2199. container.appendChild(await CKTools.domHelper("div", async btns => {
  2200. btns.style.display = "flex";
  2201. btns.style.alignItems = "flex-end";
  2202. btns.appendChild(await CKTools.domHelper("button", btn => {
  2203. btn.className = "CKTOOLS-toolbar-btns";
  2204. btn.innerHTML = "关闭";
  2205. btn.style.background = "#ececec";
  2206. btn.style.color = "black";
  2207. btn.onclick = e => {
  2208. CKTools.addStyle(``, "showav_lengthpreviewcss", "update");
  2209. CKTools.modal.hideModal();
  2210. }
  2211. }))
  2212. }))
  2213. }));
  2214. //强制设置置顶,避免被占用
  2215. $("#CKTOOLS-modal").css("z-index", "99999999999");
  2216. $("#CKTOOLS-modal").height("400px");
  2217. }
  2218.  
  2219. var crabCaptcha = new CaptchaWrite();
  2220. (function () {
  2221. const resourceList = [{name: 'cktools', type: 'js'}]
  2222.  
  2223. function applyResource() {
  2224. resloop: for (let res of resourceList) {
  2225. if (!document.querySelector("#" + res.name)) {
  2226. let el;
  2227. switch (res.type) {
  2228. case 'js':
  2229. case 'rawjs':
  2230. el = document.createElement("script");
  2231. break;
  2232. case 'css':
  2233. case 'rawcss':
  2234. el = document.createElement("style");
  2235. break;
  2236. default:
  2237. console.log('Err:unknown type', res);
  2238. continue resloop;
  2239. }
  2240. el.id = res.name;
  2241. el.innerHTML = res.type.startsWith('raw') ? res.content : GM_getResourceText(res.name);
  2242. document.head.appendChild(el);
  2243. }
  2244. }
  2245. }
  2246.  
  2247. applyResource();
  2248. GM_registerMenuCommand('规则管理', function () {
  2249. GUIAddRule();
  2250. }, 'a');
  2251.  
  2252. if (Set["idCard"] == '' || Set["idCard"] == undefined) {
  2253. GM_registerMenuCommand('设置识别码', function () {
  2254. crabCaptcha.SetIdCard();
  2255. }, 's');
  2256. }
  2257. GM_registerMenuCommand('更多设置', function () {
  2258. GUISettings();
  2259. }, 'u');
  2260. crabCaptcha.Start();
  2261. CKTools.addStyle(`
  2262. #CKTOOLS-modal{
  2263. width: fit-content!important;
  2264. max-width: 80%!important;
  2265. }
  2266. .CKTOOLS-modal-content li label b {
  2267. color: green!important;
  2268. }
  2269. .CKTOOLS-modal-content li label span {
  2270. color: red!important;
  2271. }
  2272. .showav_menuitem{
  2273. line-height: 2em;
  2274. width: 100%;
  2275. transition: all .3s;
  2276. cursor: pointer;
  2277. }
  2278. .showav_menuitem:hover{
  2279. transform: translateX(6px);
  2280. }
  2281. .showav_menuitem>label{
  2282. font-weight: bold;
  2283. font-size: large;
  2284. display: block;
  2285. }
  2286. `, 'showav_dragablecss', "unique", document.head);
  2287.  
  2288. CKTools.addStyle(`
  2289. #CKTOOLS-modal li, #CKTOOLS-modal ul{
  2290. list-style: none !important;
  2291. }
  2292. `, 'showav_css_patch', 'unique', document.head);
  2293. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址