tronclass-auto 1.2.3 → 1.2.4

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tronclass-auto",
3
- "version": "1.2.3",
3
+ "version": "1.2.4",
4
4
  "description": "自動觀看 eclass/TronClass 影片、填寫表單的 CLI 工具",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/index.js CHANGED
@@ -103,7 +103,7 @@ async function processCourse(page, courseId, stats) {
103
103
  if (success) {
104
104
  markDone(courseId, act.id);
105
105
  done++;
106
- console.log(chalk.green(' [OK] Saved'));
106
+ console.log(chalk.green(' ✓ Saved'));
107
107
  } else {
108
108
  fail++;
109
109
  }
package/src/video.js CHANGED
@@ -15,11 +15,11 @@ function formatTime(seconds) {
15
15
  async function watchVideo(page, stats) {
16
16
  const hasVideo = await page.evaluate(() => document.querySelector('video') !== null);
17
17
  if (!hasVideo) {
18
- log(chalk.yellow(' [VIDEO] No video element'));
18
+ log(chalk.yellow(' No video element'));
19
19
  return false;
20
20
  }
21
21
 
22
- log(chalk.blue(' [VIDEO] Muted + 2x speed'));
22
+ log(chalk.blue(' Muted + 2x'));
23
23
 
24
24
  await page.evaluate(() => {
25
25
  document.querySelectorAll('video').forEach(v => {
@@ -38,7 +38,7 @@ async function watchVideo(page, stats) {
38
38
  });
39
39
 
40
40
  if (!isPlaying) {
41
- log(chalk.yellow(' [VIDEO] Clicking play...'));
41
+ log(chalk.yellow(' Clicking play...'));
42
42
  await page.evaluate(() => {
43
43
  document.querySelectorAll('[class*="play"], .vjs-big-play-button, button').forEach(btn => {
44
44
  if (btn.offsetParent && (btn.className.includes('play') || btn.className.includes('Play'))) {
@@ -56,14 +56,14 @@ async function watchVideo(page, stats) {
56
56
  });
57
57
 
58
58
  if (!duration || duration <= 0) {
59
- log(chalk.yellow(' [VIDEO] Cannot get duration, waiting 30s...'));
59
+ log(chalk.yellow(' Cannot get duration, waiting 30s...'));
60
60
  await page.waitForTimeout(30000);
61
61
  if (stats) stats.videosWatched++;
62
62
  return true;
63
63
  }
64
64
 
65
65
  const waitTime = (duration / 2) + 15;
66
- log(chalk.blue(` [VIDEO] ${formatTime(duration)} video, waiting ~${formatTime(waitTime)} (2x)`));
66
+ log(chalk.blue(` ${formatTime(duration)} video → ~${formatTime(waitTime)} (2x)`));
67
67
 
68
68
  if (stats) {
69
69
  stats.currentVideoDuration = duration / 2;
@@ -93,26 +93,30 @@ async function watchVideo(page, stats) {
93
93
 
94
94
  if (state.p > lastPct) {
95
95
  const pct = state.p;
96
+ const barWidth = 20;
97
+ const filled = Math.floor(barWidth * pct / 100);
98
+ const empty = barWidth - filled;
99
+ const bar = chalk.green('█'.repeat(filled)) + chalk.gray('░'.repeat(empty));
96
100
  const remaining = Math.max(0, waitTime - elapsed);
97
101
  let etaStr = '';
98
102
  if (stats && stats.remainingVideos > 0) {
99
103
  const totalRemaining = remaining + stats.estimatedTimeForRemaining;
100
- etaStr = chalk.gray(` | ETA: ${formatTime(totalRemaining)}`);
104
+ etaStr = chalk.gray(` | ETA ${formatTime(totalRemaining)}`);
101
105
  } else {
102
- etaStr = chalk.gray(` | ~${formatTime(remaining)} left`);
106
+ etaStr = chalk.gray(` | ${formatTime(remaining)} left`);
103
107
  }
104
- log(chalk.blue(` [VIDEO] ${pct}% (${formatTime(elapsed)})${etaStr}`));
108
+ log(chalk.blue(` ${bar} ${String(pct).padStart(3)}% (${formatTime(elapsed)})${etaStr}`));
105
109
  lastPct = pct;
106
110
  }
107
111
 
108
112
  if (state.e) {
109
- log(chalk.green(' [VIDEO] 100% Finished'));
113
+ log(chalk.green(' Done ✓'));
110
114
  break;
111
115
  }
112
116
 
113
117
  if (state.stalled) {
114
118
  if (elapsed % 15 === 0) {
115
- log(chalk.gray(` [VIDEO] Buffering... (${formatTime(elapsed)})`));
119
+ log(chalk.gray(` Buffering... (${formatTime(elapsed)})`));
116
120
  }
117
121
  continue;
118
122
  }
@@ -127,10 +131,10 @@ async function watchVideo(page, stats) {
127
131
 
128
132
  restartCount++;
129
133
  if (restartCount > 10) {
130
- log(chalk.red(' [VIDEO] Too many restarts, giving up'));
134
+ log(chalk.red(' Too many restarts, giving up'));
131
135
  return false;
132
136
  }
133
- log(chalk.yellow(` [VIDEO] Paused, restarting (#${restartCount})...`));
137
+ log(chalk.yellow(` Paused, restarting (#${restartCount})...`));
134
138
  await page.evaluate(() => document.querySelector('video').play());
135
139
  await page.waitForTimeout(1000);
136
140
  }