tronclass-auto 1.2.4 → 1.2.7

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.4",
3
+ "version": "1.2.7",
4
4
  "description": "自動觀看 eclass/TronClass 影片、填寫表單的 CLI 工具",
5
5
  "main": "src/index.js",
6
6
  "bin": {
package/src/auth.js CHANGED
@@ -85,7 +85,7 @@ async function autoLogin(baseUrl) {
85
85
  const exePath = await ensureBrowser();
86
86
 
87
87
  const { chromium } = require('playwright');
88
- const launchOpts = { headless: false, slowMo: 50 };
88
+ const launchOpts = { headless: false, slowMo: 50, args: ['--disable-background-timer-throttling'] };
89
89
  if (exePath) launchOpts.executablePath = exePath;
90
90
 
91
91
  const browser = await chromium.launch(launchOpts);
package/src/index.js CHANGED
@@ -130,7 +130,7 @@ async function showStatus() {
130
130
  const { chromium } = re('playwright');
131
131
  const { ensureBrowser } = re('./browser');
132
132
  const exePath = await ensureBrowser();
133
- const launchOpts = { headless: true, slowMo: 50 };
133
+ const launchOpts = { headless: true, slowMo: 50, args: ['--disable-gpu', '--disable-software-rasterizer'] };
134
134
  if (exePath) launchOpts.executablePath = exePath;
135
135
  const browser = await chromium.launch(launchOpts);
136
136
  const context = await browser.newContext();
@@ -195,7 +195,16 @@ async function launchBrowser(headless) {
195
195
  const { chromium } = re('playwright');
196
196
  const { ensureBrowser } = re('./browser');
197
197
  const exePath = await ensureBrowser();
198
- const launchOpts = { headless, slowMo: 50 };
198
+ const launchOpts = {
199
+ headless,
200
+ slowMo: 50,
201
+ args: [
202
+ '--disable-accelerated-video-decode',
203
+ '--disable-background-timer-throttling',
204
+ '--disable-backgrounding-occluded-windows',
205
+ '--disable-renderer-backgrounding',
206
+ ]
207
+ };
199
208
  if (exePath) launchOpts.executablePath = exePath;
200
209
  const browser = await chromium.launch(launchOpts);
201
210
  const context = await browser.newContext({
package/src/tui.js CHANGED
@@ -2,6 +2,7 @@ const inquirer = require('inquirer');
2
2
  const chalk = require('chalk');
3
3
  const { loadConfig, saveConfig, BASE_URL } = require('./config');
4
4
  const { loadCookies } = require('./auth');
5
+ const pkg = require('../package.json');
5
6
 
6
7
  function box(lines, width = 52) {
7
8
  const top = '╔' + '═'.repeat(width - 2) + '╗';
@@ -25,7 +26,7 @@ async function mainMenu() {
25
26
  const config = loadConfig();
26
27
 
27
28
  box([
28
- chalk.bold.white('tronclass-auto v1.1.0'),
29
+ chalk.bold.white(`tronclass-auto v${pkg.version}`),
29
30
  chalk.gray('自動觀看 eclass/TronClass 影片'),
30
31
  '',
31
32
  `課程: ${chalk.cyan(config.courses.length + ' 個')} | Cookie: ${chalk.green('✓')} | 倍速: ${chalk.yellow(config.playbackRate || 2)}x`,
package/src/video.js CHANGED
@@ -12,6 +12,15 @@ function formatTime(seconds) {
12
12
  return `${s}s`;
13
13
  }
14
14
 
15
+ function progress(msg) {
16
+ process.stdout.write('\r\x1b[K' + msg);
17
+ }
18
+
19
+ function log(msg) {
20
+ process.stdout.write('\n');
21
+ progress(msg);
22
+ }
23
+
15
24
  async function watchVideo(page, stats) {
16
25
  const hasVideo = await page.evaluate(() => document.querySelector('video') !== null);
17
26
  if (!hasVideo) {
@@ -105,7 +114,7 @@ async function watchVideo(page, stats) {
105
114
  } else {
106
115
  etaStr = chalk.gray(` | ${formatTime(remaining)} left`);
107
116
  }
108
- log(chalk.blue(` ${bar} ${String(pct).padStart(3)}% (${formatTime(elapsed)})${etaStr}`));
117
+ progress(`${bar} ${String(pct).padStart(3)}% (${formatTime(elapsed)})${etaStr}`);
109
118
  lastPct = pct;
110
119
  }
111
120
 
@@ -115,9 +124,6 @@ async function watchVideo(page, stats) {
115
124
  }
116
125
 
117
126
  if (state.stalled) {
118
- if (elapsed % 15 === 0) {
119
- log(chalk.gray(` Buffering... (${formatTime(elapsed)})`));
120
- }
121
127
  continue;
122
128
  }
123
129
 
@@ -145,10 +151,6 @@ async function watchVideo(page, stats) {
145
151
  return true;
146
152
  }
147
153
 
148
- function log(msg) {
149
- console.log(msg);
150
- }
151
-
152
154
  function printReport(stats) {
153
155
  console.log('');
154
156
  console.log(chalk.cyan('┌' + '─'.repeat(48) + '┐'));