Autoverify-mod

autoverify captcha

สคริปต์นี้ไม่ควรถูกติดตั้งโดยตรง มันเป็นคลังสำหรับสคริปต์อื่น ๆ เพื่อบรรจุด้วยคำสั่งเมทา // @require https://update.greatest.deepsurf.us/scripts/464752/1292226/Autoverify-mod.js

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