forked from sw1128/Web_Captcha
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsrc.js
More file actions
1062 lines (1027 loc) · 44.6 KB
/
src.js
File metadata and controls
1062 lines (1027 loc) · 44.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name 自动识别填充网页验证码
// @namespace http://tampermonkey.net/
// @version 0.5.8
// @description 自动识别填写大部分网站的数英验证码
// @author lcymzzZ
// @license GPL Licence
// @connect *
// @match http://*/*
// @match https://*/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant GM_xmlhttpRequest
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_registerMenuCommand
// @downloadURL https://update.greasyfork.org/scripts/459260/%E8%87%AA%E5%8A%A8%E8%AF%86%E5%88%AB%E5%A1%AB%E5%85%85%E7%BD%91%E9%A1%B5%E9%AA%8C%E8%AF%81%E7%A0%81.user.js
// @updateURL https://update.greasyfork.org/scripts/459260/%E8%87%AA%E5%8A%A8%E8%AF%86%E5%88%AB%E5%A1%AB%E5%85%85%E7%BD%91%E9%A1%B5%E9%AA%8C%E8%AF%81%E7%A0%81.meta.js
// ==/UserScript==
(function() {
'use strict';
var element, input, imgIndex, canvasIndex, inputIndex, captchaType;
var localRules = [];
var queryUrl = "http://captcha.zwhyzzz.top:8092/"
var exist = false;
var iscors = false;
var inBlack = false;
var firstin = true;
var fisrtUse = GM_getValue("fisrtUse", true);
if (fisrtUse) {
var mzsm = prompt("自动识别填充网页验证码\n首次使用,请阅读并同意以下免责条款。\n\n \
1. 此脚本仅用于学习研究,您必须在下载后24小时内将所有内容从您的计算机或手机或任何存储设备中完全删除,若违反规定引起任何事件本人对此均不负责。\n \
2. 请勿将此脚本用于任何商业或非法目的,若违反规定请自行对此负责。\n \
3. 本人对此脚本引发的问题概不负责,包括但不限于由脚本错误引起的任何损失和损害。\n \
4. 任何以任何方式查看此脚本的人或直接或间接使用此脚本的使用者都应仔细阅读此条款。\n \
5. 本人保留随时更改或补充此条款的权利,一旦您使用或复制了此脚本,即视为您已接受此免责条款。\n\n \
若您同意以上内容,请输入“我已阅读并同意以上内容” 然后开始使用。", "");
if (mzsm == "我已阅读并同意以上内容") {
GM_setValue("fisrtUse", false);
}
else {
alert("免责条款未同意,脚本停止运行。\n若不想使用,请自行禁用脚本,以免每个页面都弹出该提示。");
return;
}
}
//添加菜单
GM_registerMenuCommand('添加当前页面规则', addRule);
GM_registerMenuCommand('清除当前页面规则', delRule);
GM_registerMenuCommand('管理网页黑名单', manageBlackList);
GM_registerMenuCommand('云码Token(算术验证码专用)', saveToken)
GM_registerMenuCommand('加入交流/反馈群', getQQGroup);
GM_setValue("preCode", "");
function getQQGroup() {
GM_xmlhttpRequest({
method: "GET",
url: queryUrl + "getQQGroup",
onload: function(response) {
try {
var qqGroup = response.responseText;
alert(qqGroup);
}
catch(err){
return "群号获取失败";
}
}
});
}
function saveToken(){
var token = prompt(`帮助文档:https://docs.qq.com/doc/DWkhma0dsb1BxdEtU`, "输入Token");
if (token == null) {
return;
}
alert("Token保存成功");
GM_setValue("token", token);
}
//判断是否为验证码(预设规则)
function isCode(){
if (element.height >= 100 || element.height == element.width)
return false;
var attrList = ["id", "title", "alt", "name", "className", "src"];
var strList = ["code", "Code", "CODE", "captcha", "Captcha", "CAPTCHA", "yzm", "Yzm", "YZM", "check", "Check", "CHECK", "random", "Random", "RANDOM", "veri", "Veri", "VERI", "验证码", "看不清", "换一张"];
for (var i = 0; i < attrList.length; i++) {
for (var j = 0; j < strList.length; j++) {
// var str = "element." + attrList[i];
var attr = element[attrList[i]];
if (attr.indexOf(strList[j]) != -1) {
return true;
}
}
}
return false;
}
//判断是否为验证码输入框(预设规则)
function isInput(){
var attrList = ["placeholder", "alt", "title", "id", "className", "name"];
var strList = ["code", "Code", "CODE", "captcha", "Captcha", "CAPTCHA", "yzm", "Yzm", "YZM", "check", "Check", "CHECK", "random", "Random", "RANDOM", "veri", "Veri", "VERI", "验证码", "看不清", "换一张"];
for (var i = 0; i < attrList.length; i++) {
for (var j = 0; j < strList.length; j++) {
// var str = "input." + attrList[i];
var attr = input[attrList[i]];
if (attr.indexOf(strList[j]) != -1) {
// console.log(attr);
return true;
}
}
}
return false;
}
//手动添加规则(操作)
function addRule(){
var ruleData = {"url": window.location.href.split("?")[0], "img": "", "input": "", "inputType": "", "type": "", "captchaType": ""};
//检测鼠标右键点击事件
topNotice("请在验证码图片上点击鼠标 “右”👉 键");
document.oncontextmenu = function(e){
e = e || window.event;
e.preventDefault();
if (e.target.tagName == "IMG" || e.target.tagName == "GIF") {
var imgList = document.getElementsByTagName('img');
for (var i = 0; i < imgList.length; i++) {
if (imgList[i] == e.target) {
var k = i;
ruleData.type = "img";
}
}
}
else if (e.target.tagName == "CANVAS") {
var imgList = document.getElementsByTagName('canvas');
for (var i = 0; i < imgList.length; i++) {
if (imgList[i] == e.target) {
var k = i;
ruleData.type = "canvas";
}
}
}
if (k == null) {
topNotice("选择有误,请重新点击验证码图片");
return;
}
ruleData.img = k;
topNotice("请在验证码输入框上点击鼠标 “左”👈 键");
document.onclick = function(e){
e = e || window.event;
e.preventDefault();
var inputList = document.getElementsByTagName('input');
var textareaList = document.getElementsByTagName('textarea');
// console.log(inputList);
if (e.target.tagName == "INPUT") {
ruleData.inputType = "input";
for (var i = 0; i < inputList.length; i++) {
if (inputList[i] == e.target) {
if (inputList[0] && (inputList[0].id == "_w_simile" || inputList[0].id == "black_node")) {
var k = i - 1;
}
else {
var k = i;
}
}
}
}
else if (e.target.tagName == "TEXTAREA") {
ruleData.inputType = "textarea";
for (var i = 0; i < textareaList.length; i++) {
if (textareaList[i] == e.target) {
var k = i;
}
}
}
if (k == null) {
topNotice("选择有误,请重新点击验证码输入框");
return;
}
ruleData.input = k;
var r = confirm("选择验证码类型\n\n数/英验证码请点击“确定”,算术验证码请点击“取消”");
if (r == true) {
ruleData.captchaType = "general";
}
else {
ruleData.captchaType = "math";
}
addR(ruleData).then((res)=>{
if (res.status == 200){
topNotice("添加规则成功");
document.oncontextmenu = null;
document.onclick = null;
start();
}
else {
topNotice("Error,添加规则失败");
document.oncontextmenu = null;
document.onclick = null;
}
});
}
}
}
//手动添加规则(请求)
function addR(ruleData){
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: "POST",
url: queryUrl+"updateRule",
data: JSON.stringify(ruleData),
headers: {
"Content-Type": "application/json"
},
onload: function(response) {
return resolve(response);
}
});
});
}
//删除当前页面规则
function delRule(){
var ruleData = {"url": window.location.href.split("?")[0]}
delR(ruleData).then((res)=>{
if (res.status == 200)
topNotice("删除规则成功");
else
topNotice("Error,删除规则失败");
});
}
//删除规则(请求)
function delR(ruleData){
return new Promise((resolve, reject) => {
GM_xmlhttpRequest({
method: "POST",
url: queryUrl+"deleteRule",
data: JSON.stringify(ruleData),
headers: {
"Content-Type": "application/json"
},
onload: function(response) {
return resolve(response);
}
});
});
}
//按已存规则填充
function codeByRule(){
var code = "";
var src = element.src;
if (firstin){
firstin = false;
if (src.indexOf('data:image') != -1) {
// console.log(src);
code = src.split("base64,")[1];
GM_setValue("tempCode", code);
if (GM_getValue("tempCode") != GM_getValue("preCode")) {
// console.log("preCode:" + GM_getValue("preCode"))
// console.log("tempCode:" + GM_getValue("tempCode"))
GM_setValue("preCode", GM_getValue("tempCode"));
p1(code).then((ans) => {
if (ans != "")
writeIn1(ans);
else
codeByRule();
});
}
}
else if (src.indexOf('blob') != -1) {
const image = new Image()
image.src = src;
image.onload = () => {
const canvas = document.createElement('canvas')
canvas.width = image.width
canvas.height = image.height
const context = canvas.getContext('2d')
context.drawImage(image, 0, 0, image.width, image.height);
code = canvas.toDataURL().split("base64,")[1];
GM_setValue("tempCode", code);
if (GM_getValue("tempCode") != GM_getValue("preCode")) {
GM_setValue("preCode", GM_getValue("tempCode"));
p1(code).then((ans) => {
if (ans != "")
writeIn1(ans);
else
codeByRule();
});
}
}
}
else {
try {
var img = element;
if (img.src && img.width != 0 && img.height != 0) {
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0, img.width, img.height);
code = canvas.toDataURL("image/png").split("base64,")[1];
GM_setValue("tempCode", code);
if (GM_getValue("tempCode") != GM_getValue("preCode")) {
// console.log("preCode:" + GM_getValue("preCode"))
// console.log("tempCode:" + GM_getValue("tempCode"))
GM_setValue("preCode", GM_getValue("tempCode"));
p1(code).then((ans) => {
if (ans != "")
writeIn1(ans);
else
codeByRule();
});
}
}
else {
codeByRule();
}
}
catch(err){
return;
}
}
}
else {
if (src.indexOf('data:image') != -1) {
// console.log(src);
code = src.split("base64,")[1];
GM_setValue("tempCode", code);
if (GM_getValue("tempCode") != GM_getValue("preCode")) {
// console.log("preCode:" + GM_getValue("preCode"))
// console.log("tempCode:" + GM_getValue("tempCode"))
GM_setValue("preCode", GM_getValue("tempCode"));
p1(code).then((ans) => {
writeIn1(ans);
});
}
}
else if (src.indexOf('blob') != -1) {
const image = new Image()
image.src = src;
image.onload = () => {
const canvas = document.createElement('canvas')
canvas.width = image.width
canvas.height = image.height
const context = canvas.getContext('2d')
context.drawImage(image, 0, 0, image.width, image.height);
code = canvas.toDataURL().split("base64,")[1];
GM_setValue("tempCode", code);
if (GM_getValue("tempCode") != GM_getValue("preCode")) {
GM_setValue("preCode", GM_getValue("tempCode"));
p1(code).then((ans) => {
writeIn1(ans);
})
}
}
}
else {
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
element.onload = function() {
// console.log("img.onload");
canvas.width = element.width;
canvas.height = element.height;
ctx.drawImage(element, 0, 0, element.width, element.height);
code = canvas.toDataURL("image/png").split("base64,")[1];
GM_setValue("tempCode", code);
if (GM_getValue("tempCode") != GM_getValue("preCode")) {
// console.log("preCode:" + GM_getValue("preCode"))
// console.log("tempCode:" + GM_getValue("tempCode"))
GM_setValue("preCode", GM_getValue("tempCode"));
p1(code).then((ans) => {
writeIn1(ans);
});
}
}
}
}
}
function canvasRule(){
setTimeout(function(){
// console.log(element.toDataURL("image/png"));
try {
var code = element.toDataURL("image/png").split("base64,")[1];
GM_setValue("tempCode", code);
if (GM_getValue("tempCode") != GM_getValue("preCode")) {
// console.log("preCode:" + GM_getValue("preCode"))
// console.log("tempCode:" + GM_getValue("tempCode"))
GM_setValue("preCode", GM_getValue("tempCode"));
p1(code).then((ans) => {
writeIn1(ans);
});
}
}
catch(err){
canvasRule();
}
}, 100);
}
//寻找网页中的验证码
function findCode(k){
var code = '';
var codeList = document.getElementsByTagName('img');
// console.log(codeList);
for (var i = k; i < codeList.length; i++) {
var src = codeList[i].src;
element = codeList[i];
if (src.indexOf('data:image') != -1) {
if (isCode()) {
firstin = false;
code = src.split("base64,")[1];
// console.log('code: ' + code);
GM_setValue("tempCode", code);
if (GM_getValue("tempCode") != GM_getValue("preCode")) {
// console.log("preCode:" + GM_getValue("preCode"))
// console.log("tempCode:" + GM_getValue("tempCode"))
GM_setValue("preCode", GM_getValue("tempCode"));
p(code, i).then((ans) => {
writeIn(ans);
});
}
break;
}
}
else {
if (isCode()) {
if (firstin){
firstin = false;
var img = element;
if (img.src && img.width != 0 && img.height != 0) {
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0, img.width, img.height);
code = canvas.toDataURL("image/png").split("base64,")[1];
try{
code = canvas.toDataURL("image/png").split("base64,")[1];
}
catch(err){
//console.log(err);
findCode(i + 1);
return;
}
// console.log(code);
GM_setValue("tempCode", code);
if (GM_getValue("tempCode") != GM_getValue("preCode")) {
iscors = isCORS();
// console.log("preCode:" + GM_getValue("preCode"))
// console.log("tempCode:" + GM_getValue("tempCode"))
GM_setValue("preCode", GM_getValue("tempCode"));
p(code, i).then((ans) => {
if (ans != "")
writeIn(ans);
else
findCode(i);
});
return;
}
}
else{
findCode(i);
return;
}
}
else {
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
element.onload = function(){
canvas.width = element.width;
canvas.height = element.height;
ctx.drawImage(element, 0, 0, element.width, element.height);
try{
code = canvas.toDataURL("image/png").split("base64,")[1];
}
catch(err){
//console.log(err);
findCode(i + 1);
return;
}
// console.log(code);
GM_setValue("tempCode", code);
if (GM_getValue("tempCode") != GM_getValue("preCode")) {
iscors = isCORS();
// console.log("preCode:" + GM_getValue("preCode"))
// console.log("tempCode:" + GM_getValue("tempCode"))
GM_setValue("preCode", GM_getValue("tempCode"));
p(code, i).then((ans) => {
writeIn(ans);
});
return;
}
}
break;
}
}
}
}
}
//寻找网页中的验证码输入框
function findInput(){
var inputList = document.getElementsByTagName('input');
// console.log(inputList);
for (var i = 0; i < inputList.length; i++) {
input = inputList[i];
if (isInput()) {
return true;
}
}
}
//将识别结果写入验证码输入框(预设规则)
function writeIn(ans){
if (findInput()) {
ans = ans.replace(/\s+/g,"");
input.value = ans;
if (typeof(InputEvent)!=="undefined"){
input.value = ans;
input.dispatchEvent(new InputEvent('input'));
var eventList = ['input', 'change', 'focus', 'keypress', 'keyup', 'keydown', 'select'];
for (var i = 0; i < eventList.length; i++) {
fire(input, eventList[i]);
}
input.value = ans;
}
else if(KeyboardEvent) {
input.dispatchEvent(new KeyboardEvent("input"));
}
}
}
//识别验证码(预设规则)
function p(code, i){
return new Promise((resolve, reject) =>{
const datas = {
"ImageBase64": String(code),
}
GM_xmlhttpRequest({
method: "POST",
url: queryUrl + "identify_GeneralCAPTCHA",
data: JSON.stringify(datas),
headers: {
"Content-Type": "application/json",
},
responseType: "json",
onload: function(response) {
// console.log(response);
if (response.status == 200) {
if (response.responseText.indexOf("触发限流策略") != -1)
topNotice(response.response["msg"]);
try{
var result = response.response["result"];
console.log("识别结果:" + result);
return resolve(result);
}
catch(e){
if (response.responseText.indexOf("接口请求频率过高") != -1)
// console.log(response.responseText)
topNotice(response.responseText);
}
}
else {
try {
if (response.response["result"] == null)
findCode(i + 1);
else
console.log("识别失败");
}
catch(err){
console.log("识别失败");
}
}
}
});
});
}
//识别验证码(自定义规则)
function p1(code){
if (captchaType == "general" || captchaType == null) {
return new Promise((resolve, reject) =>{
const datas = {
"ImageBase64": String(code),
}
GM_xmlhttpRequest({
method: "POST",
url: queryUrl + "identify_GeneralCAPTCHA",
data: JSON.stringify(datas),
headers: {
"Content-Type": "application/json",
},
responseType: "json",
onload: function(response) {
// console.log(response);
if (response.status == 200) {
if (response.responseText.indexOf("触发限流策略") != -1)
topNotice(response.response["msg"]);
try{
var result = response.response["result"];
console.log("识别结果:" + result);
return resolve(result);
}
catch(e){
if (response.responseText.indexOf("接口请求频率过高") != -1)
// console.log(response.responseText)
topNotice(response.responseText);
}
}
else {
console.log("识别失败");
}
}
});
});
}
else if (captchaType == "math") {
if (GM_getValue("token") == undefined) {
topNotice("识别算术验证码请先填写云码Token");
return;
}
var token = GM_getValue("token").replace(/\+/g,'%2B');
const datas = {
"image": String(code),
"type": "50100",
"token": token,
"developer_tag": "41acabfb0d980a24e6022e89f9c1bfa4"
}
return new Promise((resolve, reject) =>{
GM_xmlhttpRequest({
method: "POST",
url: "https://www.jfbym.com/api/YmServer/customApi",
data: JSON.stringify(datas),
headers: {
"Content-Type": "application/json",
},
responseType: "json",
onload: function(response) {
// console.log(response);
if (response.response["msg"] == "识别成功") {
try{
var result = response.response["data"]["data"];
console.log("识别结果:" + result);
return resolve(result);
}
catch(e){
topNotice(response.response["msg"]);
}
}
else if (response.response["msg"] == "余额不足"){
topNotice("云码积分不足,请自行充值");
}
else {
topNotice("请检查Token是否正确");
}
}
});
});
}
}
//判断是否跨域
function isCORS(){
try {
if (element.src.indexOf('http') != -1 || element.src.indexOf('https') != -1) {
if (element.src.indexOf(window.location.host) == -1) {
console.log("检测到当前页面存在跨域问题");
return true;
}
//console.log("当前页面不存在跨域问题");
return false;
}
}
catch(err){
return;
}
}
//将url转换为base64(解决跨域问题)
function p2(){
return new Promise((resolve, reject) =>{
GM_xmlhttpRequest({
url: element.src,
method: "GET",
headers: {'Content-Type': 'application/json; charset=utf-8','path' : window.location.href},
responseType: "blob",
onload: function(response) {
// console.log(response);
let blob = response.response;
let reader = new FileReader();
reader.onloadend = (e) => {
let data = e.target.result;
element.src = data;
return resolve(data);
}
reader.readAsDataURL(blob);
}
});
});
}
//此段逻辑借鉴Crab大佬的代码,十分感谢
function fire(element,eventName){
var event = document.createEvent("HTMLEvents");
event.initEvent(eventName, true, true);
element.dispatchEvent(event);
}
function FireForReact(element, eventName) {
try {
let env = new Event(eventName);
element.dispatchEvent(env);
var funName = Object.keys(element).find(p => Object.keys(element[p]).find(f => f.toLowerCase().endsWith(eventName)));
if (funName != undefined) {
element[funName].onChange(env)
}
}
catch (e) {}
}
//将识别结果写入验证码输入框(自定义规则)
function writeIn1(ans){
ans = ans.replace(/\s+/g,"");
if (input.tagName == "TEXTAREA") {
input.innerHTML = ans;
}
else {
input.value = ans;
if (typeof(InputEvent)!=="undefined"){
input.value = ans;
input.dispatchEvent(new InputEvent('input'));
var eventList = ['input', 'change', 'focus', 'keypress', 'keyup', 'keydown', 'select'];
for (var i = 0; i < eventList.length; i++) {
fire(input, eventList[i]);
}
FireForReact(input, 'change');
input.value = ans;
}
else if(KeyboardEvent) {
input.dispatchEvent(new KeyboardEvent("input"));
}
}
}
//判断当前页面是否存在规则,返回布尔值
function compareUrl(){
return new Promise((resolve, reject) => {
var datas = {"url": window.location.href};
GM_xmlhttpRequest({
method: "POST",
url: queryUrl+"queryRule",
headers: {
"Content-Type": "application/json"
},
data: JSON.stringify(datas),
onload: function(response) {
// console.log(response);
try {
localRules = JSON.parse(response.responseText);
}
catch(err){
localRules = [];
}
if (localRules.length == 0)
return resolve(false);
return resolve(true);
}
});
});
}
//开始识别
function start(){
compareUrl().then((isExist) => {
if (isExist) {
exist = true;
console.log("【自动识别填充验证码】已存在该网站规则");
if (localRules["type"] == "img") {
captchaType = localRules["captchaType"];
imgIndex = localRules["img"];
inputIndex = localRules["input"];
element = document.getElementsByTagName('img')[imgIndex];
// console.log(element.src);
if (localRules["inputType"] == "textarea") {
input = document.getElementsByTagName('textarea')[inputIndex];
}
else {
input = document.getElementsByTagName('input')[inputIndex];
var inputList = document.getElementsByTagName('input');
// console.log(inputList);
if (inputList[0] && (inputList[0].id == "_w_simile" || inputList[0].id == "black_node")) {
inputIndex = parseInt(inputIndex) + 1;
input = inputList[inputIndex];
}
}
// console.log(input);
if (element && input) {
iscors = isCORS();
// console.log(input);
// console.log(element);
if (iscors) {
p2().then(() => {
// console.log(data);
codeByRule();
});
}
else {
codeByRule();
}
}
else
pageChange();
}
else if (localRules["type"] == "canvas") {
captchaType = localRules["captchaType"];
canvasIndex = localRules["img"];
inputIndex = localRules["input"];
element = document.getElementsByTagName('canvas')[canvasIndex];
if (localRules["inputType"] == "textarea") {
input = document.getElementsByTagName('textarea')[inputIndex];
}
else {
input = document.getElementsByTagName('input')[inputIndex];
var inputList = document.getElementsByTagName('input');
// console.log(inputList);
if (inputList[0] && (inputList[0].id == "_w_simile" || inputList[0].id == "black_node")) {
inputIndex = parseInt(inputIndex) + 1;
input = inputList[inputIndex];
}
}
iscors = isCORS();
if (iscors) {
p2().then(() => {
// console.log(data);
canvasRule();
});
}
else {
canvasRule();
}
}
}
else {
console.log("【自动识别填充验证码】不存在该网站规则,正在根据预设规则自动识别...");
findCode(0);
}
});
}
//页面变化执行函数
function pageChange(){
if (exist) {
if (localRules["type"] == "img" || localRules["type"] == null) {
element = document.getElementsByTagName('img')[imgIndex];
if (localRules["inputType"] == "textarea") {
input = document.getElementsByTagName('textarea')[inputIndex];
}
else {
input = document.getElementsByTagName('input')[inputIndex];
var inputList = document.getElementsByTagName('input');
if (inputList[0] && (inputList[0].id == "_w_simile" || inputList[0].id == "black_node")) {
input = inputList[inputIndex];
}
}
// console.log(element);
// console.log(input);
iscors = isCORS();
if (iscors) {
p2().then(() => {
// console.log(data);
codeByRule();
});
}
else {
codeByRule();
}
}
else if (localRules["type"] == "canvas") {
element = document.getElementsByTagName('canvas')[canvasIndex];
if (localRules["inputType"] == "textarea") {
input = document.getElementsByTagName('textarea')[inputIndex];
}
else {
input = document.getElementsByTagName('input')[inputIndex];
var inputList = document.getElementsByTagName('input');
if (inputList[0] && (inputList[0].id == "_w_simile" || inputList[0].id == "black_node")) {
input = inputList[inputIndex];
}
}
// console.log(element);
// console.log(input);
iscors = isCORS();
if (iscors) {
p2().then(() => {
// console.log(data);
canvasRule();
});
}
else {
canvasRule();
}
}
}
else {
findCode(0);
}
}
function topNotice(msg){
var div = document.createElement('div');
div.id = 'topNotice';
div.style.cssText = 'position: fixed; top: 0; left: 0; width: 100%; height: 5%; z-index: 9999999999; background: rgba(117,140,148,1); display: flex; justify-content: center; align-items: center; color: #fff; font-family: "Microsoft YaHei"; text-align: center;';
div.innerHTML = msg;
div.style.fontSize = 'medium';
document.body.appendChild(div);
setTimeout(function(){
document.body.removeChild(document.getElementById('topNotice'));
}, 3500);
}
function manageBlackList(){
var blackList = GM_getValue("blackList", []);
var div = document.createElement("div");
div.style.cssText = 'width: 700px; height: 350px; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: white; border: 1px solid black; z-index: 9999999999; text-align: center; padding-top: 20px; padding-bottom: 20px; padding-left: 20px; padding-right: 20px; box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.75); border-radius: 10px; overflow: auto;';
div.innerHTML = "<h3 style='margin-bottom: 12px; font-weight: bold; font-size: 18px;'>黑名单</h3><button style='position: absolute; top: 10px; left: 10px; width: 50px; height: 30px; line-height: 30px; text-align: center; font-size: 13px; margin: 10px' id='add'>添加</button><table id='blackList' style='width:100%; border-collapse:collapse; border: 1px solid black;'><thead style='background-color: #f5f5f5;'><tr><th style='width: 80%; text-align: center; padding: 5px;'>字符串</th><th style='width: 20%; text-align: center; padding: 5px;'>操作</th></tr></thead><tbody></tbody></table><button style='position: absolute; top: 10px; right: 10px; width: 30px; height: 30px; line-height: 30px; text-align: center; font-size: 18px; font-weight: bold; color: #333; background-color: transparent; border: none; outline: none; cursor: pointer;' id='close'>×</button>";
document.body.insertBefore(div, document.body.firstChild);
var table = document.getElementById("blackList").getElementsByTagName('tbody')[0];
for (var i = 0; i < blackList.length; i++) {
var row = table.insertRow(i);
row.insertCell(0).innerHTML = "<div style='white-space: nowrap; overflow: hidden; text-overflow: ellipsis;'>" + blackList[i] + "</div>";
var removeBtn = document.createElement("button");
removeBtn.className = "remove";
removeBtn.style.cssText = 'background-color: transparent; color: blue; border: none; padding: 5px; font-size: 14px; border-radius: 5px;';
removeBtn.innerText = "移除";
row.insertCell(1).appendChild(removeBtn);
}
var close = document.getElementById("close");
close.onclick = function(){
div.remove();
}
var add = document.getElementById("add");
add.onclick = function(){
var zz = prompt("请输入一个字符串,任何URL中包含该字符串的网页都将被加入黑名单");
if (zz == null) return;
var blackList = GM_getValue("blackList", []);
if (blackList.indexOf(zz) == -1) {
blackList.push(zz);
GM_setValue("blackList", blackList);
var row = table.insertRow(table.rows.length);
row.insertCell(0).innerHTML = "<div style='white-space: nowrap; overflow: hidden; text-overflow: ellipsis;'>" + zz + "</div>";
var removeBtn = document.createElement("button");
removeBtn.className = "remove";
removeBtn.style.cssText = "background-color: transparent; color: blue; border: none; padding: 5px; font-size: 14px; border-radius: 5px; cursor: pointer; ";
removeBtn.innerText = "移除";
row.insertCell(1).appendChild(removeBtn);
removeBtn.onclick = function(){
var index = this.parentNode.parentNode.rowIndex - 1;
blackList.splice(index, 1);
GM_setValue("blackList", blackList);
this.parentNode.parentNode.remove();
}
topNotice("添加黑名单成功,刷新页面生效")
}
else {
topNotice("该网页已在黑名单中");
}
}
var remove = document.getElementsByClassName("remove");
for (var i = 0; i < remove.length; i++) {
remove[i].onclick = function(){
var index = this.parentNode.parentNode.rowIndex - 1;
blackList.splice(index, 1);
GM_setValue("blackList", blackList);
this.parentNode.parentNode.remove();
topNotice("移除黑名单成功,刷新页面生效");
}
}
}
console.log("【自动识别填充验证码】正在运行...");
var url = window.location.href;
var blackList = GM_getValue("blackList", []);
var inBlack = blackList.some(function(blackItem) {
return url.includes(blackItem);
});
if (inBlack) {
console.log("【自动识别填充验证码】当前页面在黑名单中");
return;
} else {
start();
}
var imgSrc = "";
//监听页面变化
setTimeout(function(){