tronclass-auto 1.4.2 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/video.js +22 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tronclass-auto",
3
- "version": "1.4.2",
3
+ "version": "1.4.3",
4
4
  "description": "自動觀看 eclass/TronClass 影片、填寫表單的 CLI 工具",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/video.js CHANGED
@@ -160,7 +160,28 @@ async function watchYouTube(page, stats) {
160
160
  }
161
161
 
162
162
  log(chalk.green(' Done ✓'));
163
- await page.waitForTimeout(2000);
163
+ log(chalk.gray(' Syncing with platform...'));
164
+
165
+ for (let i = 0; i < 5; i++) {
166
+ await page.evaluate(() => {
167
+ const f = document.querySelector('iframe[src*="youtube"], iframe[src*="youtu.be"]');
168
+ if (!f) return;
169
+ try {
170
+ f.contentWindow.postMessage(JSON.stringify({ event: 'command', func: 'seekTo', args: [670, true] }), '*');
171
+ f.contentWindow.postMessage(JSON.stringify({ event: 'command', func: 'playVideo', args: [] }), '*');
172
+ } catch(e) {}
173
+ });
174
+ await page.waitForTimeout(3000);
175
+ await page.evaluate(() => {
176
+ const f = document.querySelector('iframe[src*="youtube"], iframe[src*="youtu.be"]');
177
+ if (!f) return;
178
+ try {
179
+ f.contentWindow.postMessage(JSON.stringify({ event: 'command', func: 'pauseVideo', args: [] }), '*');
180
+ } catch(e) {}
181
+ });
182
+ await page.waitForTimeout(2000);
183
+ }
184
+
164
185
  if (stats) stats.videosWatched++;
165
186
  return true;
166
187
  }