Autoverify-mod

autoverify captcha

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

此脚本不应直接安装,它是供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/464752/1191370/Autoverify-mod.js

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