Autoverify-mod

autoverify captcha

当前为 2023-05-19 提交的版本,查看 最新版本

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

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

QingJ © 2025

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