1+ // ==UserScript==
2+ // @name 注册邀请码抢码工具
3+ // @name :en Tool for register with invite code
4+ // @name :zh-TW 注冊邀請碼搶碼工具
5+ // @namespace hoothin
6+ // @version 0.1
7+ // @description 自动遍历论坛注册邀请码得出正确结果
8+ // @description :en Just a tool for register with invite code
9+ // @description :zh-TW 自動遍歷論壇注冊邀請碼得出正確結果
10+ // @author hoothin
11+ // @include *
12+ // @grant GM_registerMenuCommand
13+ // @grant GM_setValue
14+ // @grant GM_getValue
15+ // @grant GM_deleteValue
16+ // @grant unsafeWindow
17+ // @license MIT License
18+ // @compatible chrome
19+ // @compatible firefox
20+ // ==/UserScript==
21+
22+ ( function ( ) {
23+ 'use strict' ;
24+ var is1024 = document . title . indexOf ( '\u8349\u69b4' ) != - 1 ;
25+ var invitecode = document . querySelector ( ( is1024 ?"#invcode" :"#invitecode" ) ) ,
26+ chkInvitecode = document . querySelector ( ( is1024 ?"#check_info_invcode" :"#chk_invitecode" ) ) ,
27+ codeChar = [ "0" , "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" , "i" , "j" , "k" , "l" , "m" , "n" , "o" , "p" , "q" , "r" , "s" , "t" , "u" , "v" , "w" , "x" , "y" , "z" ] , checkFun , checkinvite , preTxt = "" , codeArr ;
28+ String . prototype . pmatch = function ( reg ) {
29+ if ( ! ( reg instanceof RegExp ) ) return 0 ;
30+ var a = [ ] ;
31+ if ( ! reg . global ) {
32+ a = this . match ( reg ) ;
33+ return a ? [ a . slice ( 1 , a . length ) ] : 0 ;
34+ }
35+ var b = reg . exec ( this ) ;
36+ while ( b ) {
37+ b . shift ( ) ;
38+ a . push ( b [ 0 ] ) ;
39+ b = reg . exec ( this ) ;
40+ }
41+ return a . length > 0 ?a :0 ;
42+ } ;
43+ function checkCode ( ) {
44+ if ( checkFun ) clearInterval ( checkFun ) ;
45+ var checkNext = function ( ) {
46+ if ( codeArr . length === 0 ) {
47+ alert ( "沒有找到正確的邀請碼!" ) ;
48+ return ;
49+ }
50+ invitecode . value = codeArr . shift ( ) ;
51+ if ( is1024 ) {
52+ unsafeWindow . invcodecheck ( ) ;
53+ } else {
54+ unsafeWindow . checkinvite ( ) ;
55+ }
56+ } ;
57+ checkFun = setInterval ( function ( ) {
58+ if ( preTxt != chkInvitecode . innerHTML ) {
59+ preTxt = chkInvitecode . innerHTML ;
60+ if ( chkInvitecode . innerHTML ) {
61+ if ( is1024 ) {
62+ if ( checkinvite ) clearInterval ( checkinvite ) ;
63+ if ( chkInvitecode . innerHTML . indexOf ( "green" ) != - 1 ) {
64+ clearInterval ( checkFun ) ;
65+ alert ( "已匹配到正確的邀請碼!" ) ;
66+ } else if ( chkInvitecode . innerHTML . indexOf ( "red" ) != - 1 ) {
67+ checkNext ( ) ;
68+ checkinvite = setInterval ( function ( ) { unsafeWindow . invcodecheck ( ) ; } , 2000 ) ;
69+ }
70+ } else {
71+ if ( chkInvitecode . innerHTML . indexOf ( "邀请码错误" ) == - 1 ) {
72+ clearInterval ( checkFun ) ;
73+ alert ( "已匹配到正確的邀請碼!" ) ;
74+ } else {
75+ checkNext ( ) ;
76+ }
77+ }
78+ }
79+ }
80+ } , 100 ) ;
81+ checkNext ( ) ;
82+ }
83+ function geneCodeArr ( ) {
84+ var tempCode = [ ] ;
85+ codeArr . forEach ( function ( item ) {
86+ if ( item . indexOf ( "*" ) != - 1 ) {
87+ for ( var char of codeChar ) {
88+ var tempItem = item . replace ( / \* / , char ) ;
89+ if ( tempCode . toString ( ) . indexOf ( tempItem ) == - 1 ) {
90+ tempCode . push ( tempItem ) ;
91+ }
92+ }
93+ } else if ( tempCode . toString ( ) . indexOf ( item ) == - 1 ) {
94+ tempCode . push ( item ) ;
95+ }
96+ } ) ;
97+ codeArr = [ ] ;
98+ while ( tempCode . length > 0 ) {
99+ var random = Math . floor ( Math . random ( ) * tempCode . length ) ;
100+ var curCode = tempCode [ random ] ;
101+ codeArr . push ( curCode ) ;
102+ tempCode . splice ( random , 1 ) ;
103+ }
104+ }
105+ if ( invitecode ) {
106+ var copiedCode = GM_getValue ( "copiedCode" ) ;
107+ if ( copiedCode ) {
108+ GM_deleteValue ( "copiedCode" ) ;
109+ codeArr = copiedCode ;
110+ checkCode ( ) ;
111+ }
112+ GM_registerMenuCommand ( "开始筛选邀请码" , function ( ) {
113+ var codeStr = prompt ( "输入邀请码:" , "" ) ;
114+ if ( ! codeStr ) return ;
115+ codeArr = codeStr . pmatch ( ( is1024 ?/ \b ( [ 0 - 9 a - z \* ] { 16 } ) \b / gi :/ \b ( [ 0 - 9 a - z ] { 6 } ) (?: \s | $ ) / gi) ) ;
116+ if ( codeArr === 0 ) return ;
117+ geneCodeArr ( ) ;
118+ checkCode ( ) ;
119+ } ) ;
120+ } else {
121+ if ( is1024 ) {
122+ codeArr = document . body . innerHTML . pmatch ( / (?: ^ | [ ^ \/ ] ) \b ( [ 0 - 9 a - z \* ] { 16 } ) \b / gi) ;
123+ if ( codeArr !== 0 ) {
124+ if ( window . confirm ( "檢測到邀請碼,是否立即前往注冊?" ) ) {
125+ geneCodeArr ( ) ;
126+ GM_setValue ( "copiedCode" , codeArr ) ;
127+ location . href = "/register.php" ;
128+ }
129+ }
130+ }
131+ }
132+ } ) ( ) ;
0 commit comments