phase 2 rework
This commit is contained in:
1 parent
20054198f3
commit
b397ea9256
44 files changed
+5528
-1377
No files matched your search
@@ -0,0 +1,94 @@
|
||||
(() => {
|
||||
'use strict';
|
||||
|
||||
const main = document.getElementById('main-content');
|
||||
const alert = document.getElementById('captcha-alert');
|
||||
const message = document.getElementById('captcha-message');
|
||||
const status = document.getElementById('global-status');
|
||||
const statusText = document.getElementById('global-status-text');
|
||||
const queueCount = document.getElementById('nav-queue-count');
|
||||
let inFlight = false;
|
||||
let timer = null;
|
||||
let controller = null;
|
||||
let disposed = false;
|
||||
let lastPaused = alert ? !alert.hidden : false;
|
||||
|
||||
function updateStatus(snapshot) {
|
||||
if (!snapshot || typeof snapshot.global !== 'object' || snapshot.global === null) return;
|
||||
lastPaused = snapshot.global.captcha_blocked === true;
|
||||
if (message) message.textContent = snapshot.global.pause_reason === 'resolution'
|
||||
? 'The video link could not be resolved. Possible causes include CAPTCHA or login verification, an unavailable video, or a source change. Workers are paused for verification.'
|
||||
: 'Authentication or access needs verification on Proxer. Workers are paused until verification is complete.';
|
||||
if (alert) alert.hidden = !lastPaused;
|
||||
if (status) {
|
||||
status.classList.toggle('is-paused', lastPaused);
|
||||
status.classList.toggle('is-ready', !lastPaused);
|
||||
status.classList.remove('is-stale');
|
||||
status.removeAttribute('title');
|
||||
}
|
||||
if (statusText) statusText.textContent = lastPaused ? 'Downloads paused' : 'Queue ready';
|
||||
if (queueCount && snapshot.counts) {
|
||||
const queued = Number(snapshot.counts.queued);
|
||||
const processing = Number(snapshot.counts.processing);
|
||||
if (Number.isFinite(queued) && queued >= 0 && Number.isFinite(processing) && processing >= 0) {
|
||||
queueCount.textContent = (queued + processing).toLocaleString();
|
||||
queueCount.hidden = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function markUnavailable() {
|
||||
if (status) {
|
||||
status.classList.remove('is-ready');
|
||||
status.classList.add('is-stale');
|
||||
status.title = 'The latest queue status could not be loaded. The last known information is still shown.';
|
||||
}
|
||||
if (statusText) statusText.textContent = lastPaused ? 'Paused · status unavailable' : 'Status unavailable';
|
||||
}
|
||||
|
||||
async function refreshSummary() {
|
||||
if (disposed || inFlight || document.hidden || ['queue', 'dashboard'].includes(main?.dataset.page)) return;
|
||||
inFlight = true;
|
||||
controller = new AbortController();
|
||||
const timeout = setTimeout(() => controller?.abort(), 8000);
|
||||
try {
|
||||
const response = await fetch('/status-summary', { cache: 'no-store', signal: controller.signal });
|
||||
if (!response.ok) throw new Error('Status unavailable');
|
||||
const snapshot = await response.json();
|
||||
if (!snapshot || typeof snapshot.global !== 'object' || !snapshot.counts) throw new Error('Invalid status');
|
||||
if (!disposed) updateStatus(snapshot);
|
||||
} catch {
|
||||
if (!disposed && !document.hidden) markUnavailable();
|
||||
} finally {
|
||||
clearTimeout(timeout);
|
||||
inFlight = false;
|
||||
controller = null;
|
||||
if (!disposed) timer = setTimeout(refreshSummary, 10000);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('proxer:status', event => updateStatus(event.detail));
|
||||
document.addEventListener('proxer:status-error', markUnavailable);
|
||||
document.addEventListener('visibilitychange', () => {
|
||||
clearTimeout(timer);
|
||||
if (document.hidden) controller?.abort();
|
||||
else refreshSummary();
|
||||
});
|
||||
document.addEventListener('submit', event => {
|
||||
const confirmation = event.target?.dataset?.confirm;
|
||||
if (!event.defaultPrevented && confirmation && !window.confirm(confirmation)) event.preventDefault();
|
||||
});
|
||||
window.addEventListener('pagehide', () => {
|
||||
disposed = true;
|
||||
clearTimeout(timer);
|
||||
controller?.abort();
|
||||
});
|
||||
window.addEventListener('pageshow', event => {
|
||||
if (event.persisted) {
|
||||
disposed = false;
|
||||
refreshSummary();
|
||||
}
|
||||
});
|
||||
window.ProxerUI = Object.freeze({ updateStatus, markUnavailable });
|
||||
refreshSummary();
|
||||
})();
|
||||
Reference in new issue
Block a user