tronclass-auto 1.3.8 → 1.4.0
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 +1 -1
- package/src/index.js +30 -3
- package/src/video.js +36 -24
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -157,9 +157,36 @@ async function processCourse(page, courseId, stats) {
|
|
|
157
157
|
}
|
|
158
158
|
const success = await watchVideo(page, stats);
|
|
159
159
|
if (success) {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
160
|
+
await page.waitForTimeout(5000);
|
|
161
|
+
await page.goto(`${BASE_URL}/course/${courseId}/content#/`, {
|
|
162
|
+
waitUntil: 'domcontentloaded', timeout: 15000
|
|
163
|
+
}).catch(() => {});
|
|
164
|
+
await page.waitForTimeout(3000);
|
|
165
|
+
|
|
166
|
+
const serverComplete = await page.evaluate((actId) => {
|
|
167
|
+
const el = document.querySelector('.learning-activities');
|
|
168
|
+
if (!el) return false;
|
|
169
|
+
const scope = angular.element(el).scope();
|
|
170
|
+
if (!scope) return false;
|
|
171
|
+
const activities = document.querySelectorAll('.learning-activity.sortable');
|
|
172
|
+
for (const actEl of activities) {
|
|
173
|
+
const actScope = angular.element(actEl).scope();
|
|
174
|
+
if (!actScope || !actScope.activity) continue;
|
|
175
|
+
if (actScope.activity.id == actId) {
|
|
176
|
+
try { return scope.getActivityCompleteness(actScope.activity) === 'full'; } catch (e) {}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
}, act.id);
|
|
181
|
+
|
|
182
|
+
if (serverComplete) {
|
|
183
|
+
markDone(courseId, act.id);
|
|
184
|
+
done++;
|
|
185
|
+
console.log(chalk.green(' ✓ Saved (server confirmed)'));
|
|
186
|
+
} else {
|
|
187
|
+
console.log(chalk.yellow(' Server not confirmed yet, will retry next run'));
|
|
188
|
+
fail++;
|
|
189
|
+
}
|
|
163
190
|
} else {
|
|
164
191
|
fail++;
|
|
165
192
|
}
|
package/src/video.js
CHANGED
|
@@ -58,31 +58,39 @@ async function watchVideo(page, stats) {
|
|
|
58
58
|
async function watchYouTube(page, stats) {
|
|
59
59
|
log(chalk.blue(' YouTube embed'));
|
|
60
60
|
|
|
61
|
-
const speedSet = await page.evaluate(() => {
|
|
62
|
-
const f = document.querySelector('iframe[src*="youtube"], iframe[src*="youtu.be"]');
|
|
63
|
-
if (!f) return false;
|
|
64
|
-
const src = f.src || '';
|
|
65
|
-
if (!src.includes('enablejsapi=1')) return false;
|
|
66
|
-
try {
|
|
67
|
-
f.contentWindow.postMessage(JSON.stringify({ event: 'command', func: 'mute', args: [] }), '*');
|
|
68
|
-
f.contentWindow.postMessage(JSON.stringify({ event: 'command', func: 'setPlaybackRate', args: [2] }), '*');
|
|
69
|
-
f.contentWindow.postMessage(JSON.stringify({ event: 'command', func: 'playVideo', args: [] }), '*');
|
|
70
|
-
return true;
|
|
71
|
-
} catch (e) { return false; }
|
|
72
|
-
});
|
|
73
|
-
|
|
74
61
|
try {
|
|
62
|
+
const ytFrame = page.locator('iframe[src*="youtube"], iframe[src*="youtu.be"]');
|
|
63
|
+
await ytFrame.click({ timeout: 5000 }).catch(() => {});
|
|
64
|
+
await page.waitForTimeout(2000);
|
|
65
|
+
|
|
75
66
|
const frame = page.frameLocator('iframe[src*="youtube"], iframe[src*="youtu.be"]');
|
|
76
|
-
const playBtn = frame.locator('.ytp-large-play-button
|
|
77
|
-
await playBtn.
|
|
78
|
-
|
|
67
|
+
const playBtn = frame.locator('.ytp-large-play-button');
|
|
68
|
+
await playBtn.click({ timeout: 5000 }).catch(() => {});
|
|
69
|
+
await page.waitForTimeout(2000);
|
|
79
70
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
71
|
+
try {
|
|
72
|
+
await frame.locator('.ytp-settings-button').click({ timeout: 3000 });
|
|
73
|
+
await page.waitForTimeout(500);
|
|
74
|
+
await frame.locator('.ytp-menuitem:has-text("播放速度"), .ytp-menuitem:has-text("Playback speed")').click({ timeout: 3000 });
|
|
75
|
+
await page.waitForTimeout(500);
|
|
76
|
+
await frame.locator('.ytp-menuitem:has-text("2"), .ytp-menuitem:has-text("2x")').click({ timeout: 3000 });
|
|
77
|
+
log(chalk.blue(' Speed: 2x ✓'));
|
|
78
|
+
} catch (e) {
|
|
79
|
+
log(chalk.yellow(' Speed: 1x (settings menu unavailable)'));
|
|
80
|
+
}
|
|
84
81
|
|
|
85
|
-
|
|
82
|
+
try {
|
|
83
|
+
await frame.locator('.ytp-settings-button').click({ timeout: 2000 });
|
|
84
|
+
await page.waitForTimeout(500);
|
|
85
|
+
await frame.locator('.ytp-menuitem:has-text("字幕"), .ytp-menuitem:has-text("Subtitles"), .ytp-menuitem:has-text("CC")').click({ timeout: 2000 }).catch(() => {});
|
|
86
|
+
await frame.locator('.ytp-menuitem:has-text("關閉"), .ytp-menuitem:has-text("Off"), .ytp-menuitem:has-text("None")').click({ timeout: 2000 }).catch(() => {});
|
|
87
|
+
await page.keyboard.press('Escape');
|
|
88
|
+
} catch (e) {}
|
|
89
|
+
} catch (e) {
|
|
90
|
+
log(chalk.yellow(' YouTube setup failed, falling back'));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
await page.waitForTimeout(2000);
|
|
86
94
|
|
|
87
95
|
const ytDuration = await page.evaluate(() => {
|
|
88
96
|
const actText = document.querySelector('.activity-attribute, [class*="attribute"]');
|
|
@@ -93,9 +101,13 @@ async function watchYouTube(page, stats) {
|
|
|
93
101
|
return 180;
|
|
94
102
|
});
|
|
95
103
|
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
const waitTime = ytDuration + 30;
|
|
105
|
+
log(chalk.blue(` ~${formatTime(ytDuration)} video → ~${formatTime(waitTime)} (YouTube 1x safe)`));
|
|
106
|
+
|
|
107
|
+
if (stats) {
|
|
108
|
+
stats.currentVideoDuration = ytDuration;
|
|
109
|
+
stats.currentVideoElapsed = 0;
|
|
110
|
+
}
|
|
99
111
|
|
|
100
112
|
let elapsed = 0;
|
|
101
113
|
let lastPct = -1;
|