-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent-kwik.js
More file actions
31 lines (29 loc) · 1.42 KB
/
Copy pathcontent-kwik.js
File metadata and controls
31 lines (29 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// Runs on kwik /d/ pages (inside the hidden helper tab).
// The page's own JS has already built the real <form> (action + hidden _token) by the time we run,
// so we just submit it. Because we're ON the page, the POST carries the correct action, _token,
// Referer and cookies -> server replies 302 -> .mp4, which the browser downloads as an attachment.
(() => {
const CFG = globalThis.APD_CONFIG;
const t0 = Date.now();
(function poll() {
const btn = document.querySelector(CFG.selectors.kwik.submitBtn);
const form = (btn && btn.form) || document.querySelector(CFG.selectors.kwik.form);
const token = document.querySelector(CFG.selectors.kwik.tokenInput);
if (form && token && token.value) {
// Tell the SW we're about to trigger the download so it can attach the next onCreated event.
// Pass the size shown on the button (e.g. "139.54 MB") along for the progress toast.
const sizeMatch = ((btn && btn.textContent) || '').match(/\(([^)]+)\)/);
chrome.runtime.sendMessage(
{ type: 'APD_KWIK_READY', detail: sizeMatch ? '(' + sizeMatch[1] + ')' : '' },
() => void chrome.runtime.lastError
);
form.submit();
return;
}
if (Date.now() - t0 > CFG.behavior.kwikMaxWaitMs) {
chrome.runtime.sendMessage({ type: 'APD_FAIL', stage: 'kwik' }, () => void chrome.runtime.lastError);
return;
}
setTimeout(poll, CFG.behavior.kwikScanIntervalMs);
})();
})();