tronclass-auto 1.3.4 → 1.3.5

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/index.js +19 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tronclass-auto",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
4
4
  "description": "自動觀看 eclass/TronClass 影片、填寫表單的 CLI 工具",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -110,27 +110,33 @@ async function processCourse(page, courseId, stats) {
110
110
  try {
111
111
  await page.goto(url, { waitUntil: 'domcontentloaded', timeout: 15000 });
112
112
  } catch (e) {}
113
- await page.waitForTimeout(5000);
113
+ await page.waitForTimeout(8000);
114
114
 
115
115
  if (!page.url().includes('learning-activity')) {
116
- console.log(chalk.yellow(' Locked (page redirect), skipping rest'));
116
+ console.log(chalk.yellow(' Page redirect, skipping'));
117
117
  markLocked(courseId, act.id);
118
118
  break;
119
119
  }
120
120
 
121
- const hasVideo = await page.evaluate(() => document.querySelector('video') !== null);
122
- if (!hasVideo) {
123
- consecutiveLocked++;
124
- if (consecutiveLocked >= 2) {
125
- console.log(chalk.yellow(' Locked (no video), stopping this course'));
126
- markLocked(courseId, act.id);
127
- break;
121
+ const hasVideo = await page.evaluate(() => {
122
+ if (document.querySelector('video')) return true;
123
+ for (const f of document.querySelectorAll('iframe')) {
124
+ try { if (f.contentDocument && f.contentDocument.querySelector('video')) return true; } catch (e) {}
128
125
  }
129
- console.log(chalk.yellow(' No video, might be loading... waiting'));
130
- await page.waitForTimeout(5000);
131
- const hasVideoNow = await page.evaluate(() => document.querySelector('video') !== null);
126
+ return false;
127
+ });
128
+ if (!hasVideo) {
129
+ console.log(chalk.yellow(' No video, waiting more...'));
130
+ await page.waitForTimeout(10000);
131
+ const hasVideoNow = await page.evaluate(() => {
132
+ if (document.querySelector('video')) return true;
133
+ for (const f of document.querySelectorAll('iframe')) {
134
+ try { if (f.contentDocument && f.contentDocument.querySelector('video')) return true; } catch (e) {}
135
+ }
136
+ return false;
137
+ });
132
138
  if (!hasVideoNow) {
133
- console.log(chalk.yellow(' Still no video, locked'));
139
+ console.log(chalk.yellow(' Still no video, skipping (not a video activity)'));
134
140
  markLocked(courseId, act.id);
135
141
  break;
136
142
  }