Skip to content

Commit b92b5d4

Browse files
authored
v1.5.0: 合并代码
1 parent db12612 commit b92b5d4

1 file changed

Lines changed: 26 additions & 21 deletions

File tree

tsdmAutoSignAndWork.user.js

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,16 @@ async function autoSign() {
4040
startWorking('sign', 'dsu_paulsign:sign', '签到', 80, (document, window) =>{
4141
let error = document.querySelector('#ct_shell > div:nth-child(1) > h1:nth-child(1)');
4242
if (error) {
43-
return error.textContent;
43+
return Promise.resolve(error.textContent);
4444
}
45-
window.Icon_selected('kx');
46-
document.getElementById('todaysay').value = '每日签到';
47-
setTimeout(() => {
48-
window.showWindow('qwindow', 'qiandao', 'post', '0');
49-
}, 3000);
45+
return new Promise((resolve) => {
46+
window.Icon_selected('kx');
47+
document.getElementById('todaysay').value = '每日签到';
48+
setTimeout(() => {
49+
resolve();
50+
window.showWindow('qwindow', 'qiandao', 'post', '0');
51+
}, 3000);
52+
});
5053
});
5154
}
5255

@@ -57,20 +60,23 @@ async function autoWork() {
5760
let [full, hh, mm, ss] = error.textContent.match(/(\d)(\d+)(\d+)/);
5861
let next = hh * 3600000 + mm * 60000 + ss * 1000;
5962
setTimeout(autoWork, next);
60-
return error.textContent;
63+
return Promise.resolve(error.textContent);
6164
}
6265
let index = 0;
63-
for (let a of document.querySelectorAll('#advids > div > a')) {
66+
return new Promise((resolve) => {
67+
for (let a of document.querySelectorAll('#advids > div > a')) {
68+
setTimeout(() => {
69+
a.removeAttribute('href');
70+
a.removeAttribute('target');
71+
a.click();
72+
}, index++ * 300);
73+
}
6474
setTimeout(() => {
65-
a.removeAttribute('href');
66-
a.removeAttribute('target');
67-
a.click();
68-
}, index++ * 300);
69-
}
70-
setTimeout(() => {
71-
document.querySelector('#stopad > a').click();
72-
setTimeout(autoWork, 21600000);
73-
}, 3000);
75+
resolve();
76+
document.querySelector('#stopad > a').click();
77+
setTimeout(autoWork, 21600000);
78+
}, 3000);
79+
});
7480
});
7581
}
7682

@@ -84,17 +90,16 @@ function startWorking(type, id, work, top, callback) {
8490
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`;
8591
iframe.src = `/plugin.php?id=${id}`;
8692
iframe.style.display = 'none';
87-
iframe.addEventListener('load', (evnet) => {
93+
iframe.addEventListener('load', async (evnet) => {
8894
popup.textContent = `开始${work}...`;
8995
let { contentDocument, contentWindow } = iframe;
9096
contentWindow.setTimeout = () => null;
91-
popup.textContent = callback(contentDocument, contentWindow) ?? `已完成${work}`;
97+
popup.textContent = await callback(contentDocument, contentWindow) ?? `已完成${work}`;
9298
setTimeout(() => {
9399
delete action[type];
94100
iframe.remove();
95101
popup.remove();
96-
iframe = null;
97-
popup = null;
102+
iframe = popup = null;
98103
}, 3000);
99104
});
100105
}

0 commit comments

Comments
 (0)