MCPcopy Create free account
hub / github.com/dajie111/nodeseek-userscript / scheduleNextHourlySign

Method scheduleNextHourlySign

Clockin.js:112–162  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

110
111 // 计算并设置下一个整点签到
112 scheduleNextHourlySign() {
113 if (!this.isMaster) return;
114
115 // 清除可能存在的旧定时器
116 if (this.nextSignTimer) {
117 clearTimeout(this.nextSignTimer);
118 this.nextSignTimer = null;
119 }
120
121 const now = new Date();
122 const nextHour = new Date(now);
123
124 // 设置为下一个整点
125 nextHour.setHours(now.getHours() + 1);
126 nextHour.setMinutes(0);
127 nextHour.setSeconds(0);
128 nextHour.setMilliseconds(0);
129
130 // 计算到下一个整点的毫秒数
131 const timeUntilNextHour = nextHour.getTime() - now.getTime();
132
133 // 获取当前小时
134 const currentHour = now.getHours();
135
136 // 获取上次签到的小时记录
137 const lastSignTimeStr = localStorage.getItem(STORAGE_KEYS.hourlySignTime);
138 let lastSignTime = null;
139 let lastSignHour = -1;
140
141 if (lastSignTimeStr) {
142 lastSignTime = new Date(parseInt(lastSignTimeStr));
143 lastSignHour = lastSignTime.getHours();
144 }
145
146 // 如果当前是整点(00分00秒)且这个小时还没签到过,立即签到
147 if (now.getMinutes() === 0 && now.getSeconds() === 0 && lastSignHour !== currentHour) {
148 this.performSignIn();
149 }
150
151 // 设置下一个整点的定时器
152 this.nextSignTimer = setTimeout(() => {
153 const hourToSign = nextHour.getHours();
154 this.performSignIn();
155
156 // 签到后再次设置下一个整点的定时器
157 this.scheduleNextHourlySign();
158 }, timeUntilNextHour);
159
160 // 将定时器ID添加到timers数组中,以便清理
161 this.timers.push(this.nextSignTimer);
162 }
163
164 // 执行签到API
165 async performSignIn() {

Callers 1

becomeMasterMethod · 0.95

Calls 1

performSignInMethod · 0.95

Tested by

no test coverage detected