Autoverify-mod

autoverify captcha

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

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

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

QingJ © 2025

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