// ==UserScript==
// @name 时间倍速器
// @name:en 时间倍速器
// @namespace https://gitee.com/HGJing/everthing-hook/
// @homepageURL https://timer.palerock.cn
// @version 2.2.8
// @description 控制网页计时器速度|加速跳过页面计时广告|视频快进(慢放)|跳过广告|支持几乎所有网页。支持后台验证码验证与激活码,打赏请使用页面链接。
// @description:en Control timer speed, skip ads, support almost all websites. Verification and activation supported. Donation via the linked page.
// @include *
// @author Cangshi
// @run-at document-start
// @grant unsafeWindow
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_listValues
// @grant GM_deleteValue
// @grant GM_addValueChangeListener
// @grant GM_removeValueChangeListener
// @grant GM_log
// @grant GM_registerMenuCommand
// @grant GM_unregisterMenuCommand
// @grant GM_openInTab
// @grant GM_xmlhttpRequest
// @grant GM_getTab
// @grant GM_saveTab
// @grant GM_notification
// @grant GM_setClipboard
// @grant GM.deleteValue
// @grant GM.getValue
// @grant GM.listValues
// @grant GM.setValue
// @grant GM.getResourceUrl
// @grant GM.notification
// @grant GM.registerMenuCommand
// @grant GM.xmlHttpRequest
// @note 免费试用按后台验证码设置生效;激活期限以服务器返回为准;打赏仅使用 HTTPS 打赏链接。
// @supportURL http://103.236.88.53:23123
// @antifeature payment 免费验证与激活码两种方式;打赏通过链接页面完成,具体权益以页面及服务端为准。
// @connect 103.236.88.53
// @grant GM_info
// ==/UserScript==
// 免费验证使用 video-trial;付费激活码独立验证。打赏只打开指定页面。
// 保留原脚本身份、个人设置、既有激活码与设备算法,旧的本地试用时间不代替真实会话。
(function () {
'use strict';
// 手机脚本管理器的 window 可能是代理。原生计时器必须与所属窗口配对,
// 并在倍速核心 hook 页面 API 之前保存,不能把页面函数绑定到沙箱 window。
const __videoSpeedNative = (() => {
const NativeDate = Date;
const now = NativeDate.now.bind(NativeDate);
const hosts = [];
if (typeof unsafeWindow !== 'undefined' && unsafeWindow) hosts.push(unsafeWindow);
if (!hosts.includes(window)) hosts.push(window);
function capture(setName, clearName) {
for (const host of hosts) {
let probe = null;
try {
const schedule = host[setName], cancel = host[clearName];
if (typeof schedule !== 'function' || typeof cancel !== 'function') continue;
const set = (...args) => Reflect.apply(schedule, host, args);
const clear = id => Reflect.apply(cancel, host, [id]);
// bind() 成功不代表原生方法接受该 receiver;实际安排并取消一次。
probe = set(() => {}, 2147483647);
clear(probe);
return {set, clear};
} catch (_) {
// timeout/interval 共用同一窗口的 ID 池。取消器不兼容时,
// 用另一窗口包装中的取消器清掉探测任务,再尝试下一套方法。
if (probe !== null) {
for (const cleanupHost of hosts) {
for (const name of ['clearTimeout', 'clearInterval']) {
try { Reflect.apply(cleanupHost[name], cleanupHost, [probe]); } catch (_) {}
}
}
}
}
}
throw new Error('当前脚本管理器不支持原生计时器,请更新浏览器和脚本猫后重试');
}
const timeout = capture('setTimeout', 'clearTimeout');
const interval = capture('setInterval', 'clearInterval');
return Object.freeze({now, NativeDate, setTimeout:timeout.set, clearTimeout:timeout.clear,
setInterval:interval.set, clearInterval:interval.clear});
})();
(function () {
'use strict';
const __videoSpeedAccess = (() => {
let allowed = false;
const listeners = new Set();
return Object.freeze({
get allowed() { return allowed; },
subscribe(listener) { listeners.add(listener); return () => listeners.delete(listener); },
setAllowed(value) {
value = value === true;
if (allowed === value) return;
allowed = value;
for (const listener of listeners) {
try { listener(); } catch (error) { console.warn('[时间倍速器]', error); }
}
}
});
})();
// ========== 验证码验证模块 ==========
(function () {
const SERVICE = 'http://103.236.88.53:23123';
const SHOP_URL = 'https://120.79.20.248:24443/index.php?r=shop';
const SCOPE = 'video-trial';
const STORAGE_KEY = 'video_speed_valid_until';
const TOKEN_KEY = 'video_speed_verify_session_token';
const PERMANENT_KEY = 'video_speed_permanent_code';
const DEVICE_KEY = 'video_speed_device_id';
const nativeNow = __videoSpeedNative.now;
const nativeSetTimeout = __videoSpeedNative.setTimeout;
const nativeClearTimeout = __videoSpeedNative.clearTimeout;
const nativeSetInterval = __videoSpeedNative.setInterval;
const nativeClearInterval = __videoSpeedNative.clearInterval;
const RECHECK_AHEAD_MS = 15000;
const isTop = window.self === window.top;
let stopped = false, policy = null, policyRequest = null, syncRequest = null;
let revision = 0, sessionCache = null, paidCache = null, grant = null, expiryTimer = null;
let dialog = null, previousFocus = null, qrVersion = 0, qrObjectUrl = '';
let statusText = '请先验证后使用倍速功能';
let requestBackoffUntil = 0;
// 第一次升级沿用原算法的结果,然后持久化,避免屏幕变化导致设备标识漂移。
function getDeviceId() {
const stored = String(GM_getValue(DEVICE_KEY, '') || '');
if (stored.length >= 8 && stored.length <= 255) return stored;
let value = '';
try {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
if (!ctx) throw new Error('canvas unavailable');
ctx.textBaseline = 'top'; ctx.font = '14px Arial';
ctx.fillText('device-fingerprint', 2, 2);
const features = [navigator.platform, navigator.hardwareConcurrency,
screen.width + 'x' + screen.height, screen.colorDepth,
new __videoSpeedNative.NativeDate().getTimezoneOffset(), canvas.toDataURL().slice(-50)].join('|');
let hash = 0;
for (let i = 0; i < features.length; i++) hash = ((hash << 5) - hash + features.charCodeAt(i)) | 0;
value = 'DEV' + Math.abs(hash).toString(16).toUpperCase().padStart(12, '0');
} catch (_) {
const bytes = new Uint8Array(16);
crypto.getRandomValues(bytes);
value = 'dev_' + Array.from(bytes, b => b.toString(16).padStart(2, '0')).join('');
}
GM_setValue(DEVICE_KEY, value);
return value;
}
const DEVICE_ID = getDeviceId();
function api(path, fields) {
return new Promise((resolve, reject) => {
if (requestBackoffUntil > nativeNow()) {
reject(new Error('请求较频繁,请稍后重试')); return;
}
const fail = message => reject(new Error(message));
try {
GM_xmlhttpRequest({
method: fields ? 'POST' : 'GET',
url: SERVICE + '/index.php?s=/api/code/' + path,
headers: { Accept: 'application/json', ...(fields ? {'Content-Type': 'application/x-www-form-urlencoded'} : {}) },
...(fields ? {data: new URLSearchParams(fields).toString()} : {}),
timeout: 10000,
onload(response) {
if (response.status === 429) {
const retry = /(?:^|\r?\n)retry-after:\s*(\d+)/i.exec(response.responseHeaders || '');
requestBackoffUntil = nativeNow() + Math.max(10, Math.min(300, Number(retry?.[1]) || 60)) * 1000;
}
let result;
try { result = JSON.parse(response.responseText); }
catch (_) { fail(response.status === 429 ? '请求较频繁,请稍后重试' : '服务器响应异常,请稍后重试'); return; }
if (response.status < 200 || response.status >= 300 || result?.code !== 1 || !result.data || typeof result.data !== 'object') {
const error = new Error(typeof result?.msg === 'string' ? result.msg : '验证失败,请稍后重试');
error.rejected = [400, 401, 403].includes(response.status) && result?.code === 0;
reject(error); return;
}
resolve(result.data);
},
onerror() { fail('网络错误,请稍后重试'); },
ontimeout() { fail('请求超时,请稍后重试'); },
onabort() { fail('请求已取消,请重试'); }
});
} catch (_) { fail('无法连接验证服务,请检查脚本管理器权限'); }
});
}
function safeQrUrl(value) {
if (typeof value !== 'string' || !value || value.length > 2048 || /[\u0000-\u0020\u007f\\]/.test(value)) return '';
try {
const url = new URL(value, SERVICE + '/');
return /^https?:$/.test(url.protocol) && !url.username && !url.password ? url.href : '';
} catch (_) { return ''; }
}
async function refreshPolicy(force = false) {
if (policyRequest) return policyRequest;
if (!force && policy && policy.expiresAt - nativeNow() > RECHECK_AHEAD_MS) return policy;
// 趁现有策略仍有效提前复核;其原到期计时器继续生效,过期不会因请求挂起而延期。
if (!policy || policy.expiresAt <= nativeNow()) {
policy = null;
if (grant?.kind === 'policy') setGrant(null);
}
policyRequest = (async () => {
try {
const data = await api('config');
const maxAge = Math.min(60, Math.max(1, Number(data.refresh_after) || 60)) * 1000;
policy = {required: data.scopes?.[SCOPE] !== false, qrcode: safeQrUrl(data.qrcode_url), expiresAt: nativeNow() + maxAge};
} catch (_) {
policy = {required: true, qrcode: '', expiresAt: nativeNow() + 10000};
}
if (policy.required && grant?.kind === 'policy') setGrant(null);
paintPolicy();
return policy;
})();
try { return await policyRequest; } finally { policyRequest = null; }
}
function setGrant(value) {
const previousTimer = expiryTimer;
expiryTimer = null;
try {
if (previousTimer !== null) nativeClearTimeout(previousTimer);
if (value) {
// 同时遵守真实到期时间和最多60秒的复核期限;用原生时钟避免倍速影响。
expiryTimer = nativeSetTimeout(() => {
expiryTimer = null;
setGrant(null);
synchronize();
}, Math.max(1, value.checkedUntil - nativeNow()));
}
} catch (error) {
grant = null;
__videoSpeedAccess.setAllowed(false);
console.warn('[时间倍速器] 安排授权复核计时器失败', error);
throw new Error('浏览器计时器调用不兼容,请更新 UC 和脚本猫后刷新页面重试');
}
// 复核计时安排成功后才启用,避免浏览器方法异常留下半启用状态。
grant = value;
__videoSpeedAccess.setAllowed(!!value);
if (dialog) dialog.querySelector('#_activation_status').textContent = statusText;
updateActivationButton();
}
function validDeadline(data) {
return typeof data.valid_until === 'number' && Number.isFinite(data.valid_until) && data.valid_until >= 0;
}
async function synchronize(force = false) {
if (stopped) return false;
if (force) { revision++; sessionCache = null; paidCache = null; }
if (syncRequest) {
await syncRequest;
return force ? synchronize() : __videoSpeedAccess.allowed;
}
const activeRevision = revision;
syncRequest = (async () => {
if (grant && grant.checkedUntil <= nativeNow()) setGrant(null);
const currentPolicy = await refreshPolicy(force);
if (activeRevision !== revision || stopped) return false;
const paidCode = String(GM_getValue(PERMANENT_KEY, '') || '');
if (paidCode) {
try {
if (!paidCache || paidCache.code !== paidCode || paidCache.expiresAt - nativeNow() <= RECHECK_AHEAD_MS) {
const data = await api('verify_permanent', {code: paidCode, device_id: DEVICE_ID});
if (activeRevision !== revision || stopped) return false;
if (data.valid !== true || !validDeadline(data) || (data.valid_until !== 0 && data.valid_until <= nativeNow() / 1000)) throw Object.assign(new Error('激活码已失效'), {rejected: true});
paidCache = {code: paidCode, data, expiresAt: Math.min(nativeNow() + 60000, data.valid_until === 0 ? Infinity : data.valid_until * 1000)};
}
if (activeRevision !== revision || stopped) return false;
const until = paidCache.data.valid_until;
statusText = until === 0 ? '已永久激活' : '已激活,到期时间:' + new __videoSpeedNative.NativeDate(until * 1000).toLocaleString();
setGrant({kind: 'paid', checkedUntil: paidCache.expiresAt});
return true;
} catch (error) {
if (activeRevision !== revision || stopped) return false;
paidCache = null;
if (error.rejected && GM_getValue(PERMANENT_KEY, '') === paidCode) GM_deleteValue(PERMANENT_KEY);
statusText = error.message;
}
}
const token = String(GM_getValue(TOKEN_KEY, '') || '');
const until = Number(GM_getValue(STORAGE_KEY, 0)) || 0;
if (currentPolicy.required && (!token || until <= nativeNow() / 1000)) {
statusText = '请先获取验证码并完成验证';
setGrant(null); return false;
}
const key = [currentPolicy.required, token, until, currentPolicy.expiresAt].join('|');
try {
if (!sessionCache || sessionCache.key !== key || sessionCache.expiresAt - nativeNow() <= RECHECK_AHEAD_MS) {
const data = await api('check_session', {scope: SCOPE, device_id: DEVICE_ID, ...(token ? {session_token: token} : {})});
if (activeRevision !== revision || stopped) return false;
if (data.valid !== true || data.scope !== SCOPE) throw new Error('验证会话无效,请重新验证');
if (data.verification_required === false) {
if (currentPolicy.required) { policy = null; throw new Error('验证规则已变化,请重新检查'); }
sessionCache = {key, kind: 'policy', expiresAt: Math.min(nativeNow() + 60000, currentPolicy.expiresAt)};
} else {
if (!token || data.verification_required !== true || !validDeadline(data) || data.valid_until <= nativeNow() / 1000 || until <= nativeNow() / 1000) throw new Error('验证会话已失效,请重新验证');
sessionCache = {key, kind: 'session', expiresAt: Math.min(nativeNow() + 60000, until * 1000, data.valid_until * 1000)};
}
}
if (activeRevision !== revision || stopped) return false;
statusText = sessionCache.kind === 'policy' ? '当前无需验证码,可直接使用' : '验证有效,到期时间:' + new __videoSpeedNative.NativeDate(until * 1000).toLocaleString();
setGrant({kind: sessionCache.kind, checkedUntil: sessionCache.expiresAt});
return true;
} catch (error) {
if (activeRevision !== revision || stopped) return false;
sessionCache = null;
if (error.rejected && GM_getValue(TOKEN_KEY, '') === token) {
GM_deleteValue(TOKEN_KEY); GM_setValue(STORAGE_KEY, 0);
}
statusText = error.message;
setGrant(null); return false;
}
})();
try { return await syncRequest; }
finally {
syncRequest = null;
if (activeRevision !== revision && !stopped) nativeSetTimeout(() => synchronize(), 0);
}
}
function updateActivationButton() {
if (!isTop || !document.documentElement) return;
const existing = document.getElementById('_activate_btn');
if (__videoSpeedAccess.allowed) { existing?.remove(); return; }
if (existing || dialog) return;
const btn = document.createElement('button');
btn.id = '_activate_btn'; btn.type = 'button';
btn.textContent = '激活时间倍速器';
btn.title = statusText;
btn.style.cssText = 'position:fixed;right:20px;bottom:max(40px,env(safe-area-inset-bottom));z-index:999998;padding:12px 20px;border:0;border-radius:24px;background:#6673d9;color:#fff;box-shadow:0 3px 12px #0003;font:600 14px system-ui;cursor:pointer;touch-action:none;';
let drag = null, moved = false;
btn.addEventListener('pointerdown', event => {
if (event.button !== 0) return;
const rect = btn.getBoundingClientRect();
drag = {x:event.clientX, y:event.clientY, left:rect.left, top:rect.top}; moved = false;
btn.setPointerCapture?.(event.pointerId);
});
btn.addEventListener('pointermove', event => {
if (!drag) return;
const dx = event.clientX - drag.x, dy = event.clientY - drag.y;
if (Math.abs(dx) > 5 || Math.abs(dy) > 5) moved = true;
if (moved) {
btn.style.left = Math.max(0, Math.min(window.innerWidth - btn.offsetWidth, drag.left + dx)) + 'px';
btn.style.top = Math.max(0, Math.min(window.innerHeight - btn.offsetHeight, drag.top + dy)) + 'px';
btn.style.right = 'auto'; btn.style.bottom = 'auto';
}
});
btn.addEventListener('pointerup', () => { drag = null; });
btn.addEventListener('pointercancel', () => { drag = null; moved = false; });
btn.addEventListener('click', async event => {
if (moved && event.detail !== 0) { moved = false; return; }
btn.disabled = true; btn.textContent = '检查验证状态…';
try { if (!await synchronize(true)) showVerifyDialog(); }
finally { btn.disabled = false; btn.textContent = '激活时间倍速器'; }
});
(document.body || document.documentElement).appendChild(btn);
}
function releaseQr() {
qrVersion++;
if (qrObjectUrl) URL.revokeObjectURL(qrObjectUrl);
qrObjectUrl = '';
}
function closeDialog() {
if (!dialog) return;
const old = dialog; dialog = null;
releaseQr();
if (old.open && typeof old.close === 'function') old.close();
old.remove();
if (previousFocus?.isConnected) previousFocus.focus();
previousFocus = null;
}
function paintPolicy() {
if (!dialog) return;
const required = !policy || policy.expiresAt <= nativeNow() || policy.required;
const fields = dialog.querySelector('#_verify_free_fields');
fields.hidden = !required;
dialog.querySelector('#_verify_code_free').required = required;
dialog.querySelector('#_free_description').textContent = required ? '获取四位验证码,验证成功后按服务端有效期使用。' : '当前无需四位验证码,点击下方按钮确认并启用。';
dialog.querySelector('#_verify_submit_free').textContent = required ? '立即验证' : '直接启用';
const image = dialog.querySelector('#_verify_qrcode');
const hint = dialog.querySelector('#_qr_hint');
const url = required ? policy?.qrcode || '' : '';
if (image.dataset.source === url) return;
releaseQr(); image.dataset.source = url; image.removeAttribute('src'); image.hidden = true;
hint.textContent = required ? '二维码尚未配置,请联系管理员获取验证码。' : '';
if (!url) return;
const version = qrVersion;
const target = new URL(url);
if (target.protocol === 'https:') {
image.src = url; image.hidden = false; hint.textContent = '';
image.onerror = () => { if (version === qrVersion) { image.hidden = true; hint.textContent = '二维码加载失败,请稍后重试。'; } };
return;
}
if (target.origin !== new URL(SERVICE).origin) { hint.textContent = '二维码需使用 HTTPS 地址或本站上传图片。'; return; }
hint.textContent = '正在加载验证码二维码…';
try {
GM_xmlhttpRequest({
method: 'GET', url, responseType: 'blob', timeout: 15000,
onload(response) {
if (version !== qrVersion || !dialog) return;
const blob = response.response;
const finalUrl = safeQrUrl(response.finalUrl || url);
if (response.status !== 200 || !finalUrl || new URL(finalUrl).origin !== target.origin || !blob || !['image/png','image/jpeg','image/gif','image/webp'].includes(String(blob.type).split(';')[0].toLowerCase()) || blob.size > 5 * 1024 * 1024) {
hint.textContent = '二维码加载失败,请稍后重试。'; return;
}
qrObjectUrl = URL.createObjectURL(blob); image.src = qrObjectUrl; image.hidden = false; hint.textContent = '';
},
onerror() { if (version === qrVersion) hint.textContent = '二维码加载失败,请稍后重试。'; },
ontimeout() { if (version === qrVersion) hint.textContent = '二维码加载超时,请稍后重试。'; }
});
} catch (_) { hint.textContent = '二维码加载失败,请稍后重试。'; }
}
function showVerifyDialog() {
if (!isTop || dialog) return;
previousFocus = document.activeElement;
document.getElementById('_activate_btn')?.remove();
const overlay = document.createElement('dialog');
overlay.id = '_verify_overlay';
overlay.setAttribute('aria-labelledby', '_activation_title');
overlay.innerHTML = `
激活时间倍速器
`;
dialog = overlay;
(document.body || document.documentElement).appendChild(overlay);
overlay.querySelector('#_device_id_display').textContent = DEVICE_ID;
overlay.querySelector('#_activation_status').textContent = statusText;
function switchTab(paid) {
for (const [id, selected] of [['_tab_free', !paid], ['_tab_permanent', paid]]) {
const tab = overlay.querySelector('#' + id);
tab.setAttribute('aria-selected', String(selected)); tab.tabIndex = selected ? 0 : -1;
}
overlay.querySelector('#_free_content').hidden = paid;
overlay.querySelector('#_permanent_content').hidden = !paid;
}
for (const [id, paid] of [['_tab_free', false], ['_tab_permanent', true]]) {
const tab = overlay.querySelector('#' + id);
tab.addEventListener('click', () => switchTab(paid));
tab.addEventListener('keydown', event => {
if (!['ArrowLeft','ArrowRight','Home','End'].includes(event.key)) return;
event.preventDefault();
const targetPaid = event.key === 'Home' ? false : event.key === 'End' ? true : !paid;
switchTab(targetPaid); overlay.querySelector(targetPaid ? '#_tab_permanent' : '#_tab_free').focus();
});
}
overlay.querySelector('#_copy_device_id').onclick = () => {
const button = overlay.querySelector('#_copy_device_id');
try { GM_setClipboard(DEVICE_ID, 'text'); button.textContent = '已复制'; }
catch (_) { button.textContent = '请选中设备码复制'; }
};
function dismiss() { closeDialog(); updateActivationButton(); document.getElementById('_activate_btn')?.focus(); }
overlay.querySelector('#_verify_cancel').onclick = dismiss;
overlay.addEventListener('cancel', event => { event.preventDefault(); dismiss(); });
const freeButton = overlay.querySelector('#_verify_submit_free');
const paidButton = overlay.querySelector('#_verify_submit_perm');
let submitting = false;
async function submit(paid) {
if (submitting) return;
const error = overlay.querySelector(paid ? '#_verify_error_perm' : '#_verify_error_free');
const input = overlay.querySelector(paid ? '#_verify_code_perm' : '#_verify_code_free');
error.textContent = ''; input.removeAttribute('aria-invalid');
submitting = true; freeButton.disabled = true; paidButton.disabled = true;
const button = paid ? paidButton : freeButton;
const label = button.textContent; button.textContent = '验证中…';
try {
if (!paid) await refreshPolicy(true);
const code = input.value.trim();
if (paid || policy.required) {
if (paid ? code.length < 6 : !/^\d{4}$/.test(code)) {
input.setAttribute('aria-invalid', 'true'); input.focus();
throw new Error(paid ? '请输入有效的激活码' : '请输入4位数字验证码');
}
const data = await api(paid ? 'verify_permanent' : 'verify', {code, device_id: DEVICE_ID, ...(paid ? {} : {scope: SCOPE})});
if (data.valid !== true || !validDeadline(data)) throw new Error('服务端验证结果无效,请重试');
if (paid) {
if (data.valid_until !== 0 && data.valid_until <= nativeNow() / 1000) throw new Error('激活码已到期');
GM_setValue(PERMANENT_KEY, code);
paidCache = {code, data, expiresAt: Math.min(nativeNow() + 60000, data.valid_until === 0 ? Infinity : data.valid_until * 1000)};
} else {
if (data.scope !== SCOPE || data.verification_required !== true || typeof data.session_token !== 'string' || !data.session_token || data.valid_until <= nativeNow() / 1000) throw new Error('验证会话无效,请重新获取验证码');
GM_setValue(STORAGE_KEY, data.valid_until); GM_setValue(TOKEN_KEY, data.session_token);
}
revision++; sessionCache = null;
}
if (syncRequest) await syncRequest;
if (!await synchronize()) throw new Error(statusText);
closeDialog();
} catch (failure) {
if (dialog === overlay) error.textContent = failure.message || '验证失败,请稍后重试';
} finally {
submitting = false; freeButton.disabled = false; paidButton.disabled = false;
button.textContent = label;
}
}
freeButton.onclick = () => submit(false); paidButton.onclick = () => submit(true);
for (const [id, paid] of [['_verify_code_free', false], ['_verify_code_perm', true]]) {
overlay.querySelector('#' + id).addEventListener('keydown', event => { if (event.key === 'Enter') { event.preventDefault(); submit(paid); } });
}
paintPolicy();
if (typeof overlay.showModal === 'function') overlay.showModal(); else overlay.setAttribute('open', '');
overlay.querySelector('#_tab_free').focus();
}
if (isTop && typeof GM_registerMenuCommand === 'function') GM_registerMenuCommand('查看或激活时间倍速器', async () => {
await refreshPolicy(true); showVerifyDialog();
});
const heartbeat = nativeSetInterval(() => synchronize(), 10000);
const resume = () => { if (!stopped) synchronize(true); };
window.addEventListener('focus', resume);
window.addEventListener('pageshow', resume);
document.addEventListener('visibilitychange', () => { if (document.visibilityState === 'visible') resume(); });
if (typeof GM_addValueChangeListener === 'function') {
for (const key of [STORAGE_KEY, TOKEN_KEY, PERMANENT_KEY]) GM_addValueChangeListener(key, (_key, _old, _new, remote) => { if (remote) synchronize(true); });
}
window.addEventListener('pagehide', event => {
if (event.persisted) return;
stopped = true; revision++;
nativeClearInterval(heartbeat); releaseQr();
setGrant(null);
});
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', updateActivationButton, {once:true});
synchronize();
})();
// ========== 验证码验证模块结束 ==========
// ========== 悬浮球拖动模块 ==========
// 验证状态保存在 userscript 私有作用域;核心只初始化一次,失效后回到正常速度。
const __videoSpeedOriginalSetTimeout = __videoSpeedNative.setTimeout;
let __videoSpeedCore = null;
let __videoSpeedFeaturesStarted = false;
let __videoSpeedLastAllowed = false;
let __videoSpeedSavedRate = 1;
let __videoSpeedSilentUi = false;
function __startVideoSpeedFeatures() {
(function() {
'use strict';
const DRAG_POS_KEY = 'video_speed_drag_pos';
function initDrag() {
const container = document.querySelector('._th-container');
if (!container) return __videoSpeedOriginalSetTimeout(initDrag, 500);
// 恢复保存的位置
const savedPos = GM_getValue(DRAG_POS_KEY, null);
if (savedPos) {
container.style.left = savedPos.left;
container.style.right = 'auto';
container.style.top = savedPos.top;
}
let isDragging = false,
startX, startY, startLeft, startTop;
container.addEventListener('mousedown', function(e) {
if (e.button !== 0) return;
isDragging = false;
startX = e.clientX;
startY = e.clientY;
const rect = container.getBoundingClientRect();
startLeft = rect.left;
startTop = rect.top;
container.style.transition = 'none';
function onMove(e) {
const dx = e.clientX - startX,
dy = e.clientY - startY;
if (Math.abs(dx) > 3 || Math.abs(dy) > 3) isDragging = true;
if (isDragging) {
container.style.left = (startLeft + dx) + 'px';
container.style.top = (startTop + dy) + 'px';
container.style.right = 'auto';
}
}
function onUp() {
document.removeEventListener('mousemove', onMove);
document.removeEventListener('mouseup', onUp);
container.style.transition = '';
if (isDragging) {
GM_setValue(DRAG_POS_KEY, {
left: container.style.left,
top: container.style.top
});
__videoSpeedOriginalSetTimeout(function() {
isDragging = false;
}, 50);
}
}
document.addEventListener('mousemove', onMove);
document.addEventListener('mouseup', onUp);
});
// 阻止拖动时触发点击
container.addEventListener('click', function(e) {
if (isDragging) {
e.stopPropagation();
e.preventDefault();
}
}, true);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', function() {
__videoSpeedOriginalSetTimeout(initDrag, 1000);
});
} else {
__videoSpeedOriginalSetTimeout(initDrag, 1000);
}
})();
// ========== 悬浮球拖动模块结束 ==========
! function(t, e) {
"object" == typeof exports && "undefined" != typeof module ? module.exports = e() : "function" == typeof define &&
define.amd ? define(e) : (t = "undefined" != typeof globalThis ? globalThis : t || self).$hookTimer = e()
}(this, (function() {
"use strict";
function t(t, e) {
if (!(t instanceof e)) throw new TypeError("Cannot call a class as a function")
}
function e(t, e) {
for (var n = 0; n < e.length; n++) {
var r = e[n];
r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), Object
.defineProperty(t, r.key, r)
}
}
function n(t, n, r) {
return n && e(t.prototype, n), r && e(t, r), t
}
function r(t) {
if (void 0 === t) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
return t
}
function o(t, e) {
return (o = Object.setPrototypeOf || function(t, e) {
return t.__proto__ = e, t
})(t, e)
}
function i(t, e) {
if ("function" != typeof e && null !== e) throw new TypeError(
"Super expression must either be null or a function");
t.prototype = Object.create(e && e.prototype, {
constructor: {
value: t,
writable: !0,
configurable: !0
}
}), e && o(t, e)
}
function a(t) {
return (a = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(t) {
return typeof t
} : function(t) {
return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol
.prototype ? "symbol" : typeof t
})(t)
}
function u(t, e) {
return !e || "object" !== a(e) && "function" != typeof e ? r(t) : e
}
function c(t) {
return (c = Object.setPrototypeOf ? Object.getPrototypeOf : function(t) {
return t.__proto__ || Object.getPrototypeOf(t)
})(t)
}
function l(t, e, n) {
return e in t ? Object.defineProperty(t, e, {
value: n,
enumerable: !0,
configurable: !0,
writable: !0
}) : t[e] = n, t
}
var s, f, h, d = 1e3;
function y() {
return d++
}
function p() {
return null == s && (s = "undefined" == typeof unsafeWindow ? window : unsafeWindow), s
}
function v() {
var t = p().parent !== p();
try {
t = t && "FRAMESET" !== p().parent.document.body.tagName
} catch (t) {}
return t
}
function g(t) {
var e = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : 1 / 0,
n = Array.prototype.flat || function() {
var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[0] : 1 / 0;
if (t < 1) return this;
var e = [],
r = t - 1;
return this.forEach((function(t) {
t instanceof Array ? e = e.concat(n.call(t, r)) : e.push(t)
})), e
};
return n.call(t, e)
}
function m(t, e) {
(null == e || e > t.length) && (e = t.length);
for (var n = 0, r = new Array(e); n < e; n++) r[n] = t[n];
return r
}
function b(t, e) {
if (t) {
if ("string" == typeof t) return m(t, e);
var n = Object.prototype.toString.call(t).slice(8, -1);
return "Object" === n && t.constructor && (n = t.constructor.name), "Map" === n || "Set" === n ?
Array.from(t) : "Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n) ? m(t,
e) : void 0
}
}
function w(t, e) {
return function(t) {
if (Array.isArray(t)) return t
}(t) || function(t, e) {
var n = t && ("undefined" != typeof Symbol && t[Symbol.iterator] || t["@@iterator"]);
if (null != n) {
var r, o, i = [],
a = !0,
u = !1;
try {
for (n = n.call(t); !(a = (r = n.next()).done) && (i.push(r.value), !e || i.length !==
e); a = !0);
} catch (t) {
u = !0, o = t
} finally {
try {
a || null == n.return || n.return()
} finally {
if (u) throw o
}
}
return i
}
}(t, e) || b(t, e) || function() {
throw new TypeError(
"Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
)
}()
}
function k(t, e) {
var n = "undefined" != typeof Symbol && t[Symbol.iterator] || t["@@iterator"];
if (!n) {
if (Array.isArray(t) || (n = function(t, e) {
if (!t) return;
if ("string" == typeof t) return x(t, e);
var n = Object.prototype.toString.call(t).slice(8, -1);
"Object" === n && t.constructor && (n = t.constructor.name);
if ("Map" === n || "Set" === n) return Array.from(t);
if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return x(t,
e)
}(t)) || e && t && "number" == typeof t.length) {
n && (t = n);
var r = 0,
o = function() {};
return {
s: o,
n: function() {
return r >= t.length ? {
done: !0
} : {
done: !1,
value: t[r++]
}
},
e: function(t) {
throw t
},
f: o
}
}
throw new TypeError(
"Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
)
}
var i, a = !0,
u = !1;
return {
s: function() {
n = n.call(t)
},
n: function() {
var t = n.next();
return a = t.done, t
},
e: function(t) {
u = !0, i = t
},
f: function() {
try {
a || null == n.return || n.return()
} finally {
if (u) throw i
}
}
}
}
function x(t, e) {
(null == e || e > t.length) && (e = t.length);
for (var n = 0, r = new Array(e); n < e; n++) r[n] = t[n];
return r
}
function O() {
return null == h && (h = "undefined" == typeof unsafeWindow ? window : unsafeWindow), h
}
function R() {
var t = O().parent !== O();
try {
t = t && "FRAMESET" !== O().parent.document.body.tagName
} catch (t) {}
return t
}! function(t) {
t.BOOLEAN = "boolean", t.STRING = "string", t.NUMBER = "number", t.SHORTCUT = "shortcut", t
.LONG_STRING = "long_string", t.DATE = "date", t.COLOR = "color", t.ARRAY = "array", t.PICKLIST =
"picklist", t.DUELING_PICKLIST = "dueling_picklist"
}(f || (f = {}));
var M = "__hooks_load_module",
_ = Object.getOwnPropertyNames.bind(Object),
A = Object.getPrototypeOf.bind(Object);
function S(t) {
var e, n = {},
r = k(_(t));
try {
for (r.s(); !(e = r.n()).done;) {
var o = e.value;
n[o] = t[o]
}
} catch (t) {
r.e(t)
} finally {
r.f()
}
return n
}
var C = [
[Array.prototype],
[Object, !1]
].map((function(t) {
var e = w(t, 1)[0];
return [e, S(e)]
}));
function T(t) {
var e, n = k(C);
try {
for (n.s(); !(e = n.n()).done;) {
var r = w(e.value, 2),
o = r[0],
i = r[1];
if (t === o) return i
}
} catch (t) {
n.e(t)
} finally {
n.f()
}
return t
}
function I(t, e) {
return function(t, e) {
var n = T(arguments.length > 2 && void 0 !== arguments[2] && !arguments[2] ? t : A(t)),
r = n[e];
return "function" == typeof r ? r.bind(t) : n[e]
}(e.conditions || [], "reduce")((function(e, n) {
return e || Object.entries(n).every((function(e) {
var n = w(e, 2),
r = n[0],
o = n[1];
return t[r] === o
}))
}), !1)
}
var E = {};
try {
E.addStyle = GM_addStyle
} catch (t) {}
try {
E.addElement = GM_addElement
} catch (t) {}
try {
E.deleteValue = GM_deleteValue
} catch (t) {}
try {
E.listValues = GM_listValues
} catch (t) {}
try {
E.getValue = GM_getValue
} catch (t) {}
try {
E.setValue = GM_setValue
} catch (t) {}
try {
E.addValueChangeListener = GM_addValueChangeListener
} catch (t) {}
try {
E.removeValueChangeListener = GM_removeValueChangeListener
} catch (t) {}
try {
E.xmlhttpRequest = GM_xmlhttpRequest
} catch (t) {}
try {
E.registerMenuCommand = GM_registerMenuCommand
} catch (t) {}
try {
E.unregisterMenuCommand = GM_unregisterMenuCommand
} catch (t) {}
try {
E.download = GM_download
} catch (t) {}
try {
E.log = GM_log
} catch (t) {}
try {
E.openInTab = GM_openInTab
} catch (t) {}
try {
E.setClipboard = GM_setClipboard
} catch (t) {}
try {
E.info = GM_info
} catch (t) {}
try {
E.getResourceText = GM_getResourceText
} catch (t) {}
try {
E.getResourceURL = GM_getResourceURL
} catch (t) {}
try {
E.getTab = GM_getTab
} catch (t) {}
try {
E.getTabs = GM_getTabs
} catch (t) {}
try {
E.saveTab = GM_saveTab
} catch (t) {}
try {
E.notification = GM_notification
} catch (t) {}
var j = window,
D = new Proxy({}, {
get: function(t, e) {
var n = ["GM", e].join("_");
return j[n] ? j[n] : E[e] ? E[e] : j.GM && j.GM[e] ? j.GM[e] : void 0
}
}),
P = function() {
if (!R()) {
for (var t = arguments.length, e = new Array(t), n = 0; n < t; n++) e[n] = arguments[n];
var r;
if (e.unshift("[TimerHook]"), "function" == typeof D.log) D.log(e.join(" "));
else(r = console).log.apply(r, e)
}
},
N = function() {
if (!R()) {
for (var t, e = arguments.length, n = new Array(e), r = 0; r < e; r++) n[r] = arguments[r];
n.unshift("[TimerHook]"), (t = console).warn.apply(t, n)
}
},
L = function() {
function e() {
t(this, e), l(this, "host", void 0), l(this, "isActive", !1), l(this, "isMountHost", !1)
}
return n(e, [{
key: "mountHost",
value: function(t) {
this.host = t, this.isMountHost = !0, this.onMounted()
}
}, {
key: "activate",
value: function() {
this.isActive = !0, this.init()
}
}, {
key: "deactivate",
value: function() {
this.isActive = !1, this.onDestroy()
}
}, {
key: "moduleName",
get: function() {}
}, {
key: "priority",
get: function() {
return 50
}
}, {
key: "autoActivate",
get: function() {
return !0
}
}, {
key: "isCoreModule",
get: function() {
return !1
}
}, {
key: "isOnlyOuterIframe",
get: function() {
return !1
}
}, {
key: "getDependencyModule",
value: function(t) {
if (null != this.host) {
var e = this.host.getModule(t);
return e && e.moduleIdentityName ? e : void 0
}
}
}, {
key: "init",
value: function() {}
}, {
key: "onMounted",
value: function() {}
}, {
key: "onDestroy",
value: function() {}
}, {
key: "declareConfigs",
value: function() {
return []
}
}, {
key: "setConfig",
value: function(t, e) {
var n = this.getDependencyModule("configs");
n && n.available() || N(
"Config module not found, can't set configs values."), n.setValue(
this.moduleIdentityName, t, e)
}
}, {
key: "getConfig",
value: function(t) {
var e, n = this.getDependencyModule("configs"),
r = (this.declareConfigs().find((function(e) {
return e.key === t
})) || {}).default;
return n && n.available() && null !== (e = n.getValue(this
.moduleIdentityName, t)) && void 0 !== e ? e : r
}
}, {
key: "window",
get: function() {
return this.host ? this.host.getWindow() : O()
}
}, {
key: "document",
get: function() {
return this.window.document
}
}]), e
}();
function B(t, e, n) {
return (B = "undefined" != typeof Reflect && Reflect.get ? Reflect.get : function(t, e, n) {
var r = function(t, e) {
for (; !Object.prototype.hasOwnProperty.call(t, e) && null !== (t = c(t)););
return t
}(t, e);
if (r) {
var o = Object.getOwnPropertyDescriptor(r, e);
return o.get ? o.get.call(n) : o.value
}
})(t, e, n || t)
}
function V(t) {
var e = function() {
if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
if (Reflect.construct.sham) return !1;
if ("function" == typeof Proxy) return !0;
try {
return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), !0
} catch (t) {
return !1
}
}();
return function() {
var n, r = c(t);
if (e) {
var o = c(this).constructor;
n = Reflect.construct(r, arguments, o)
} else n = r.apply(this, arguments);
return u(this, n)
}
}
var U = function(e) {
i(a, e);
var o = V(a);
function a() {
var e;
t(this, a);
for (var n = arguments.length, i = new Array(n), u = 0; u < n; u++) i[u] = arguments[u];
return l(r(e = o.call.apply(o, [this].concat(i))), "rate", 1), l(r(e), "host", void 0), e
}
return n(a, [{
key: "onRateChange",
value: function(t) {
this.rate = t
}
}, {
key: "mountHost",
value: function(t) {
B(c(a.prototype), "mountHost", this).call(this, t), this.rate = t.rate
}
}]), a
}(L);
function G(t) {
var e = function() {
if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
if (Reflect.construct.sham) return !1;
if ("function" == typeof Proxy) return !0;
try {
return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), !0
} catch (t) {
return !1
}
}();
return function() {
var n, r = c(t);
if (e) {
var o = c(this).constructor;
n = Reflect.construct(r, arguments, o)
} else n = r.apply(this, arguments);
return u(this, n)
}
}
var H = function(e) {
i(a, e);
var o = G(a);
function a() {
var e;
t(this, a);
for (var n = arguments.length, i = new Array(n), u = 0; u < n; u++) i[u] = arguments[u];
return l(r(e = o.call.apply(o, [this].concat(i))), "isDOMLoaded", !1), l(r(e),
"waitDomLoadedCallback", void 0), e
}
return n(a, [{
key: "onMounted",
value: function() {
var t = this;
B(c(a.prototype), "onMounted", this).call(this), this.document
.addEventListener("readystatechange", (function() {
"interactive" !== t.document.readyState && "complete" !== t
.document.readyState || (t.isDOMLoaded = !0,
"function" == typeof t.waitDomLoadedCallback && t
.waitDomLoadedCallback(void 0))
}))
}
}, {
key: "waitDomLoaded",
value: function() {
var t, e, n, r = this;
return this.isDOMLoaded || null !== (t = this.document) && void 0 !== t &&
null !== (e = t.body) && void 0 !== e && null !== (n = e.childNodes) &&
void 0 !== n && n.length ? Promise.resolve() : new Promise((function(
t) {
r.waitDomLoadedCallback = t
}))
}
}, {
key: "applyStyle",
value: function(t) {
var e = this.style(),
n = this.document.createElement("style");
if (n.setAttribute("type", "text/css"), n.styleSheet) n.styleSheet.cssText =
e;
else {
var r = this.document.createTextNode(e);
n.appendChild(r)
}
t.appendChild(n)
}
}, {
key: "applyElement",
value: function() {
var t = this.element();
t.hidden = !__videoSpeedAccess.allowed;
return this.document.body.appendChild(t), t
}
}, {
key: "onUiRateChange",
value: function(t) {}
}, {
key: "onRateChange",
value: function(t) {
var e = this.rate !== t;
B(c(a.prototype), "onRateChange", this).call(this, t), e && this
.onUiRateChange(t)
}
}, {
key: "init",
value: function() {
var t = this;
P("Started to loading '".concat(this.moduleIdentityName, "' component...")),
this.waitDomLoaded().then((function() {
t.applyStyle(t.applyElement()), P("UI component '".concat(t
.moduleIdentityName, "' loaded."))
}))
}
}]), a
}(U);
function W(t) {
var e = function() {
if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
if (Reflect.construct.sham) return !1;
if ("function" == typeof Proxy) return !0;
try {
return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), !0
} catch (t) {
return !1
}
}();
return function() {
var n, r = c(t);
if (e) {
var o = c(this).constructor;
n = Reflect.construct(r, arguments, o)
} else n = r.apply(this, arguments);
return u(this, n)
}
}
var q = "hook_timer__change_rate",
F = function(e) {
i(a, e);
var o = W(a);
function a() {
var e;
t(this, a);
for (var n = arguments.length, i = new Array(n), u = 0; u < n; u++) i[u] = arguments[u];
return l(r(e = o.call.apply(o, [this].concat(i))), "rate", 1), l(r(e), "state", "preparing"), l(
r(e), "setIntervalOrigin", void 0), l(r(e), "clearIntervalOrigin", void 0), l(r(e),
"inTimeCheckId", void 0), e
}
return n(a, [{
key: "setSpeed",
value: function(t) {
if (!__videoSpeedAccess.allowed && t !== 1) return;
var e = arguments.length > 1 && void 0 !== arguments[1] && arguments[1];
if (0 === t && (t = this.defaultRate), Number.isFinite(t) && (t !== this.rate || e) && t >
0 && (this.rate = t, this.onRateChanged(t)), null == t) {
var n = prompt("输入欲改变计时器变化倍率(当前:" + this.rate + ")");
n && this.setSpeed(parseFloat(n))
}
}
}, {
key: "speedDown",
value: function(t) {
null == t && (t = this.getConfig("decrementRate")), this.setSpeed(this
.rate - t)
}
}, {
key: "speedUp",
value: function(t) {
null == t && (t = this.getConfig("incrementRate")), this.setSpeed(this
.rate + t)
}
}, {
key: "speedDivide",
value: function(t) {
null == t && (t = this.getConfig("divideRate")), this.setSpeed(this.rate / (
t || 1))
}
}, {
key: "speedMultiply",
value: function(t) {
null == t && (t = this.getConfig("multiplyRate")), this.setSpeed(this.rate *
(t || 1))
}
}, {
key: "onRateChanged",
value: function(t) {
P("Timer speed rate changed to:", t), this.sentChangesToIframe(), this
.getAllActivateModules().filter((function(t) {
return t.onRateChange
})).forEach((function(e) {
e.onRateChange(t)
}))
}
}, {
key: "beginInTimeCheck",
value: function() {
var t = this;
this.keptInTime && (this.inTimeCheckId = this.setIntervalOrigin.call(this
.getWindow(), (function() {
t.rate && 1 !== t.rate && t.setSpeed(t.rate, !0)
}), this.keptInterval))
}
}, {
key: "catchOriginMethod",
value: function() {
this.setIntervalOrigin = this.getWindow().setInterval, this
.clearIntervalOrigin = this.getWindow().clearInterval
}
}, {
key: "keptInTime",
get: function() {
return this.getConfig("keptInTime")
}
}, {
key: "keptInterval",
get: function() {
return this.getConfig("keptInterval")
}
}, {
key: "defaultRate",
get: function() {
return this.getConfig("defaultRate")
}
}, {
key: "bootstrap",
value: function() {
"preparing" === this.state && (this.catchOriginMethod(), this
.listenParentEvent(), this.launchModules(this.getAllModules()), this
.setSpeed(this.defaultRate), this.beginInTimeCheck(), this
.waitForModulesLoad(), this.state = "started")
}
}, {
key: "launchModules",
value: function(t) {
var e = this;
t.filter((function(t) {
return t.autoActivate
})).forEach((function(t) {
var n = t.moduleIdentityName;
e.deactivateModules.includes(n) && !t.isCoreModule || e
.activateModule(n)
}))
}
}, {
key: "registerModules",
value: function(t) {
var e = this;
return t.filter((function(t) {
var n = t.moduleIdentityName;
return n && e.registerModule(t, t.isOnlyOuterIframe), n
}))
}
}, {
key: "waitForModulesLoad",
value: function() {
var t = this,
e = this.getWindow().___hooks_preModules || [];
e.length > 0 && this.launchModules(this.registerModules(e)), this
.getWindow()[M] = 1, this.getWindow().addEventListener(M, (function(e) {
e.detail && e.detail.moduleIdentityName && t.launchModules(t
.registerModules([e.detail]))
}))
}
}, {
key: "exportOuter",
value: function() {
var t = this;
this.getWindow()._OxA ? (this.getWindow().$hookTimer = this, this
.getWindow()._OxA = this) : Object.defineProperty(this.getWindow(),
"_OxA", {
get: function() {
return 1
},
set: function(e) {
"_OxA" === e && (t.getWindow().$hookTimer = t)
}
})
}
}, {
key: "listenParentEvent",
value: function() {
var t = this;
v() && this.getWindow().addEventListener("message", (function(e) {
var n = e.data;
(n.type || "") === q && t.setSpeed(n.rate || 0)
}))
}
}, {
key: "deactivateModules",
get: function() {
return this.getConfig("deactivateModules")
}
}, {
key: "sentChangesToIframe",
value: function() {
var t = this.getWindow().document,
e = t.querySelectorAll("iframe") || [],
n = t.querySelectorAll("frame");
if (e.length)
for (var r = 0; r < e.length; r++) e[r].contentWindow.postMessage({
type: q,
rate: this.rate
}, "*");
if (n.length)
for (var o = 0; o < n.length; o++) n[o].contentWindow.postMessage({
type: q,
rate: this.rate
}, "*")
}
}, {
key: "declareConfigs",
value: function() {
return [{
key: "multiplyRate",
type: f.NUMBER,
default: 2
}, {
key: "divideRate",
type: f.NUMBER,
default: 2
}, {
key: "decrementRate",
type: f.NUMBER,
default: 2
}, {
key: "incrementRate",
type: f.NUMBER,
default: 2
}, {
key: "defaultRate",
type: f.NUMBER,
default: 1
}, {
key: "keptInTime",
type: f.BOOLEAN,
default: !0
}, {
key: "keptInterval",
type: f.NUMBER,
default: 4e3
}, {
key: "deactivateModules",
type: f.ARRAY,
values: this.getAllModules().map((function(t) {
return {
key: t.moduleIdentityName
}
})),
default: []
}]
}
}, {
key: "setConfig",
value: function(t, e) {
var n = this.getModule("configs");
n && n.available() || N(
"Config module not found, can't set configs values."), n.setValue(
"host", t, e)
}
}, {
key: "getConfig",
value: function(t) {
var e, n = this.getModule("configs"),
r = (this.declareConfigs().find((function(e) {
return e.key === t
})) || {}).default;
return n && n.available() && null !== (e = n.getValue("host", t)) &&
void 0 !== e ? e : r
}
}]), a
}(function() {
function e() {
t(this, e), l(this, "modules", {})
}
return n(e, [{
key: "activateModule",
value: function(t) {
var e = this.getModule(t);
e ? (e.activate(), P("Module - '".concat(t, "' activated"))) : N(
"Activate module failed, ".concat(t, " is not found"))
}
}, {
key: "deactivateModule",
value: function(t) {
var e = this.getModule(t);
e || N("Deactivate module failed, '".concat(t, "' is not found")), e
.deactivate()
}
}, {
key: "getModule",
value: function(t) {
return this.modules[t]
}
}, {
key: "registerModule",
value: function(t) {
var e = arguments.length > 1 && void 0 !== arguments[1] && arguments[1];
e && v() || (this.modules[t.moduleIdentityName] = t, t.mountHost(this))
}
}, {
key: "getAllActivateModules",
value: function() {
return Object.values(this.modules).filter((function(t) {
return t.isActive
}))
}
}, {
key: "getAllModules",
value: function() {
return Object.values(this.modules)
}
}, {
key: "getWindow",
value: function() {
return p()
}
}]), e
}());
var z = function(t, e) {
if (!(t instanceof e)) throw new TypeError("Cannot call a class as a function")
};
function Y(t, e) {
return t(e = {
exports: {}
}, e.exports), e.exports
}
var $ = Y((function(t) {
function e(n, r) {
return t.exports = e = Object.setPrototypeOf || function(t, e) {
return t.__proto__ = e, t
}, e(n, r)
}
t.exports = e
}));
var K = function(t, e) {
if ("function" != typeof e && null !== e) throw new TypeError(
"Super expression must either be null or a function");
t.prototype = Object.create(e && e.prototype, {
constructor: {
value: t,
writable: !0,
configurable: !0
}
}), e && $(t, e)
},
J = Y((function(t) {
function e(n) {
return "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? t.exports =
e = function(t) {
return typeof t
} : t.exports = e = function(t) {
return t && "function" == typeof Symbol && t.constructor === Symbol && t !==
Symbol.prototype ? "symbol" : typeof t
}, e(n)
}
t.exports = e
}));
var Q = function(t) {
if (void 0 === t) throw new ReferenceError(
"this hasn't been initialised - super() hasn't been called");
return t
};
var X = function(t, e) {
return !e || "object" !== J(e) && "function" != typeof e ? Q(t) : e
},
Z = Y((function(t) {
function e(n) {
return t.exports = e = Object.setPrototypeOf ? Object.getPrototypeOf : function(t) {
return t.__proto__ || Object.getPrototypeOf(t)
}, e(n)
}
t.exports = e
}));
var tt = function(t, e) {
(null == e || e > t.length) && (e = t.length);
for (var n = 0, r = new Array(e); n < e; n++) r[n] = t[n];
return r
};
var et = function(t) {
if (Array.isArray(t)) return tt(t)
};
var nt = function(t) {
if ("undefined" != typeof Symbol && Symbol.iterator in Object(t)) return Array.from(t)
};
var rt = function(t, e) {
if (t) {
if ("string" == typeof t) return tt(t, e);
var n = Object.prototype.toString.call(t).slice(8, -1);
return "Object" === n && t.constructor && (n = t.constructor.name), "Map" === n || "Set" === n ?
Array.from(t) : "Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n) ?
tt(t, e) : void 0
}
};
var ot = function() {
throw new TypeError(
"Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
)
};
var it = function(t) {
return et(t) || nt(t) || rt(t) || ot()
};
function at(t, e) {
for (var n = 0; n < e.length; n++) {
var r = e[n];
r.enumerable = r.enumerable || !1, r.configurable = !0, "value" in r && (r.writable = !0), Object
.defineProperty(t, r.key, r)
}
}
var ut = function(t, e, n) {
return e && at(t.prototype, e), n && at(t, n), t
};
var ct = function(t, e) {
for (; !Object.prototype.hasOwnProperty.call(t, e) && null !== (t = Z(t)););
return t
},
lt = Y((function(t) {
function e(n, r, o) {
return "undefined" != typeof Reflect && Reflect.get ? t.exports = e = Reflect.get : t
.exports = e = function(t, e, n) {
var r = ct(t, e);
if (r) {
var o = Object.getOwnPropertyDescriptor(r, e);
return o.get ? o.get.call(n) : o.value
}
}, e(n, r, o || n)
}
t.exports = e
}));
var st = function(t) {
return -1 !== Function.toString.call(t).indexOf("[native code]")
};
var ft = function() {
if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
if (Reflect.construct.sham) return !1;
if ("function" == typeof Proxy) return !0;
try {
return Date.prototype.toString.call(Reflect.construct(Date, [], (function() {}))), !0
} catch (t) {
return !1
}
},
ht = Y((function(t) {
function e(n, r, o) {
return ft() ? t.exports = e = Reflect.construct : t.exports = e = function(t, e, n) {
var r = [null];
r.push.apply(r, e);
var o = new(Function.bind.apply(t, r));
return n && $(o, n.prototype), o
}, e.apply(null, arguments)
}
t.exports = e
})),
dt = Y((function(t) {
function e(n) {
var r = "function" == typeof Map ? new Map : void 0;
return t.exports = e = function(t) {
if (null === t || !st(t)) return t;
if ("function" != typeof t) throw new TypeError(
"Super expression must either be null or a function");
if (void 0 !== r) {
if (r.has(t)) return r.get(t);
r.set(t, e)
}
function e() {
return ht(t, arguments, Z(this).constructor)
}
return e.prototype = Object.create(t.prototype, {
constructor: {
value: e,
enumerable: !1,
writable: !0,
configurable: !0
}
}), $(e, t)
}, e(n)
}
t.exports = e
}));
function yt(t, e) {
var n = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : "initAssign",
r = Object.getPrototypeOf(e);
return Object.setPrototypeOf(t, r), "function" == typeof r[n] && r[n].call(t, e), t
}
function pt(t) {
return Number(Math.random().toString().substr(3, t) + Date.now()).toString(36)
}
function vt(t) {
var e = function() {
if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
if (Reflect.construct.sham) return !1;
if ("function" == typeof Proxy) return !0;
try {
return Date.prototype.toString.call(Reflect.construct(Date, [], (function() {}))), !0
} catch (t) {
return !1
}
}();
return function() {
var n, r = Z(t);
if (e) {
var o = Z(this).constructor;
n = Reflect.construct(r, arguments, o)
} else n = r.apply(this, arguments);
return X(this, n)
}
}! function(t, e) {
t(e = {
exports: {}
}, e.exports)
}((function(t) {
function e(n) {
return "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? t.exports = e =
function(t) {
return typeof t
} : t.exports = e = function(t) {
return t && "function" == typeof Symbol && t.constructor === Symbol && t !== Symbol
.prototype ? "symbol" : typeof t
}, e(n)
}
t.exports = e
}));
var gt = {
instanceType: function(t) {
K(n, t);
var e = vt(n);
function n() {
return z(this, n), e.apply(this, arguments)
}
return ut(n, [{
key: "initAssign",
value: function(t) {
this.id = pt(7),
function(t, e, n, r) {
e && void 0 !== e[n] ? t[n] = e[n] : "function" ==
typeof r && (t[n] = r())
}(this, t, "uniqueId", (function() {
return pt(7)
}))
}
}, {
key: "bind",
value: function(t) {
var e, r = arguments.length > 1 && void 0 !== arguments[1] ?
arguments[1] : [];
return yt((e = lt(Z(n.prototype), "bind", this)).call.apply(e, [
this, t
].concat(it(r))), this)
}
}, {
key: "before",
value: function(t) {
var e = arguments.length > 1 && void 0 !== arguments[1] &&
arguments[1];
return this.surround({
before: t,
adaptAsync: e
})
}
}, {
key: "after",
value: function(t) {
var e = arguments.length > 1 && void 0 !== arguments[1] &&
arguments[1];
return this.surround({
after: t,
adaptAsync: e
})
}
}, {
key: "surround",
value: function(t) {
var e = t.before,
n = void 0 === e ? void 0 : e,
r = t.after,
o = void 0 === r ? void 0 : r,
i = t.onError,
a = void 0 === i ? void 0 : i,
u = t.adaptAsync,
c = void 0 !== u && u,
l = this;
return "function" != typeof l ? l : yt((function() {
for (var t = this, e = arguments.length, r =
new Array(e), i = 0; i < e; i++) r[i] =
arguments[i];
var u = {},
s = {
origin: l,
args: r,
trans: u
},
f = "function" == typeof a;
try {
var h, d, y = !1;
return "function" == typeof n && (h = n.call(
this, Object.assign({}, s, {
preventDefault: function() {
y = !0
}
})), y) ? h : (d =
h instanceof Promise && c ? h.then((
function() {
return l.apply(t, r)
})) : l.apply(this, r),
"function" == typeof o && (d =
d instanceof Promise && c ? d.then((
function(e) {
return o.call(t, Object
.assign({}, s, {
lastValue: e
}))
})) : o.call(this, Object
.assign({}, s, {
lastValue: d
}))), d instanceof Promise &&
c && f ? d.catch((function(e) {
var n = !1,
r = "";
return Promise.resolve(a
.call(t, Object
.assign({}, s, {
error: e,
resolve: function(
t
) {
r = t,
n = !
0
}
}))).then((
function(t) {
if (!n)
throw e;
return r ||
t
}))
})) : d)
} catch (t) {
if (!f) throw t;
var p = !1,
v = "",
g = function(t) {
v = t, p = !0
},
m = a.call(this, Object.assign({}, s, {
error: t,
resolve: g
}));
if (!p) throw t;
return v || m
}
}), this)
}
}, {
key: "then",
value: function(t) {
var e = this;
return yt((function() {
for (var n = arguments.length, r = new Array(n), o =
0; o < n; o++) r[o] = arguments[o];
var i = e.apply(this, r);
return Promise.resolve(i).then(t)
}), this)
}
}, {
key: "catch",
value: function(t) {
var e = this;
return yt((function() {
var n;
try {
for (var r = arguments.length, o = new Array(r),
i = 0; i < r; i++) o[i] = arguments[i];
if ((n = e.apply(this, o)) instanceof Promise)
return n.catch(t)
} catch (e) {
n = t.call(this, e)
}
return n
}), this)
}
}, {
key: "finally",
value: function(t) {
var e = this;
return yt((function() {
var n = function() {
try {
t.call(this)
} catch (t) {}
};
try {
for (var r = arguments.length, o = new Array(r),
i = 0; i < r; i++) o[i] = arguments[i];
var a = e.apply(this, o);
return a instanceof Promise ? "function" ==
typeof a.finally ? a.finally((function() {
return n()
})) : a.catch((function(t) {
return t
})).then((function(t) {
if (n(), t instanceof Error)
throw t
})) : (n(), a)
} catch (t) {
throw n(), t
}
}), this)
}
}, {
key: "register",
value: function() {
var t = arguments.length > 0 && void 0 !== arguments[0] ? arguments[
0] : {};
return this.registerClass((function(e) {
var n = function(t) {
K(n, t);
var e = vt(n);
function n() {
return z(this, n), e.apply(this,
arguments)
}
return n
}(e);
return Object.assign(n.prototype, t), n
}))
}
}, {
key: "registerClass",
value: function(t) {
var e = t(this.constructor),
n = this.bind(this);
if (Object.setPrototypeOf(n, e.prototype), "function" != typeof e ||
!(n instanceof this.constructor)) throw new Error(
"Registered class must extend FunctionInstance");
return n
}
}]), n
}(dt(Function))
};
function mt(t, e) {
var n = function() {
for (var e = arguments.length, n = new Array(e), r = 0; r < e; r++) n[r] = arguments[r];
return (t || function() {}).apply(this, n)
};
return function(t, e) {
var n = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : "initAssign",
r = e.prototype;
Object.setPrototypeOf(t, r), "function" == typeof r[n] && r[n].call(t)
}(n, (e = Object.assign({}, gt, e)).instanceType), n
}
var bt, wt = {
protect: !1,
syncDesc: !0,
native: !1
},
kt = Object.defineProperty,
xt = Object.defineProperties;
function Ot(t, e, n) {
var r = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : {},
o = t[e];
if ("function" == typeof o) {
var i = Object.assign({}, wt, r),
a = i.native,
u = n(a ? o : mt(o));
t[e] = a ? u : function() {
for (var t = arguments.length, e = new Array(t), n = 0; n < t; n++) e[n] = arguments[n];
try {
return u.apply(this, e)
} catch (t) {
return console.warn("[Hook JS]", "Hooks running lost once."), o.apply(this, e)
}
};
var c = i.protect,
l = i.syncDesc;
c && At(t, e), l && St(o, t[e])
}
}
function Rt(t, e, n, r) {
var o = arguments.length > 4 && void 0 !== arguments[4] ? arguments[4] : {};
return Ot(t, e, (function(t) {
return t[n](r)
}), o)
}
function Mt(t, e, n) {
var r = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : {};
return Rt(t, e, "before", n, r)
}
function _t(t, e, n) {
var r = arguments.length > 3 && void 0 !== arguments[3] ? arguments[3] : {};
return Ot(t, e, n, Object.assign({}, r, {
native: !0
}))
}
function At(t, e) {
kt.call(Object, t, e, {
writable: !1
})
}
function St(t, e) {
xt.call(Object, e, {
toString: {
enumerable: !1,
writable: !0,
value: function() {
return t.toString()
}
},
toLocaleString: {
enumerable: !1,
writable: !0,
value: function() {
return t.toLocaleString()
}
}
})
}
function Ct(t) {
var e = function() {
if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
if (Reflect.construct.sham) return !1;
if ("function" == typeof Proxy) return !0;
try {
return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), !0
} catch (t) {
return !1
}
}();
return function() {
var n, r = c(t);
if (e) {
var o = c(this).constructor;
n = Reflect.construct(r, arguments, o)
} else n = r.apply(this, arguments);
return u(this, n)
}
}! function(t) {
t.TIMEOUT = "timeout", t.INTERVAL = "interval"
}(bt || (bt = {}));
var Tt = function(e) {
i(a, e);
var o = Ct(a);
function a() {
var e;
t(this, a);
for (var n = arguments.length, i = new Array(n), u = 0; u < n; u++) i[u] = arguments[u];
return l(r(e = o.call.apply(o, [this].concat(i))), "percentage", void 0), l(r(e),
"interval", Object.create(null)), l(r(e), "timeout", Object.create(null)), l(r(e), "setIntervalOrigin", void 0), l(r(e),
"setTimeoutOrigin", void 0), l(r(e), "clearIntervalOrigin", void 0), l(r(e),
"clearTimeoutOrigin", void 0), e
}
return n(a, [{
key: "onMounted",
value: function() {
B(c(a.prototype), "onMounted", this).call(this), this.setIntervalOrigin =
this.window.setInterval, this.setTimeoutOrigin = this.window.setTimeout,
this.clearIntervalOrigin = this.window.clearInterval, this
.clearTimeoutOrigin = this.window.clearTimeout
}
}, {
key: "init",
value: function() {
var t = this;
this.percentage = 1 / this.rate, _t(this.window, "setInterval", (function(
e) {
return t.getHookedTimerFunction(bt.INTERVAL, e)
})), _t(this.window, "setTimeout", (function(e) {
return t.getHookedTimerFunction(bt.TIMEOUT, e)
})), Mt(this.window, "clearInterval", (function(e) {
var n = e.args;
t.redirectNewestId(n)
})), Mt(this.window, "clearTimeout", (function(e) {
var n = e.args;
t.redirectNewestId(n)
}))
}
}, {
key: "onRateChange",
value: function(t) {
var e = this, previousRate = this.rate;
B(c(a.prototype), "onRateChange", this).call(this, t), this.percentage = 1 /
t;
// 四秒保持仍可修正视频速度,但同倍率不重建游戏心跳和定时任务。
if (previousRate === t) return;
Object.values(this.interval).forEach((function(record) {
record.args[1] = e.getScaledDelay(record.originMS);
e.clearIntervalOrigin.call(e.window, record.nowId);
record.nowId = e.setIntervalOrigin.apply(e.window, record.args);
}));
var now = __videoSpeedNative.now();
Object.values(this.timeout).forEach((function(record) {
if (record.readyToRun) return;
var fullDelay = e.getScaledDelay(record.originMS);
var remaining = Math.max(0, record.exceptNextFireTime - now);
// 截止时间和余量都用未倍速的真实时钟;钳制后的延时也参与换算。
var delay = record.scheduledDelay > 0 ? Math.floor(
Math.min(remaining, record.scheduledDelay) * fullDelay / record.scheduledDelay
) : 0;
e.clearTimeoutOrigin.call(e.window, record.nowId);
e.clearTimeoutCleanup(record);
record.scheduledDelay = fullDelay;
record.exceptNextFireTime = now + delay;
record.nowId = e.scheduleTimeout(record, delay);
}));
}
}, {
key: "normalizeDelay",
value: function(delay) {
// 对齐浏览器的有符号 long 转换,避免字符串拼接和超范围延时溢出。
var numeric = +delay;
return Math.max(0, Number.isFinite(numeric) ? numeric >> 0 : 0);
}
}, {
key: "getScaledDelay",
value: function(delay) {
if (delay <= 0) return 0;
// 不把正延时压成忙循环,也不放慢原本就短于 4ms 的任务。
return Math.min(2147483647, Math.max(Math.min(delay, 4), Math.floor(delay * this.percentage)));
}
}, {
key: "clearTimeoutCleanup",
value: function(record) {
if (record.cleanupId != null) {
this.clearTimeoutOrigin.call(this.window, record.cleanupId);
record.cleanupId = null;
}
if (record.releaseId != null) {
this.clearTimeoutOrigin.call(this.window, record.releaseId);
record.releaseId = null;
}
}
}, {
key: "scheduleTimeout",
value: function(record, delay) {
var self = this, id = null;
record.args[1] = delay;
record.readyToRun = false;
// 字符串交给原生计时器执行,保留全局作用域和 CSP 行为。
// 到期先禁止重排,主体之后才释放 ID 映射,期间仍可取消。
if (record.stringHandler) {
record.cleanupId = this.setTimeoutOrigin.call(this.window, function() {
self.notifyExec(record.originId);
}, delay);
}
try {
id = this.setTimeoutOrigin.apply(this.window, record.args);
if (record.stringHandler) {
record.releaseId = this.setTimeoutOrigin.call(this.window, function() {
delete self.timeout[record.originId];
record.releaseId = null;
}, delay);
}
return id;
} catch (error) {
if (id !== null) this.clearTimeoutOrigin.call(this.window, id);
this.clearTimeoutCleanup(record);
throw error;
}
}
}, {
key: "notifyExec",
value: function(id) {
var record = this.timeout[id];
if (!record) return;
if (record.stringHandler) {
record.cleanupId = null;
record.readyToRun = true;
return;
}
delete this.timeout[id];
this.clearTimeoutCleanup(record);
}
}, {
key: "redirectNewestId",
value: function(args) {
// 浏览器的 timeout/interval 共用 ID 池,两个 clear 方法均可交叉取消。
var id = args[0], record = this.interval[id] || this.timeout[id];
if (!record) return;
args[0] = record.nowId;
this.clearTimeoutCleanup(record);
delete this.interval[id];
delete this.timeout[id];
}
}, {
key: "getHookedTimerFunction",
value: function(t, e) {
var n = t,
r = this;
return function() {
for (var t = arguments.length, o = new Array(t), i = 0; i < t; i++)
o[i] = arguments[i];
var handler = o[0], originMS = r.normalizeDelay(o[1]);
var delay = r.getScaledDelay(originMS);
var record = {
args: o,
originMS: originMS,
originId: null,
nowId: null,
cleanupId: null,
releaseId: null,
readyToRun: false,
stringHandler: typeof handler !== "function",
scheduledDelay: delay,
exceptNextFireTime: __videoSpeedNative.now() + delay
};
// timeout 在调用用户代码前直接删除:抛错、回调内调速均不会复活。
// interval 不需要清理 timeout,也不扫描其他未完成任务。
if (n === bt.TIMEOUT && typeof handler === "function") {
o[0] = function() {
r.notifyExec(record.originId);
return handler.apply(this, arguments);
};
}
o[1] = delay;
var id = n === bt.TIMEOUT ? r.scheduleTimeout(record, delay) : e.apply(r.window, o);
record.originId = record.nowId = id;
r[n][id] = record;
return id;
}
}
}, {
key: "moduleIdentityName",
get: function() {
return "timer"
}
}]), a
}(U);
function It(t) {
var e = function() {
if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
if (Reflect.construct.sham) return !1;
if ("function" == typeof Proxy) return !0;
try {
return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), !0
} catch (t) {
return !1
}
}();
return function() {
var n, r = c(t);
if (e) {
var o = c(this).constructor;
n = Reflect.construct(r, arguments, o)
} else n = r.apply(this, arguments);
return u(this, n)
}
}
var Et, jt = function(e) {
i(a, e);
var o = It(a);
function a() {
var e;
t(this, a);
for (var n = arguments.length, i = new Array(n), u = 0; u < n; u++) i[u] = arguments[u];
return l(r(e = o.call.apply(o, [this].concat(i))), "DateOrigin", void 0), l(r(e),
"DateModified", void 0), l(r(e), "rate", 1), l(r(e), "lastDatetime", void 0), l(r(e),
"lastMDatetime", void 0), e
}
return n(a, [{
key: "onMounted",
value: function() {
B(c(a.prototype), "onMounted", this).call(this), this.lastDatetime = Date
.now(), this.lastMDatetime = Date.now(), this.DateOrigin = this.window
.Date, this.DateModified = this.window.Date
}
}, {
key: "init",
value: function() {
this.hookedDate()
}
}, {
key: "onRateChange",
value: function(t) {
this.DateModified && (this.lastMDatetime = this.DateModified.now(), this
.lastDatetime = this.DateOrigin.now()), B(c(a.prototype),
"onRateChange", this).call(this, t)
}
}, {
key: "hookedDate",
value: function() {
var e = this,
n = this;
_t(this.window, "Date", (function(e) {
var r = function(e) {
i(o, e);
var r = It(o);
function o() {
t(this, o);
for (var e = arguments.length, i = new Array(e),
a = 0; a < e; a++) i[a] = arguments[a];
if (0 === i.length) {
var u = n.DateOrigin.now(),
c = u - n.lastDatetime,
l = c * n.rate;
i.push(n.lastMDatetime + l)
}
return r.call.apply(r, [this].concat(i))
}
return o
}(e);
return r = r.bind(new r)
})), this.DateModified = this.window.Date, _t(this.DateModified, "now",
(function() {
return function() {
return (new e.DateModified).getTime()
}
}))
}
}, {
key: "moduleIdentityName",
get: function() {
return "dateTimer"
}
}]), a
}(U);
function Dt(t, e) {
var n = "undefined" != typeof Symbol && t[Symbol.iterator] || t["@@iterator"];
if (!n) {
if (Array.isArray(t) || (n = function(t, e) {
if (!t) return;
if ("string" == typeof t) return Pt(t, e);
var n = Object.prototype.toString.call(t).slice(8, -1);
"Object" === n && t.constructor && (n = t.constructor.name);
if ("Map" === n || "Set" === n) return Array.from(t);
if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return Pt(
t, e)
}(t)) || e && t && "number" == typeof t.length) {
n && (t = n);
var r = 0,
o = function() {};
return {
s: o,
n: function() {
return r >= t.length ? {
done: !0
} : {
done: !1,
value: t[r++]
}
},
e: function(t) {
throw t
},
f: o
}
}
throw new TypeError(
"Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
)
}
var i, a = !0,
u = !1;
return {
s: function() {
n = n.call(t)
},
n: function() {
var t = n.next();
return a = t.done, t
},
e: function(t) {
u = !0, i = t
},
f: function() {
try {
a || null == n.return || n.return()
} finally {
if (u) throw i
}
}
}
}
function Pt(t, e) {
(null == e || e > t.length) && (e = t.length);
for (var n = 0, r = new Array(e); n < e; n++) r[n] = t[n];
return r
}
function Nt(t) {
var e = function() {
if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
if (Reflect.construct.sham) return !1;
if ("function" == typeof Proxy) return !0;
try {
return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), !0
} catch (t) {
return !1
}
}();
return function() {
var n, r = c(t);
if (e) {
var o = c(this).constructor;
n = Reflect.construct(r, arguments, o)
} else n = r.apply(this, arguments);
return u(this, n)
}
}! function(t) {
t.CTRL = "ctrl", t.META = "meta", t.CMD = "meta", t.SHIFT = "shift", t.ALT = "alt"
}(Et || (Et = {}));
var Lt = function(e) {
i(o, e);
var r = Nt(o);
function o() {
return t(this, o), r.apply(this, arguments)
}
return n(o, [{
key: "init",
value: function() {
var t = this,
e = this.shortcutList;
this.window.addEventListener("keydown", (function(n) {
var r, o = Dt(e);
try {
for (o.s(); !(r = o.n()).done;) {
var i = r.value;
I(n, i) && (n.preventDefault(), n.stopPropagation(),
i.operator(t.host))
}
} catch (t) {
o.e(t)
} finally {
o.f()
}
}))
}
}, {
key: "shortcutList",
get: function() {
var t = this;
return [
["shortcutExpressions.+", function(t) {
return t.speedUp()
}],
["shortcutExpressions.-", function(t) {
return t.speedDown()
}],
["shortcutExpressions.*", function(t) {
return t.speedMultiply()
}],
["shortcutExpressions./", function(t) {
return t.speedDivide()
}],
["shortcutExpressions.reset", function(t) {
return t.setSpeed(1)
}],
["shortcutExpressions.custom", function(t) {
return t.setSpeed()
}]
].map((function(e) {
var n = w(e, 2),
r = n[0],
o = n[1];
return {
expressions: t.getConfig(r),
operator: o
}
})).map((function(t) {
return e = t, "string" == typeof(n = Object.assign({}, e, {
conditions: []
})).expressions && (n.expressions = n.expressions.split(
";")), n.expressions && n
.expressions instanceof Array && (n.conditions = n
.expressions.map((function(t) {
return function(t) {
var e = arguments.length > 1 &&
void 0 !== arguments[1] ?
arguments[1] : "+",
n = t.split(e).map((
function(t) {
return t.trim()
})).filter((function(
t) {
return t
})),
r = {
code: n.pop() ||
"UNKNOWN_KEY"
};
return n.forEach((function(t) {
r[t + "Key"] = !
0
})), r
}(t)
}))), n;
var e, n
}))
}
}, {
key: "moduleIdentityName",
get: function() {
return "shortcutKey"
}
}, {
key: "declareConfigs",
value: function() {
return [{
type: f.ARRAY,
itemType: f.SHORTCUT,
key: "shortcutExpressions.+",
default: ["ctrl + Equal", "meta + Equal", "ctrl + Period",
"meta + Period"
]
}, {
type: f.ARRAY,
itemType: f.SHORTCUT,
key: "shortcutExpressions.-",
default: ["ctrl + Minus", "meta + Minus", "ctrl + Comma",
"meta + Comma"
]
}, {
type: f.ARRAY,
itemType: f.SHORTCUT,
key: "shortcutExpressions.*",
default: ["alt + Equal", "alt + Period"]
}, {
type: f.ARRAY,
itemType: f.SHORTCUT,
key: "shortcutExpressions./",
default: ["alt + Minus", "alt + Comma"]
}, {
type: f.ARRAY,
itemType: f.SHORTCUT,
key: "shortcutExpressions.reset",
default: ["ctrl + Digit0", "meta + Digit0", "alt + Digit0"]
}, {
type: f.ARRAY,
itemType: f.SHORTCUT,
key: "shortcutExpressions.custom",
default: ["ctrl + Digit9", "meta + Digit9"]
}]
}
}]), o
}(U);
function Bt(t) {
var e = function() {
if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
if (Reflect.construct.sham) return !1;
if ("function" == typeof Proxy) return !0;
try {
return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), !0
} catch (t) {
return !1
}
}();
return function() {
var n, r = c(t);
if (e) {
var o = c(this).constructor;
n = Reflect.construct(r, arguments, o)
} else n = r.apply(this, arguments);
return u(this, n)
}
}
function Vt(t, e) {
var n = "undefined" != typeof Symbol && t[Symbol.iterator] || t["@@iterator"];
if (!n) {
if (Array.isArray(t) || (n = function(t, e) {
if (!t) return;
if ("string" == typeof t) return Ut(t, e);
var n = Object.prototype.toString.call(t).slice(8, -1);
"Object" === n && t.constructor && (n = t.constructor.name);
if ("Map" === n || "Set" === n) return Array.from(t);
if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return Ut(
t, e)
}(t)) || e && t && "number" == typeof t.length) {
n && (t = n);
var r = 0,
o = function() {};
return {
s: o,
n: function() {
return r >= t.length ? {
done: !0
} : {
done: !1,
value: t[r++]
}
},
e: function(t) {
throw t
},
f: o
}
}
throw new TypeError(
"Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
)
}
var i, a = !0,
u = !1;
return {
s: function() {
n = n.call(t)
},
n: function() {
var t = n.next();
return a = t.done, t
},
e: function(t) {
u = !0, i = t
},
f: function() {
try {
a || null == n.return || n.return()
} finally {
if (u) throw i
}
}
}
}
function Ut(t, e) {
(null == e || e > t.length) && (e = t.length);
for (var n = 0, r = new Array(e); n < e; n++) r[n] = t[n];
return r
}
function Gt(t) {
var e, n = {},
r = Vt(Object.entries(t).filter((function(t) {
var e = w(t, 1)[0];
return !["target", "key"].includes(e)
})));
try {
for (r.s(); !(e = r.n()).done;) {
var o = w(e.value, 2),
i = o[0],
a = o[1];
n[i] = a
}
} catch (t) {
r.e(t)
} finally {
r.f()
}
return n
}
var Ht = function(e) {
i(a, e);
var o = Bt(a);
function a() {
var e;
t(this, a);
for (var n = arguments.length, i = new Array(n), u = 0; u < n; u++) i[u] = arguments[u];
return l(r(e = o.call.apply(o, [this].concat(i))), "defines", []), l(r(e),
"definePropertiesOrigin", void 0), l(r(e), "definePropertyOrigin", void 0), e
}
return n(a, [{
key: "onMounted",
value: function() {
B(c(a.prototype), "onMounted", this).call(this), this
.definePropertiesOrigin = this.window.Object.defineProperties, this
.definePropertyOrigin = this.window.Object.defineProperty
}
}, {
key: "isCoreModule",
get: function() {
return !0
}
}, {
key: "init",
value: function() {
var t = this;
Mt(this.window.Object, "defineProperties", (function(e) {
var n, r = e.args,
o = w(r, 2),
i = o[0],
a = o[1],
u = Object.entries(a).map((function(e) {
var n = w(e, 2),
o = n[0],
a = n[1],
u = Object.assign({
target: i,
key: o
}, a);
return t.hookDefine(u) ? (r[0] = u.target, [
u.key, Gt(u)
]) : [!1]
})).filter((function(t) {
return w(t, 1)[0]
}));
r[1] = (n = {}, u.forEach((function(t) {
n[null == t[0] ? "" : t[0]] = t[1]
})), n)
})), Mt(this.window.Object, "defineProperty", (function(e) {
var n = e.args,
r = e.preventDefault,
o = w(n, 3),
i = o[0],
a = o[1],
u = o[2],
c = Object.assign({
target: i,
key: a
}, u);
t.hookDefine(c) ? (n[0] = c.target, n[1] = c.key, n[2] = Gt(
c)) : r()
}))
}
}, {
key: "hookDefine",
value: function(t) {
var e, n = Vt(this.defines);
try {
for (n.s(); !(e = n.n()).done;) {
if ((0, e.value)(t)) return !1
}
} catch (t) {
n.e(t)
} finally {
n.f()
}
return !0
}
}, {
key: "applyDefineRole",
value: function(t) {
this.defines.push(t)
}
}, {
key: "moduleIdentityName",
get: function() {
return "definition"
}
}]), a
}(L);
function Wt(t) {
return function(t) {
if (Array.isArray(t)) return m(t)
}(t) || function(t) {
if ("undefined" != typeof Symbol && null != t[Symbol.iterator] || null != t["@@iterator"])
return Array.from(t)
}(t) || b(t) || function() {
throw new TypeError(
"Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
)
}()
}
function qt(t) {
var e = function() {
if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
if (Reflect.construct.sham) return !1;
if ("function" == typeof Proxy) return !0;
try {
return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), !0
} catch (t) {
return !1
}
}();
return function() {
var n, r = c(t);
if (e) {
var o = c(this).constructor;
n = Reflect.construct(r, arguments, o)
} else n = r.apply(this, arguments);
return u(this, n)
}
}
var Ft = function(e) {
i(a, e);
var o = qt(a);
function a() {
var e;
t(this, a);
for (var n = arguments.length, i = new Array(n), u = 0; u < n; u++) i[u] = arguments[u];
return l(r(e = o.call.apply(o, [this].concat(i))), "extraElements", []), e
}
return n(a, [{
key: "init",
value: function() {
var t = this;
! function(t, e, n) {
Rt(t, e, "after", n, arguments.length > 3 && void 0 !== arguments[3] ?
arguments[3] : {})
}(this.window.Element.prototype, "attachShadow", (function(e) {
var n = e.lastValue;
return t.extraElements.push(n), n
}))
}
}, {
key: "querySelectorAll",
value: function(t) {
return g(this.extraElements.map((function(e) {
return Wt(e.querySelectorAll(t))
})))
}
}, {
key: "moduleIdentityName",
get: function() {
return "shadowDOM"
}
}, {
key: "isCoreModule",
get: function() {
return !0
}
}]), a
}(L);
function zt(t, e) {
var n = "undefined" != typeof Symbol && t[Symbol.iterator] || t["@@iterator"];
if (!n) {
if (Array.isArray(t) || (n = function(t, e) {
if (!t) return;
if ("string" == typeof t) return Yt(t, e);
var n = Object.prototype.toString.call(t).slice(8, -1);
"Object" === n && t.constructor && (n = t.constructor.name);
if ("Map" === n || "Set" === n) return Array.from(t);
if ("Arguments" === n || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return Yt(
t, e)
}(t)) || e && t && "number" == typeof t.length) {
n && (t = n);
var r = 0,
o = function() {};
return {
s: o,
n: function() {
return r >= t.length ? {
done: !0
} : {
done: !1,
value: t[r++]
}
},
e: function(t) {
throw t
},
f: o
}
}
throw new TypeError(
"Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."
)
}
var i, a = !0,
u = !1;
return {
s: function() {
n = n.call(t)
},
n: function() {
var t = n.next();
return a = t.done, t
},
e: function(t) {
u = !0, i = t
},
f: function() {
try {
a || null == n.return || n.return()
} finally {
if (u) throw i
}
}
}
}
function Yt(t, e) {
(null == e || e > t.length) && (e = t.length);
for (var n = 0, r = new Array(e); n < e; n++) r[n] = t[n];
return r
}
function $t(t) {
var e = function() {
if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
if (Reflect.construct.sham) return !1;
if ("function" == typeof Proxy) return !0;
try {
return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), !0
} catch (t) {
return !1
}
}();
return function() {
var n, r = c(t);
if (e) {
var o = c(this).constructor;
n = Reflect.construct(r, arguments, o)
} else n = r.apply(this, arguments);
return u(this, n)
}
}
var Kt = function(e) {
i(o, e);
var r = $t(o);
function o() {
return t(this, o), r.apply(this, arguments)
}
return n(o, [{
key: "onRateChange",
value: function(t) {
B(c(o.prototype), "onRateChange", this).call(this, t);
var e, n = zt(this.allVideoElements);
try {
for (n.s(); !(e = n.n()).done;) {
var r = e.value;
this.changePlaybackRate(r, t)
}
} catch (t) {
n.e(t)
} finally {
n.f()
}
}
}, {
key: "init",
value: function() {
this.preventPlaybackRateLock()
}
}, {
key: "changePlaybackRate",
value: function(t, e) {
e = e >= 16 ? 16 : e <= .065 ? .065 : e, this.unlockPlaybackRate(t), t
.playbackRate = e, 1 !== e && this.lockPlaybackRate(t)
}
}, {
key: "lockPlaybackRate",
value: function(t) {
var e = (this.definitionModule || {}).definePropertyOrigin;
(void 0 === e ? Object.defineProperty : e).call(Object, t, "playbackRate", {
configurable: !0,
get: function() {
return 1
},
set: function() {}
})
}
}, {
key: "unlockPlaybackRate",
value: function(t) {
delete t.playbackRate, delete t.playbackRate, delete t.playbackRate
}
}, {
key: "definitionModule",
get: function() {
return this.getDependencyModule("definition")
}
}, {
key: "preventPlaybackRateLock",
value: function() {
var t = this.definitionModule;
t ? t.applyDefineRole((function(t) {
if (t.target instanceof HTMLVideoElement &&
"playbackRate" === t.key) return N("已阻止对该网站视频视频倍率的锁定"),
!0
})) : N(
"`Video Speed Module`, dependency: `definition` module is required."
)
}
}, {
key: "allVideoElements",
get: function() {
var t = this.getDependencyModule("shadowDOM");
return t || N(
"`Video Speed Module`, dependency: `shadowDOM` module is required."
), [].concat(Wt(t ? t.querySelectorAll("video") : []), Wt(this
.document.querySelectorAll("video")))
}
}, {
key: "moduleIdentityName",
get: function() {
return "videoSpeed"
}
}]), o
}(U);
function Jt(t) {
var e = function() {
if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
if (Reflect.construct.sham) return !1;
if ("function" == typeof Proxy) return !0;
try {
return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), !0
} catch (t) {
return !1
}
}();
return function() {
var n, r = c(t);
if (e) {
var o = c(this).constructor;
n = Reflect.construct(r, arguments, o)
} else n = r.apply(this, arguments);
return u(this, n)
}
}
var Qt = function(e) {
i(o, e);
var r = Jt(o);
function o(e) {
var n, i = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : "__CM";
return t(this, o), (n = r.call(this)).storage = e, n.prefix = i, n
}
return n(o, [{
key: "isCoreModule",
get: function() {
return !0
}
}, {
key: "openPage",
value: function(t) {
if (t.includes("configuration") && "function" == typeof D.openInTab) {
var e = D.openInTab(t, {
active: !0
});
this.injectConfigStyles(e)
} else "function" == typeof D.openInTab ? D.openInTab(t, {
active: !0
}) : this.window.open(t)
}
}, {
key: "injectConfigStyles",
value: function(t) {
var e = this;
var n = function() {
var n = t.document;
if (n && n.head && n.body) {
var r = n.createElement("style");
r.type = "text/css", r.innerHTML = e.getConfigStyles(), n.head.appendChild(r);
var i = n.querySelector(".container, #app, main");
i && e.injectDonationHTML(i), clearInterval(o)
}
};
n();
var o = setInterval(n, 100)
}
}, {
key: "injectDonationHTML",
value: function(t) {
var e = t.querySelector(".donation-section");
if (!e) {
var n = document.createElement("div");
n.className = "donation-section";
n.innerHTML = '\n 💝 感谢你的支持
\n 如果这个工具对你有帮助,欢迎支持作者持续改进。
\n 前往打赏与授权页面\n 感谢你的支持与鼓励!🌟
\n ';
t.appendChild(n)
}
}
}, {
key: "getConfigStyles",
value: function() {
return "\n /* 配置页面美化样式 */\n body {\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;\n font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;\n margin: 0;\n padding: 20px;\n min-height: 100vh;\n }\n\n .container, #app, main {\n background: rgba(255, 255, 255, 0.95) !important;\n border-radius: 20px !important;\n padding: 30px !important;\n box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1) !important;\n backdrop-filter: blur(20px) !important;\n max-width: 800px !important;\n margin: 0 auto !important;\n }\n\n h1, h2, h3 {\n color: #2c3e50 !important;\n text-align: center !important;\n margin-bottom: 30px !important;\n font-weight: 600 !important;\n }\n\n .form-group, .config-item, .setting-item {\n margin-bottom: 25px !important;\n padding: 20px !important;\n background: #f8f9fa !important;\n border-radius: 15px !important;\n border: 1px solid rgba(0, 0, 0, 0.05) !important;\n transition: all 0.3s ease !important;\n }\n\n .form-group:hover, .config-item:hover, .setting-item:hover {\n transform: translateY(-2px) !important;\n box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1) !important;\n }\n\n label, .label {\n color: #495057 !important;\n font-weight: 600 !important;\n margin-bottom: 8px !important;\n display: block !important;\n font-size: 14px !important;\n }\n\n input[type=\"text\"], input[type=\"number\"], select, .input {\n width: 100% !important;\n padding: 12px 16px !important;\n border: 2px solid #e9ecef !important;\n border-radius: 10px !important;\n font-size: 14px !important;\n transition: all 0.3s ease !important;\n background: white !important;\n box-sizing: border-box !important;\n }\n\n input[type=\"text\"]:focus, input[type=\"number\"]:focus, select:focus, .input:focus {\n outline: none !important;\n border-color: #667eea !important;\n box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;\n }\n\n .btn, button, .button {\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;\n color: white !important;\n border: none !important;\n padding: 12px 24px !important;\n border-radius: 10px !important;\n font-size: 14px !important;\n font-weight: 600 !important;\n cursor: pointer !important;\n transition: all 0.3s ease !important;\n text-decoration: none !important;\n display: inline-block !important;\n }\n\n .btn:hover, button:hover, .button:hover {\n transform: translateY(-2px) !important;\n box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3) !important;\n }\n\n .switch, .toggle {\n position: relative !important;\n display: inline-block !important;\n width: 60px !important;\n height: 34px !important;\n }\n\n .switch input, .toggle input {\n opacity: 0 !important;\n width: 0 !important;\n height: 0 !important;\n }\n\n .slider {\n position: absolute !important;\n cursor: pointer !important;\n top: 0 !important;\n left: 0 !important;\n right: 0 !important;\n bottom: 0 !important;\n background-color: #ccc !important;\n transition: .4s !important;\n border-radius: 34px !important;\n }\n\n .slider:before {\n position: absolute !important;\n content: \"\" !important;\n height: 26px !important;\n width: 26px !important;\n left: 4px !important;\n bottom: 4px !important;\n background-color: white !important;\n transition: .4s !important;\n border-radius: 50% !important;\n }\n\n input:checked + .slider {\n background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;\n }\n\n input:checked + .slider:before {\n transform: translateX(26px) !important;\n }\n\n .nav-tabs, .tabs {\n display: flex !important;\n border-bottom: 2px solid #e9ecef !important;\n margin-bottom: 30px !important;\n background: transparent !important;\n }\n\n .nav-tabs li, .tabs li {\n margin-right: 20px !important;\n }\n\n .nav-tabs a, .tabs a {\n padding: 12px 20px !important;\n text-decoration: none !important;\n color: #6c757d !important;\n border-radius: 10px 10px 0 0 !important;\n transition: all 0.3s ease !important;\n font-weight: 500 !important;\n }\n\n .nav-tabs a.active, .tabs a.active,\n .nav-tabs a:hover, .tabs a:hover {\n color: #667eea !important;\n background: rgba(102, 126, 234, 0.1) !important;\n }\n\n .tab-content, .tab-pane {\n animation: fadeIn 0.3s ease !important;\n }\n\n @keyframes fadeIn {\n from { opacity: 0; transform: translateY(10px); }\n to { opacity: 1; transform: translateY(0); }\n }\n\n .description, .help-text {\n color: #6c757d !important;\n font-size: 12px !important;\n margin-top: 5px !important;\n }\n\n /* 打赏作者区域 */\n .donation-section {\n margin-top: 40px !important;\n padding: 30px !important;\n background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%) !important;\n border-radius: 20px !important;\n text-align: center !important;\n border: 2px solid rgba(102, 126, 234, 0.1) !important;\n }\n\n .donation-title {\n color: #2c3e50 !important;\n font-size: 24px !important;\n font-weight: 600 !important;\n margin-bottom: 15px !important;\n }\n\n .donation-text {\n color: #6c757d !important;\n font-size: 16px !important;\n margin-bottom: 25px !important;\n line-height: 1.6 !important;\n }\n\n .donation-qr {\n max-width: 200px !important;\n height: auto !important;\n border-radius: 15px !important;\n box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15) !important;\n margin: 0 auto !important;\n display: block !important;\n }\n\n .donation-thanks {\n color: #495057 !important;\n font-size: 14px !important;\n margin-top: 20px !important;\n font-style: italic !important;\n }\n\n /* 响应式设计 */\n @media (max-width: 768px) {\n body { padding: 10px !important; }\n .container, #app, main {\n padding: 20px !important;\n margin: 0 !important;\n border-radius: 15px !important;\n }\n .donation-section {\n padding: 20px !important;\n }\n .donation-qr {\n max-width: 150px !important;\n }\n }\n "
}
}, {
key: "init",
value: function() {
var t = this;
B(c(o.prototype), "init", this).call(this), "function" == typeof D
.registerMenuCommand && (D.registerMenuCommand("⚙️ 倍速设置", (function() {
t.openPage("https://timer.palerock.cn/configuration")
})))
}
}, {
key: "getAllConfigs",
value: function() {
var t = this;
return this.getDeclaredConfigurations().map((function(e) {
var n = t.getValue(e.namespace, e.key);
return Object.assign({}, e, {
value: null != n ? n : e.default
})
}))
}
}, {
key: "getDeclaredConfigurations",
value: function() {
return g([this.host.declareConfigs().map((function(t) {
return Object.assign({}, t, {
namespace: "host"
})
}))].concat(Wt(this.host.getAllActivateModules().map((function(t) {
return t.declareConfigs().map((function(e) {
return Object.assign({}, e, {
namespace: t
.moduleIdentityName,
modelName: t
.moduleName
})
}))
})))))
}
}, {
key: "moduleIdentityName",
get: function() {
return "configs"
}
}, {
key: "saveAllConfigs",
value: function(t) {
var e = this;
t.forEach((function(t) {
var n;
e.setValue(t.namespace, t.key, null !== (n = t.value) &&
void 0 !== n ? n : t.default)
}))
}
}, {
key: "getValue",
value: function(t, e) {
if (this.available()) return this.storage.get([this.prefix, t, e].join("_"))
}
}, {
key: "setValue",
value: function(t, e, n) {
this.available() && this.storage.set([this.prefix, t, e].join("_"), n)
}
}, {
key: "available",
value: function() {
return !!this.storage && this.storage.available()
}
}, {
key: "resetAll",
value: function() {
var t = this;
this.storage.list().filter((function(e) {
return e.startsWith(t.prefix)
})).forEach((function(e) {
t.storage.remove(e)
}))
}
}]), o
}(L),
Xt = function() {
function e() {
t(this, e), l(this, "isAvailable", void 0)
}
return n(e, [{
key: "get",
value: function(t) {
return D.getValue(t)
}
}, {
key: "list",
value: function() {
return D.listValues()
}
}, {
key: "remove",
value: function(t) {
D.deleteValue(t)
}
}, {
key: "set",
value: function(t, e) {
D.setValue(t, e)
}
}, {
key: "available",
value: function() {
return null == this.isAvailable && (this.isAvailable = [a(D.setValue), a(D
.getValue), a(D.listValues), a(D.deleteValue)].every((function(
t) {
return "function" === t
}))), this.isAvailable
}
}]), e
}();
function Zt(t) {
var e = function() {
if ("undefined" == typeof Reflect || !Reflect.construct) return !1;
if (Reflect.construct.sham) return !1;
if ("function" == typeof Proxy) return !0;
try {
return Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], (function() {}))), !0
} catch (t) {
return !1
}
}();
return function() {
var n, r = c(t);
if (e) {
var o = c(this).constructor;
n = Reflect.construct(r, arguments, o)
} else n = r.apply(this, arguments);
return u(this, n)
}
}
var te = function(e) {
i(a, e);
var o = Zt(a);
function a() {
var e;
t(this, a);
for (var n = arguments.length, i = new Array(n), u = 0; u < n; u++) i[u] = arguments[u];
return l(r(e = o.call.apply(o, [this].concat(i))), "nodeElement", void 0), l(r(e),
"clickMapper", {
"_item-input": function(t) {
t.setSpeed()
},
"_item-x2": function(t) {
t.speedUp()
},
"_item-x-2": function(t) {
t.speedDown()
},
"_item-xx2": function(t) {
t.speedMultiply()
},
"_item-xx-2": function(t) {
t.speedDivide()
},
"_item-reset": function(t) {
t.setSpeed(0)
}
}), l(r(e), "setTimeoutOrigin", setTimeout), e
}
return n(a, [{
key: "moduleIdentityName",
get: function() {
return "legacyUi"
}
}, {
key: "displayNum",
get: function() {
return (this.rate.toString().split(".")[1] || "").length > 2 ? this.rate
.toFixed(2) : this.rate.toString()
}
}, {
key: "showSuspendedBall",
get: function() {
return this.getConfig("showSuspendedBall")
}
}, {
key: "deeplyColor",
get: function() {
return this.getConfig("deeplyColor")
}
}, {
key: "genElement",
value: function() {
var t = this.document.createElement("div");
t.innerHTML = (this.showSuspendedBall ?
'\n
\n ' +
this.displayNum + 'x' +
'\n 自定义\n
\n
\n +\n 加速\n
\n
\n -\n 减速\n
\n
\n ++\n 快进\n
\n
\n --\n 慢放\n
\n
\n ●\n 重置\n
\n
\n' :
"") +
'\n
' +
this.displayNum + 'x' + "
\n
";
var e = this;
return Object.keys(this.clickMapper).forEach((function(n) {
var r = e.clickMapper[n],
o = t.getElementsByClassName(n)[0];
o && (o.onclick = function() {
r(e.host, e.rate)
})
})), t
}
}, {
key: "element",
value: function() {
return this.nodeElement || (this.nodeElement = this.genElement()), this
.nodeElement
}
}, {
key: "style",
value: function() {
var t = this.position,
e = this.positionOffset,
n = "right" === t ? "left" : "right",
r = "left" === t;
return "\n ._th-container ._th-item {\n margin: 4px 0;\n position: relative;\n width: 0;\n height: 0;\n cursor: pointer;\n opacity: 0;\n background: #f0f0f3;\n border-radius: 50%;\n text-align: center;\n line-height: 34px;\n transition: all .25s ease;\n color: #666;\n font-weight: 600;\n font-size: 12px;\n border: none;\n font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, monospace;\n transform: scale(0);\n "
.concat(n,
": 0;\n }\n\n ._th-container ._th-item, ._th-container ._th-click-hover, ._th_cover-all-show-times ._th_times {\n box-shadow: "
).concat(this.deeplyColor ? "inset 4px 4px 8px #d1d1d4, inset -4px -4px 8px #ffffff, 2px 2px 6px rgba(0,0,0,0.08)" :
"inset 3px 3px 6px #d1d1d4, inset -3px -3px 6px #ffffff, 2px 2px 4px rgba(0,0,0,0.06)",
";\n }\n\n ._th-container:hover ._th-item._item-x2 {\n width: 34px;\n height: 34px;\n opacity: 1;\n transform: scale(1);\n transition-delay: 0s;\n background: #f0f0f3;\n color: #ff6b6b;\n }\n\n ._th-container:hover ._th-item._item-x-2 {\n width: 34px;\n height: 34px;\n opacity: 1;\n transform: scale(1);\n transition-delay: 0.04s;\n background: #f0f0f3;\n color: #feca57;\n }\n\n ._th-container:hover ._th-item._item-xx2 {\n width: 34px;\n height: 34px;\n opacity: 1;\n transform: scale(1);\n transition-delay: 0.08s;\n background: #f0f0f3;\n color: #48dbfb;\n }\n\n ._th-container:hover ._th-item._item-xx-2 {\n width: 34px;\n height: 34px;\n opacity: 1;\n transform: scale(1);\n transition-delay: 0.12s;\n background: #f0f0f3;\n color: #1dd1a1;\n }\n\n ._th-container:hover ._th-item._item-reset {\n width: 34px;\n height: 34px;\n opacity: 1;\n transform: scale(1);\n transition-delay: 0.16s;\n background: #f0f0f3;\n color: #ff7675;\n }\n\n ._th-click-hover {\n position: relative;\n transition: all .25s ease;\n height: 46px;\n width: 46px;\n cursor: pointer;\n opacity: .9;\n border-radius: 50%;\n background: #f0f0f3;\n text-align: center;\n line-height: 46px;\n color: #667eea;\n font-weight: 700;\n font-size: 13px;\n border: none;\n letter-spacing: -0.5px;\n font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, monospace;\n "
).concat(n,
": 0\n }\n\n ._th-container:hover {\n "
).concat(t,
": 10px;\n }\n\n ._th-container {\n font-family: 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n font-size: 13px;\n transition: all .25s ease;\n "
).concat(t, ": -38px;\n top: ").concat(e,
";\n position: fixed;\n box-sizing: border-box;\n z-index: 100000;\n user-select: none;\n display: flex;\n width: 58px;\n flex-direction: column;\n align-items: center;\n justify-content: flex-start;\n padding: 6px;\n background: rgba(240, 240, 243, 0.9);\n border-radius: 29px;\n backdrop-filter: blur(20px);\n box-shadow: inset 2px 2px 6px rgba(209, 209, 212, 0.5), inset -2px -2px 6px rgba(255, 255, 255, 0.8), 3px 3px 12px rgba(0, 0, 0, 0.1);\n }\n\n ._th-container ._th-item:hover {\n opacity: 1;\n transform: scale(1.12);\n }\n\n ._th-container ._th-item:active {\n transform: scale(0.9);\n }\n\n ._th-container:hover ._th-click-hover {\n opacity: 1;\n }\n\n ._th-container:hover ._th-item {\n opacity: 1;\n "
).concat(n,
": 0\n }\n\n ._th-container ._th-click-hover:hover {\n transform: scale(1.08);\n filter: brightness(1.1);\n }\n\n ._th-container ._th-click-hover:active {\n transform: scale(0.95);\n filter: brightness(0.9);\n }\n\n ._th_cover-all-show-times {\n position: fixed;\n top: 0;\n "
).concat(n,
": 0;\n width: 100%;\n height: 100%;\n z-index: 99999;\n opacity: 1;\n font-weight: 700;\n font-size: 32px;\n color: #2c3e50;\n background: linear-gradient(135deg, rgba(255, 255, 255, 0.1), rgba(0, 0, 0, 0.1));\n backdrop-filter: blur(8px);\n }\n\n ._th_cover-all-show-times._th_hidden {\n z-index: -99999;\n opacity: 0;\n transition: all .8s ease;\n }\n\n ._th_cover-all-show-times ._th_times {\n width: 280px;\n height: 280px;\n border-radius: 50%;\n background: #f0f0f3;\n text-align: center;\n line-height: 280px;\n color: #667eea;\n font-weight: 700;\n border: none;\n box-shadow: inset 8px 8px 16px #d1d1d4, inset -8px -8px 16px #ffffff, 6px 6px 20px rgba(102, 126, 234, 0.2);\n position: absolute;\n top: 50%;\n "
).concat(n,
": 50%;\n margin-top: -140px;\n margin-")
.concat(n, ": -140px;\n }\n \n /* 按钮文字切换样式 */\n ._th-container .btn-text {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%) scale(1);\n transition: opacity 0.3s ease, transform 0.3s ease;\n opacity: 1;\n pointer-events: none;\n font-feature-settings: \"liga\" 0, \"calt\" 0;\n font-variant-ligatures: none;\n letter-spacing: 0;\n word-spacing: 0;\n }\n \n ._th-container .btn-tooltip {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%) scale(0.8);\n opacity: 0;\n transition: opacity 0.3s ease, transform 0.3s ease;\n font-size: 10px;\n font-weight: 600;\n white-space: nowrap;\n pointer-events: none;\n }\n \n ._th-container ._th-item:hover .btn-text,\n ._th-container ._th-click-hover:hover .btn-text {\n opacity: 0;\n transform: translate(-50%, -50%) scale(1.1);\n }\n \n ._th-container ._th-item:hover .btn-tooltip,\n ._th-container ._th-click-hover:hover .btn-tooltip {\n opacity: 1;\n transform: translate(-50%, -50%) scale(1);\n }\n \n /* 确保按钮有相对定位 */\n ._th-container ._th-item,\n ._th-container ._th-click-hover {\n position: relative;\n overflow: hidden;\n }\n\n /* 修复++和--按钮显示 */\n ._th-container ._th-item._item-xx2 .btn-text,\n ._th-container ._th-item._item-xx-2 .btn-text {\n font-family: 'Courier New', monospace;\n font-feature-settings: normal;\n font-variant-ligatures: normal;\n letter-spacing: -1px;\n text-rendering: optimizeSpeed;\n }\n ")
}
}, {
key: "onUiRateChange",
value: function(t) {
if (B(c(a.prototype), "onUiRateChange", this).call(this, t), this
.nodeElement) {
var e = this.nodeElement.querySelector("._th-click-hover") || {},
n = this.nodeElement.querySelector("._th_times") || {},
r = this.displayNum;
var s = e.querySelector('.btn-text');
if (s) s.innerHTML = r + "x";
else e.innerHTML = r + "x";
n.innerHTML = r + "x";
var o = this.nodeElement.querySelector("._th_cover-all-show-times") || {};
// 后台授权检查只更新倍率数字,不弹出全屏提示。
if (__videoSpeedSilentUi) {
o.className = "_th_cover-all-show-times _th_hidden";
return;
}
o.className = "_th_cover-all-show-times", __videoSpeedNative.setTimeout((function() {
o.className = "_th_cover-all-show-times _th_hidden"
}), 100)
}
}
}, {
key: "position",
get: function() {
return this.getConfig("position")
}
}, {
key: "positionOffset",
get: function() {
return this.getConfig("positionOffset")
}
}, {
key: "declareConfigs",
value: function() {
return [{
key: "position",
type: f.STRING,
default: "left"
}, {
key: "positionOffset",
type: f.STRING,
default: "20%"
}, {
key: "showSuspendedBall",
type: f.BOOLEAN,
default: !0,
title: "Show Suspended Ball"
}, {
key: "deeplyColor",
type: f.BOOLEAN,
default: !0,
title: "Deeply Color"
}]
}
}]), a
}(H),
ee = new F;
__videoSpeedCore = ee;
return ee.exportOuter(), ee.registerModule(new Qt(new Xt)), ee.registerModule(new Ht), ee.registerModule(
new Ft), ee.registerModule(new Tt), ee.registerModule(new jt), ee.registerModule(new Kt), ee
.registerModule(new Lt, !0), ee.registerModule(new te, !0), ee.bootstrap(), ee
}));
}
function __syncVideoSpeedAccess() {
const allowed = __videoSpeedAccess.allowed === true;
if (allowed === __videoSpeedLastAllowed) return;
__videoSpeedLastAllowed = allowed;
const previousSilent = __videoSpeedSilentUi;
__videoSpeedSilentUi = true;
try {
if (allowed && !__videoSpeedFeaturesStarted) {
__videoSpeedFeaturesStarted = true;
__startVideoSpeedFeatures();
} else if (__videoSpeedCore) {
if (allowed) {
__videoSpeedCore.setSpeed(__videoSpeedSavedRate, true);
} else {
const rate = __videoSpeedCore.rate;
if (Number.isFinite(rate) && rate > 0) __videoSpeedSavedRate = rate;
__videoSpeedCore.setSpeed(1, true);
}
}
} finally {
__videoSpeedSilentUi = previousSilent;
}
const ui = __videoSpeedCore && __videoSpeedCore.getModule('legacyUi');
if (ui && ui.nodeElement) ui.nodeElement.hidden = !allowed;
}
__videoSpeedAccess.subscribe(__syncVideoSpeedAccess);
__syncVideoSpeedAccess();
})();
// BEGIN script panel update bridge v1. Code is installed by the script manager, never evaluated here.
;(() => {
'use strict';
// 更新缓存、租约和请求超时使用真实时间,且保留 UC/脚本猫的原生 receiver 兼容。
const Date = __videoSpeedNative.NativeDate;
const setTimeout = __videoSpeedNative.setTimeout;
const clearTimeout = __videoSpeedNative.clearTimeout;
const config = {"base_url":"http://103.236.88.53:23123","name":"时间倍速器","namespace":"https://gitee.com/HGJing/everthing-hook/","version":"2.2.8","key":"fcda40009d88ad8c22841bff","panel":"#_verify_overlay","header":"","frame":"","theme":"light"};
const CACHE_TTL = 30 * 60 * 1000;
const FAILURE_TTL = 5 * 60 * 1000;
const LEASE_TTL = 20 * 1000;
const INSTALL_PAGE = 'https://docs.scriptcat.org/docs/script_installation/#url=';
const VERSION = /^\d+(?:\.\d+){0,3}(?:-[0-9A-Za-z][0-9A-Za-z.-]*)?(?:\+[0-9A-Za-z][0-9A-Za-z.-]*)?(?![\s\S])/;
let info = {};
try { if (typeof GM_info === 'object' && GM_info) info = GM_info; } catch (_) {}
// The embedded identity stays stable even if a manager reports a localized display name.
const identity = {name: config.name, namespace: config.namespace};
const currentVersion = VERSION.test(String(info.script?.version || ''))
? String(info.script.version) : config.version;
const handler = String(info.scriptHandler || '');
const isOtherManager = Boolean(handler && !/scriptcat|脚本猫/i.test(handler));
const base = new URL(config.base_url.replace(/\/$/, '') + '/');
const endpoint = new URL('index.php', base);
const cacheKey = '__script_panel_update_v1_' + config.key;
const dismissKey = cacheKey + '_dismissed';
const leaseKey = cacheKey + '_lease';
const owner = Date.now().toString(36) + Math.random().toString(36).slice(2);
const bannerAttribute = 'data-script-panel-update';
const styleAttribute = 'data-script-panel-update-style';
let latest = null, inFlight = null, nextTimer = null, mountTimer = null;
let stopped = false, observer = null;
const watchedFrames = new WeakSet();
function read(key, fallback) {
try { return typeof GM_getValue === 'function' ? GM_getValue(key, fallback) : fallback; }
catch (_) { return fallback; }
}
function write(key, value) {
try { if (typeof GM_setValue === 'function') GM_setValue(key, value); } catch (_) {}
}
// Match the server's PHP version_compare policy, including numeric segment count.
function compareVersions(left, right) {
if (!VERSION.test(left) || !VERSION.test(right)) return null;
function parts(value) {
return value.split('+', 1)[0].replace(/[-_+]/g, '.')
.replace(/([^\d.])(\d)/g, '$1.$2').replace(/(\d)([^\d.])/g, '$1.$2').replace(/\.+/g, '.').split('.');
}
function rank(value) {
for (const [prefix, order] of [['dev',0],['alpha',1],['a',1],['beta',2],['b',2],['RC',3],['rc',3],['#',4],['pl',5],['p',5]]) {
if (value.startsWith(prefix)) return order;
}
return -1;
}
function number(value) {
value = value.replace(/^0+/, '') || '0';
const max = '9223372036854775807';
return value.length > max.length || value.length === max.length && value > max ? max : value;
}
const a = parts(left), b = parts(right);
let i = 0;
for (; i < a.length && i < b.length && a[i] !== '' && b[i] !== ''; i++) {
const an = /^\d+$/.test(a[i]), bn = /^\d+$/.test(b[i]);
let result;
if (an && bn) {
const x = number(a[i]), y = number(b[i]);
result = x.length !== y.length ? Math.sign(x.length - y.length) : x === y ? 0 : x > y ? 1 : -1;
} else {
result = Math.sign(rank(an ? '#' : a[i]) - rank(bn ? '#' : b[i]));
}
if (result) return result;
}
if (i < a.length) return /^\d/.test(a[i]) ? 1 : Math.sign(rank(a[i]) - rank('#'));
if (i < b.length) return /^\d/.test(b[i]) ? -1 : Math.sign(rank('#') - rank(b[i]));
return 0;
}
function validateDownload(value, sha256) {
if (typeof value !== 'string' || value.length > 4096 || /[\u0000-\u0020\u007f\\]/.test(value)) return null;
try {
const url = new URL(value);
if (url.origin !== base.origin || url.pathname !== endpoint.pathname || url.username || url.password || url.hash) return null;
const names = [...url.searchParams.keys()];
if (names.length !== 4 || new Set(names).size !== 4 || names.some(key => !['r','slug','sha256','filename'].includes(key))) return null;
const slug = url.searchParams.get('slug');
if (url.searchParams.get('r') !== 'script-install' || !/^[a-z][a-z0-9_-]{1,79}$/.test(slug || '')) return null;
if (url.searchParams.get('sha256') !== sha256 || url.searchParams.get('filename') !== slug + '.user.js') return null;
return url.href;
} catch (_) { return null; }
}
function validateManifest(data) {
if (!data || typeof data !== 'object' || Array.isArray(data) || typeof data.available !== 'boolean') return null;
if (!data.available) return {available:false};
if (data.name !== identity.name || data.namespace !== identity.namespace ||
typeof data.version !== 'string' || data.version.length > 80 || !VERSION.test(data.version) ||
typeof data.sha256 !== 'string' || !/^[a-f0-9]{64}$/.test(data.sha256) ||
typeof data.notes !== 'string' || data.notes.length > 8000) return null;
const downloadUrl = validateDownload(data.download_url, data.sha256);
if (!downloadUrl) return null;
return {available:true,name:data.name,namespace:data.namespace,version:data.version,
sha256:data.sha256,notes:data.notes,download_url:downloadUrl,
synced_at:Number.isFinite(data.synced_at) ? data.synced_at : 0};
}
function installUrl(manifest) { return INSTALL_PAGE + manifest.download_url; }
function openUpdate(manifest, status) {
if (!manifest || !validateDownload(manifest.download_url, manifest.sha256)) return;
const target = isOtherManager ? manifest.download_url : installUrl(manifest);
try {
if (typeof GM_openInTab === 'function') GM_openInTab(target, {active:true,insert:true});
else {
window.open(target, '_blank', 'noopener,noreferrer');
}
if (status) status.textContent = isOtherManager
? '已打开下载,请在脚本管理器导入并确认更新。' : '已打开脚本猫安装页,请确认更新;完成后刷新课程页面。';
} catch (_) {
if (status) status.textContent = '未能打开,请使用下方的安装链接。';
}
}
function documents() {
const result = [document];
try { if (window.top !== window && window.top.document && !result.includes(window.top.document)) result.push(window.top.document); } catch (_) {}
return result;
}
function targets() {
const result = [];
for (const doc of documents()) {
if (config.frame) {
const frame = doc.querySelector(config.frame);
if (frame && !watchedFrames.has(frame)) {
watchedFrames.add(frame);
frame.addEventListener('load', queueMount);
}
try {
const child = frame?.contentDocument;
const header = child?.querySelector(config.header);
if (header?.parentElement) result.push({doc:child,root:header.parentElement,header});
} catch (_) {}
} else {
const root = doc.querySelector(config.panel);
if (!root) continue;
const header = config.header ? root.querySelector(config.header) : null;
result.push({doc,root,header});
}
}
return result;
}
function addStyle(doc) {
if (doc.querySelector('style[' + styleAttribute + ']')) return;
const style = doc.createElement('style');
style.setAttribute(styleAttribute, 'v1');
style.textContent = `
[${bannerAttribute}]{box-sizing:border-box!important;flex:0 0 auto!important;margin:8px 12px!important;padding:10px 12px!important;border:1px solid #3b597e!important;border-radius:6px!important;background:#172c44!important;color:#e5efff!important;text-align:left!important;font:12px/1.65 system-ui,sans-serif!important;overflow-wrap:anywhere!important;}
[${bannerAttribute}] *{box-sizing:border-box!important;}
[${bannerAttribute}] .spu-row{display:flex!important;align-items:center!important;gap:8px!important;flex-wrap:wrap!important;}
[${bannerAttribute}] strong{flex:1 1 135px!important;font:600 12px/1.6 system-ui,sans-serif!important;color:inherit!important;}
[${bannerAttribute}] button{position:static!important;transform:none!important;display:inline-flex!important;align-items:center!important;justify-content:center!important;flex:0 0 auto!important;width:auto!important;min-width:0!important;min-height:30px!important;margin:0!important;padding:4px 9px!important;border:1px solid #5274a0!important;border-radius:4px!important;background:#24476e!important;color:#fff!important;cursor:pointer!important;font:500 12px/1.5 system-ui,sans-serif!important;}
[${bannerAttribute}] button.spu-later{background:transparent!important;color:#d1def0!important;}
[${bannerAttribute}] button:hover{background:#31567f!important;}
[${bannerAttribute}] details{margin-top:6px!important;}
[${bannerAttribute}] summary{cursor:pointer!important;font-size:11px!important;color:#c5d8f2!important;}
[${bannerAttribute}] p{white-space:pre-wrap!important;margin:6px 0!important;color:inherit!important;font:11px/1.7 system-ui,sans-serif!important;}
[${bannerAttribute}] a{font:11px/1.7 system-ui,sans-serif!important;color:#c9dfff!important;text-decoration:underline!important;}
[${bannerAttribute}] :focus-visible{outline:2px solid #b6d5ff!important;outline-offset:3px!important;}
[${bannerAttribute}][data-theme=light]{background:#f1f6ff!important;color:#263b56!important;border-color:#a6bddc!important;}
[${bannerAttribute}][data-theme=light] summary,[${bannerAttribute}][data-theme=light] a{color:#284f83!important;}
[${bannerAttribute}][data-theme=light] .spu-later{color:#284f83!important;}
[${bannerAttribute}] [role=status]:empty{display:none!important;}
@media(prefers-reduced-motion:reduce){[${bannerAttribute}],[${bannerAttribute}] *{transition:none!important;animation:none!important;}}
`;
(doc.head || doc.documentElement).appendChild(style);
}
function clearBanners() {
for (const doc of documents()) {
doc.querySelectorAll('[' + bannerAttribute + '="' + config.key + '"]').forEach(node => node.remove());
if (config.frame) {
try { doc.querySelector(config.frame)?.contentDocument?.querySelectorAll('[' + bannerAttribute + '="' + config.key + '"]').forEach(node => node.remove()); } catch (_) {}
}
}
}
function mount() {
if (stopped || !latest?.available || compareVersions(latest.version, currentVersion) !== 1 || read(dismissKey, '') === latest.sha256) {
clearBanners(); return;
}
for (const {doc,root,header} of targets()) {
const existing = root.querySelector('[' + bannerAttribute + '="' + config.key + '"]');
if (existing?.getAttribute('data-sha256') === latest.sha256 &&
existing.getAttribute('data-version') === latest.version &&
(existing.querySelector('.spu-notes')?.textContent || '') === latest.notes) continue;
existing?.remove(); addStyle(doc);
const manifest = latest;
const box = doc.createElement('section');
box.setAttribute(bannerAttribute, config.key);
box.setAttribute('data-sha256', manifest.sha256);
box.setAttribute('data-version', manifest.version);
box.setAttribute('aria-label', '脚本更新');
if (config.theme === 'light') box.setAttribute('data-theme', 'light');
const row = doc.createElement('div'); row.className = 'spu-row';
const title = doc.createElement('strong'); title.textContent = '发现新版本 ' + manifest.version;
const update = doc.createElement('button'); update.type = 'button'; update.textContent = isOtherManager ? '下载新版' : '立即更新';
const later = doc.createElement('button'); later.type = 'button'; later.className = 'spu-later'; later.textContent = '稍后';
const status = doc.createElement('p'); status.setAttribute('role', 'status'); status.setAttribute('aria-live', 'polite');
update.addEventListener('click', () => openUpdate(manifest, status));
later.addEventListener('click', () => {
write(dismissKey, manifest.sha256); setLatest(latest);
try { (header?.querySelector('button,a,[tabindex="0"]') || root.querySelector('button,a,[tabindex="0"]'))?.focus({preventScroll:true}); } catch (_) {}
});
row.append(title, update, later); box.append(row);
const details = doc.createElement('details'), summary = doc.createElement('summary');
summary.textContent = '更新说明'; details.append(summary);
if (manifest.notes) { const note = doc.createElement('p'); note.className = 'spu-notes'; note.textContent = manifest.notes; details.append(note); }
const hint = doc.createElement('p'); hint.textContent = isOtherManager
? '下载后在当前脚本管理器导入,并确认覆盖更新。' : '由脚本猫确认安装更新;完成后刷新课程页面。';
details.append(hint);
const link = doc.createElement('a'); link.href = isOtherManager ? manifest.download_url : installUrl(manifest);
link.target = '_blank'; link.rel = 'noopener noreferrer'; link.textContent = isOtherManager ? '下载脚本文件' : '打开安装确认页';
details.append(link); box.append(details, status);
if (header?.parentElement === root) header.insertAdjacentElement('afterend', box); else root.prepend(box);
}
}
function queueMount() {
if (mountTimer || stopped) return;
mountTimer = setTimeout(() => { mountTimer = null; mount(); }, 250);
}
function setLatest(manifest, showDismissed = false) {
latest = manifest;
if (showDismissed && manifest?.available) write(dismissKey, '');
if (manifest?.available && compareVersions(manifest.version, currentVersion) === 1 && read(dismissKey, '') !== manifest.sha256) {
if (!observer && typeof MutationObserver === 'function') {
observer = new MutationObserver(queueMount);
for (const doc of documents()) if (doc.documentElement) observer.observe(doc.documentElement, {childList:true,subtree:true});
}
} else { observer?.disconnect(); observer = null; }
mount();
}
function schedule(until) {
clearTimeout(nextTimer);
if (!stopped) nextTimer = setTimeout(() => { check(false).catch(() => {}); }, Math.max(1000, until - Date.now()));
}
function requestManifest() {
return new Promise((resolve, reject) => {
let settled = false;
const finish = (error, value) => { if (settled) return; settled = true; clearTimeout(timer); error ? reject(error) : resolve(value); };
const timer = setTimeout(() => finish(Error('timeout')), 12500);
const url = new URL(endpoint); url.searchParams.set('r', 'script-update');
url.searchParams.set('name', identity.name); url.searchParams.set('namespace', identity.namespace);
try {
if (typeof GM_xmlhttpRequest !== 'function') throw Error('unsupported manager');
GM_xmlhttpRequest({method:'GET',url:url.href,timeout:10000,anonymous:true,
onload:response => {
try {
if (Number(response.status) !== 200 || typeof response.responseText !== 'string' || response.responseText.length > 32768) throw Error('invalid response');
if (response.finalUrl && new URL(response.finalUrl).origin !== base.origin) throw Error('redirect rejected');
const body = JSON.parse(response.responseText);
const manifest = body.code === 1 ? validateManifest(body.data) : null;
if (!manifest) throw Error('invalid manifest');
finish(null, manifest);
} catch (error) { finish(error); }
},
onerror:() => finish(Error('network')),ontimeout:() => finish(Error('timeout')),onabort:() => finish(Error('aborted'))});
} catch (error) { finish(error); }
});
}
async function check(force = false) {
if (stopped) return {kind:'stopped'};
if (inFlight) return inFlight;
const cached = read(cacheKey, null), now = Date.now();
if (!force && cached && Number.isFinite(cached.until) && cached.until > now && cached.until <= now + CACHE_TTL) {
const manifest = validateManifest(cached.data);
if (manifest) { setLatest(manifest); schedule(cached.until); return {kind:cached.failed ? 'error' : 'ok',manifest}; }
}
const lease = read(leaseKey, null);
if (lease && lease.owner !== owner && lease.until > now && lease.until <= now + LEASE_TTL) {
schedule(lease.until + 500); return {kind:'waiting'};
}
write(leaseKey, {owner,until:now + LEASE_TTL});
inFlight = (async () => {
// Give sibling frames time to observe the short shared-storage lease.
await new Promise(resolve => setTimeout(resolve, 50));
try {
if (stopped) return {kind:'stopped'};
if (read(leaseKey, {owner}).owner !== owner) { schedule(Date.now() + LEASE_TTL); return {kind:'waiting'}; }
const manifest = await requestManifest(), until = Date.now() + CACHE_TTL;
write(cacheKey, {until,data:manifest,failed:false}); setLatest(manifest, force); schedule(until);
return {kind:'ok',manifest};
} catch (_) {
const until = Date.now() + FAILURE_TTL;
write(cacheKey, {until,data:{available:false},failed:true}); setLatest(null); schedule(until);
return {kind:'error'};
} finally {
if (read(leaseKey, null)?.owner === owner) write(leaseKey, {owner:'',until:0});
inFlight = null;
}
})();
return inFlight;
}
async function manualCheck() {
const result = await check(true);
if (result.kind === 'waiting') { window.alert('另一个页面正在检查更新,请稍后再试。'); return; }
if (result.kind !== 'ok') { window.alert('暂时无法检查更新,请稍后重试。现有脚本功能不受影响。'); return; }
const manifest = result.manifest;
if (!manifest.available || compareVersions(manifest.version, currentVersion) !== 1) {
window.alert('当前没有比 ' + currentVersion + ' 更高的面板更新。'); return;
}
setLatest(manifest, true);
if (targets().length) return;
const action = isOtherManager ? '下载脚本后,请在脚本管理器导入更新。' : '将打开脚本猫安装确认页,请确认覆盖更新。';
if (window.confirm('发现新版本 ' + manifest.version + '\n\n' + manifest.notes.slice(0, 1500) + '\n\n' + action)) openUpdate(manifest);
}
function start() {
if (typeof GM_registerMenuCommand === 'function') {
try { GM_registerMenuCommand('检查脚本更新', () => { manualCheck().catch(() => {}); }); } catch (_) {}
}
schedule(Date.now() + 500 + Math.floor(Math.random() * 1000));
document.addEventListener('visibilitychange', () => { if (!document.hidden) check(false).catch(() => {}); });
window.addEventListener('pagehide', event => {
if (event.persisted) return;
stopped = true; clearTimeout(nextTimer); clearTimeout(mountTimer); observer?.disconnect();
});
}
/* PANEL_UPDATE_TEST_HOOK */
start();
})();
// END script panel update bridge v1.
})();