11// ==UserScript==
22// @name 天使动漫自动签到打工
33// @namespace https://github.com/jc3213/userscript
4- // @version 1.4.3
4+ // @version 1.5.0
55// @description 天使动漫全自动打工签到脚本 — 完全自动无需任何操作,只需静待一分钟左右
66// @author jc3213
77// @match *://www.tsdm39.com/*
@@ -13,7 +13,6 @@ let action = {};
1313let today = new Date ( ) ;
1414let date = today . getFullYear ( ) + today . getMonth ( ) + today . getDate ( ) ;
1515let now = today . getTime ( ) ;
16- let sleep = ( e ) => new Promise ( ( r ) => setTimeout ( r , e ) ) ;
1716let [ e_work , e_sign ] = document . querySelectorAll ( '#mn_Nfded_menu > li > a' ) ;
1817
1918if ( location . pathname === '/forum.php' && document . getElementById ( 'tsdm_newpm' ) ) {
@@ -22,8 +21,7 @@ if (location.pathname === '/forum.php' && document.getElementById('tsdm_newpm'))
2221 }
2322 if ( now > worked ) {
2423 autoWork ( ) ;
25- }
26- else {
24+ } else {
2725 setTimeout ( autoWork , worked - now ) ;
2826 }
2927}
@@ -39,83 +37,64 @@ e_sign.addEventListener('click', event => {
3937} ) ;
4038
4139async function autoSign ( ) {
42- if ( action . signed ) {
43- return ;
44- }
45- action . signed = true ;
46- let text ;
47- let popup = startPopup ( '查询签到状态...' , '80px' ) ;
48- let iframe = await startWork ( '/plugin.php?id=dsu_paulsign:sign' ) ;
49- let error = iframe . document . querySelector ( '#ct_shell > div:nth-child(1) > h1:nth-child(1)' ) ;
50- if ( error ) {
51- text = error . innerText ;
52- }
53- else {
54- popup . innerText = '开始签到...' ;
55- iframe . window . Icon_selected ( 'kx' ) ;
56- iframe . document . getElementById ( 'todaysay' ) . value = '每日签到' ;
57- await sleep ( 3000 ) ;
58- iframe . window . showWindow ( 'qwindow' , 'qiandao' , 'post' , '0' ) ;
59- text = '已完成签到' ;
60- }
61- endWork ( 'signed' , date , text , popup , iframe . window ) ;
40+ startWorking ( 'sign' , 'dsu_paulsign:sign' , '签到' , 80 , ( document , window ) => {
41+ let error = document . querySelector ( '#ct_shell > div:nth-child(1) > h1:nth-child(1)' ) ;
42+ if ( error ) {
43+ return error . textContent ;
44+ }
45+ window . Icon_selected ( 'kx' ) ;
46+ document . getElementById ( 'todaysay' ) . value = '每日签到' ;
47+ setTimeout ( ( ) => {
48+ window . showWindow ( 'qwindow' , 'qiandao' , 'post' , '0' ) ;
49+ } , 3000 ) ;
50+ } ) ;
6251}
6352
6453async function autoWork ( ) {
65- if ( action . worked ) {
66- return ;
67- }
68- let text , next ;
69- action . worked = true ;
70- let popup = startPopup ( '查询打工状态...' , '120px' ) ;
71- let iframe = await startWork ( '/plugin.php?id=np_cliworkdz:work' ) ;
72- if ( iframe . document . querySelector ( '#messagetext' ) ) {
73- text = iframe . document . querySelector ( '#messagetext > p:nth-child(1)' ) . innerHTML . split ( / < b r > | < s c r i p t / ) [ 1 ] ;
74- let [ full , hh , mm , ss ] = text . match ( / ( \d ) 小 时 ( \d + ) 分 钟 ( \d + ) 秒 / ) ;
75- next = hh * 3600000 + mm * 60000 + ss * 1000 ;
76- }
77- else {
78- popup . innerText = '开始打工...' ;
54+ startWorking ( 'work' , 'np_cliworkdz:work' , '打工' , 120 , ( document , window ) => {
55+ let error = document . querySelector ( '#messagetext > p:first-of-type' ) ?. childNodes ?. [ 2 ] ;
56+ if ( error ) {
57+ let [ full , hh , mm , ss ] = error . textContent . match ( / ( \d ) 小 时 ( \d + ) 分 钟 ( \d + ) 秒 / ) ;
58+ let next = hh * 3600000 + mm * 60000 + ss * 1000 ;
59+ setTimeout ( autoWork , next ) ;
60+ return error . textContent ;
61+ }
7962 let index = 0 ;
80- for ( let a of iframe . document . querySelectorAll ( '#advids > div > a' ) ) {
81- a . removeAttribute ( 'href' ) ;
82- a . removeAttribute ( 'target' ) ;
83- await sleep ( index ++ * 300 ) ;
84- a . click ( ) ;
63+ for ( let a of document . querySelectorAll ( '#advids > div > a' ) ) {
64+ setTimeout ( ( ) => {
65+ a . removeAttribute ( 'href' ) ;
66+ a . removeAttribute ( 'target' ) ;
67+ a . click ( ) ;
68+ } , index ++ * 300 ) ;
8569 }
86- await sleep ( 3000 ) ;
87- iframe . document . querySelector ( '#stopad > a' ) . click ( ) ;
88- text = '已完成打工' ;
89- next = 21600000 ;
90- setTimeout ( autoWork , next ) ;
91- }
92- endWork ( 'worked' , Date . now ( ) + next , text , popup , iframe . window ) ;
93- }
94-
95- async function endWork ( work , value , text , popup , frame ) {
96- action [ work ] = false ;
97- localStorage [ work ] = self [ work ] = value ;
98- popup . innerText = text ;
99- await sleep ( 5000 ) ;
100- frame . frameElement . remove ( ) ;
101- popup . remove ( ) ;
70+ setTimeout ( ( ) => {
71+ document . querySelector ( '#stopad > a' ) . click ( ) ;
72+ setTimeout ( autoWork , 21600000 ) ;
73+ } , 3000 ) ;
74+ } ) ;
10275}
10376
104- function startPopup ( string , top ) {
77+ function startWorking ( type , id , work , top , callback ) {
78+ if ( action [ type ] ) return ;
79+ action [ type ] = true ;
10580 let popup = document . createElement ( 'div' ) ;
106- popup . innerText = string ;
107- popup . style . cssText = 'border-radius: 5px; background-color: #FFF; padding: 5px; position: fixed; width: 380px; text-align: center; left: ' + ( document . documentElement . clientWidth - 380 ) / 2 + 'px; font-size: 16px; top: ' + top ;
108- document . body . append ( popup ) ;
109- return popup ;
110- }
111-
112- function startWork ( url ) {
113- return new Promise ( resolve => {
114- let iframe = document . createElement ( 'iframe' ) ;
115- iframe . src = url ;
116- iframe . style . display = 'none' ;
117- iframe . addEventListener ( 'load' , event => resolve ( { document : iframe . contentDocument , window : iframe . contentWindow } ) ) ;
118- document . body . append ( iframe ) ;
119- iframe . contentWindow . setTimeout = ( ) => null ;
81+ let iframe = document . createElement ( 'iframe' ) ;
82+ document . body . append ( iframe , popup ) ;
83+ popup . textContent = `查询${ work } 状态...` ;
84+ popup . style . cssText = `border-radius: 5px; background-color: #FFF; padding: 5px; position: fixed; width: 380px; text-align: center; font-size: 16px; left: ${ window . innerWidth / 2 - 190 } px; top: ${ top } px` ;
85+ iframe . src = `/plugin.php?id=${ id } ` ;
86+ iframe . style . display = 'none' ;
87+ iframe . addEventListener ( 'load' , ( evnet ) => {
88+ popup . textContent = `开始${ work } ...` ;
89+ let { contentDocument, contentWindow } = iframe ;
90+ contentWindow . setTimeout = ( ) => null ;
91+ popup . textContent = callback ( contentDocument , contentWindow ) ?? `已完成${ work } ` ;
92+ setTimeout ( ( ) => {
93+ delete action [ type ] ;
94+ iframe . remove ( ) ;
95+ popup . remove ( ) ;
96+ iframe = null ;
97+ popup = null ;
98+ } , 3000 ) ;
12099 } ) ;
121100}
0 commit comments