Autoverify-mod

autoverify captcha

当前为 2023-04-25 提交的版本,查看 最新版本

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

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

QingJ © 2025

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