tronclass-auto 1.5.2 → 1.5.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 +10 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tronclass-auto",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "自動觀看 eclass/TronClass 影片、填寫表單的 CLI 工具",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/video.js CHANGED
@@ -21,27 +21,22 @@ function log(msg) {
21
21
  }
22
22
 
23
23
  async function detectPlayerType(page) {
24
- return page.evaluate(() => {
24
+ const type = await page.evaluate(() => {
25
25
  const v = document.querySelector('video');
26
26
  if (v) return 'html5';
27
-
28
27
  const yt = document.querySelector('iframe[src*="youtube"], iframe[src*="youtu.be"], iframe[src*="vimeo"]');
29
28
  if (yt) return 'youtube';
30
-
31
29
  for (const f of document.querySelectorAll('iframe')) {
32
- try {
33
- if (f.contentDocument && f.contentDocument.querySelector('video')) return 'html5';
34
- } catch (e) {}
30
+ try { if (f.contentDocument && f.contentDocument.querySelector('video')) return 'html5'; } catch (e) {}
35
31
  }
36
32
  return 'none';
37
- }).then(async (type) => {
38
- if (type === 'none') {
39
- for (const f of page.frames) {
40
- if (f.url && (f.url.includes('youtube') || f.url.includes('youtu.be'))) return 'youtube';
41
- }
42
- }
43
- return type;
44
33
  });
34
+ if (type !== 'none') return type;
35
+ try {
36
+ const ytFrame = page.frame({ url: /youtube|youtu\.be/ });
37
+ if (ytFrame) return 'youtube';
38
+ } catch (e) {}
39
+ return 'none';
45
40
  }
46
41
 
47
42
  async function watchVideo(page, stats) {
@@ -64,13 +59,7 @@ async function watchYouTube(page, stats) {
64
59
  let rate = 1;
65
60
 
66
61
  try {
67
- let ytFrame = null;
68
- for (const f of page.frames) {
69
- if (f.url && (f.url.includes('youtube') || f.url.includes('youtu.be'))) {
70
- ytFrame = f;
71
- break;
72
- }
73
- }
62
+ const ytFrame = page.frame({ url: /youtube|youtu\.be/ });
74
63
 
75
64
  if (!ytFrame) {
76
65
  log(chalk.yellow(' YouTube frame not found'));
@@ -102,7 +91,7 @@ async function watchYouTube(page, stats) {
102
91
  if (state2 === 1) {
103
92
  log(chalk.green(' Playing ✓'));
104
93
  } else {
105
- log(chalk.yellow(` State: ${state2} (may still be loading)`));
94
+ log(chalk.yellow(` State: ${state2}`));
106
95
  }
107
96
  } catch (e) {
108
97
  log(chalk.yellow(` YouTube error: ${e.message}`));