tronclass-auto 1.3.6 → 1.3.8

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 +24 -7
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tronclass-auto",
3
- "version": "1.3.6",
3
+ "version": "1.3.8",
4
4
  "description": "自動觀看 eclass/TronClass 影片、填寫表單的 CLI 工具",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/video.js CHANGED
@@ -56,18 +56,34 @@ async function watchVideo(page, stats) {
56
56
  }
57
57
 
58
58
  async function watchYouTube(page, stats) {
59
- log(chalk.blue(' YouTube embed (platform tracks progress)'));
59
+ log(chalk.blue(' YouTube embed'));
60
60
 
61
- await page.evaluate(() => {
61
+ const speedSet = await page.evaluate(() => {
62
62
  const f = document.querySelector('iframe[src*="youtube"], iframe[src*="youtu.be"]');
63
- if (!f) return;
63
+ if (!f) return false;
64
+ const src = f.src || '';
65
+ if (!src.includes('enablejsapi=1')) return false;
64
66
  try {
65
- f.contentWindow.postMessage(JSON.stringify({ event: 'command', func: 'setPlaybackRate', args: [2] }), '*');
66
67
  f.contentWindow.postMessage(JSON.stringify({ event: 'command', func: 'mute', args: [] }), '*');
68
+ f.contentWindow.postMessage(JSON.stringify({ event: 'command', func: 'setPlaybackRate', args: [2] }), '*');
67
69
  f.contentWindow.postMessage(JSON.stringify({ event: 'command', func: 'playVideo', args: [] }), '*');
68
- } catch (e) {}
70
+ return true;
71
+ } catch (e) { return false; }
69
72
  });
70
73
 
74
+ try {
75
+ const frame = page.frameLocator('iframe[src*="youtube"], iframe[src*="youtu.be"]');
76
+ const playBtn = frame.locator('.ytp-large-play-button, .ytp-play-button, button[aria-label*="Play"], button[aria-label*="play"]');
77
+ await playBtn.first().click({ timeout: 5000 }).catch(() => {});
78
+ } catch (e) {}
79
+
80
+ try {
81
+ const ytFrame = page.locator('iframe[src*="youtube"], iframe[src*="youtu.be"]');
82
+ await ytFrame.click({ timeout: 3000 }).catch(() => {});
83
+ } catch (e) {}
84
+
85
+ await page.waitForTimeout(3000);
86
+
71
87
  const ytDuration = await page.evaluate(() => {
72
88
  const actText = document.querySelector('.activity-attribute, [class*="attribute"]');
73
89
  if (actText) {
@@ -77,8 +93,9 @@ async function watchYouTube(page, stats) {
77
93
  return 180;
78
94
  });
79
95
 
80
- const waitTime = Math.ceil(ytDuration / 2) + 30;
81
- log(chalk.blue(` ~${formatTime(ytDuration)} video → waiting ~${formatTime(waitTime)} (2x)`));
96
+ const speed = speedSet ? 2 : 1;
97
+ const waitTime = Math.ceil(ytDuration / speed) + 30;
98
+ log(chalk.blue(` ~${formatTime(ytDuration)} video → ~${formatTime(waitTime)} (${speed}x${speedSet ? '' : ', no speed control'})`));
82
99
 
83
100
  let elapsed = 0;
84
101
  let lastPct = -1;