// ==UserScript== // @name 视频面板 // @name:en Video Panel // @namespace https://video-panel.local // @version 1.1.0 // @description 页面内视频播放增强面板:0.1–16 倍无级变速、Shift 快捷键、画中画、截取画面、网页全屏、静音循环镜像、播放进度记忆、界面净化。只操作页面中已有的 HTML5 播放器,不改变视频来源。 // @author anonymous // @license MIT // @icon data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect width='64' height='64' rx='16' fill='%234ec9b8'/%3E%3Cpath d='M25 19l20 13-20 13z' fill='%2306201d'/%3E%3C/svg%3E // @match *://*.bilibili.com/* // @match *://*.iqiyi.com/* // @match *://v.qq.com/* // @match *://*.youku.com/* // @match *://*.youtube.com/* // @grant GM_getValue // @grant GM_setValue // @grant GM_registerMenuCommand // @run-at document-idle // @noframes // @charset UTF-8 // ==/UserScript== (function () { 'use strict'; var __YC_CSS__ = String.raw`/* ============================================================ 视频面板 · 视觉层 注入 Shadow DOM,与站点样式完全隔离 ============================================================ */ :host { all: initial; } *, *::before, *::after { box-sizing: border-box; } .yc-dock { position: fixed; left: 0; top: 0; width: var(--yc-w, 340px); transform: translate3d(var(--yc-x, 0px), var(--yc-y, 0px), 0); font-family: "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 13px; line-height: 1.45; color: #edf1f5; z-index: 2147483000; -webkit-font-smoothing: antialiased; contain: layout style; } .yc-dock.is-collapsed { width: auto; } /* ---------- 玻璃主体 ---------- */ .yc-panel { --fg: #edf1f5; --fg-2: rgba(237, 241, 245, 0.72); --fg-3: rgba(237, 241, 245, 0.46); --line: rgba(255, 255, 255, 0.13); --plate: rgba(255, 255, 255, 0.07); --plate-hi: rgba(255, 255, 255, 0.13); --accent: #4ec9b8; --ink: #06201d; --shadow: rgba(3, 6, 12, 0.6); position: relative; border-radius: 18px; overflow: hidden; isolation: isolate; color: var(--fg); background: linear-gradient(170deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.02) 40%, rgba(255, 255, 255, 0.05) 100%), rgba(14, 17, 23, 0.62); border: 1px solid rgba(255, 255, 255, 0.14); box-shadow: 0 18px 46px -16px var(--shadow), 0 1px 2px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.2); backdrop-filter: blur(28px) saturate(170%); -webkit-backdrop-filter: blur(28px) saturate(170%); animation: yc-in 200ms ease-out both; } .yc-panel[data-tone="light"] { --fg: #121821; --fg-2: rgba(18, 24, 33, 0.7); --fg-3: rgba(18, 24, 33, 0.44); --line: rgba(18, 24, 33, 0.11); --plate: rgba(255, 255, 255, 0.5); --plate-hi: rgba(255, 255, 255, 0.78); --accent: #0d8b7d; --ink: #ffffff; --shadow: rgba(15, 23, 42, 0.28); background: linear-gradient(170deg, rgba(255, 255, 255, 0.72) 0%, rgba(255, 255, 255, 0.44) 44%, rgba(255, 255, 255, 0.6) 100%), rgba(255, 255, 255, 0.2); border-color: rgba(255, 255, 255, 0.9); box-shadow: 0 16px 40px -18px var(--shadow), 0 1px 2px rgba(15, 23, 42, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.95); } @keyframes yc-in { from { opacity: 0; transform: translateY(6px) scale(0.99); } to { opacity: 1; transform: none; } } /* 顶部柔光 + 内壁斜面,玻璃的厚度只靠这两层表达 */ .yc-sheen { position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 1; background: radial-gradient(120% 46% at 50% -14%, rgba(255, 255, 255, 0.2), transparent 60%), linear-gradient(104deg, rgba(255, 255, 255, 0.07) 0%, transparent 32%, transparent 70%, rgba(255, 255, 255, 0.05) 100%); } .yc-panel[data-tone="light"] .yc-sheen { background: radial-gradient(120% 46% at 50% -14%, rgba(255, 255, 255, 0.9), transparent 62%), linear-gradient(104deg, rgba(255, 255, 255, 0.5) 0%, transparent 36%, transparent 72%, rgba(255, 255, 255, 0.4) 100%); } .yc-bevel { position: absolute; inset: 0; border-radius: inherit; pointer-events: none; z-index: 3; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.34), inset 0 -1px 0 rgba(255, 255, 255, 0.08), inset 1px 0 0 rgba(255, 255, 255, 0.12), inset -1px 0 0 rgba(255, 255, 255, 0.12); } .yc-panel[data-tone="light"] .yc-bevel { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.98), inset 0 -1px 0 rgba(255, 255, 255, 0.45), inset 1px 0 0 rgba(255, 255, 255, 0.6), inset -1px 0 0 rgba(255, 255, 255, 0.6); } /* ---------- 头部 ---------- */ .yc-head { position: relative; z-index: 5; display: flex; align-items: center; gap: 9px; padding: 11px 9px 9px 12px; cursor: grab; touch-action: none; user-select: none; } .yc-head.is-dragging { cursor: grabbing; } .yc-mark { flex: 0 0 auto; width: 22px; height: 22px; display: grid; place-items: center; border-radius: 7px; color: var(--accent); background: var(--plate); border: 1px solid var(--line); } .yc-mark svg { width: 12px; height: 12px; fill: currentColor; } .yc-title { flex: 1 1 auto; min-width: 0; font-size: 12.5px; font-weight: 600; letter-spacing: 0.2px; color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .yc-headbtns { display: flex; gap: 2px; flex: 0 0 auto; } .yc-icon { width: 22px; height: 22px; display: grid; place-items: center; padding: 0; border: 1px solid transparent; border-radius: 7px; background: transparent; color: var(--fg-3); font: inherit; font-size: 12px; line-height: 1; cursor: pointer; transition: background 140ms ease, color 140ms ease; } .yc-icon:hover { background: var(--plate); color: var(--fg); } .yc-icon:active { opacity: 0.7; } .yc-icon:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; } /* ---------- 内容 ---------- */ .yc-body { position: relative; z-index: 5; padding: 0 12px 10px; display: flex; flex-direction: column; gap: 10px; } .yc-row-label { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 6px; } .yc-row-label span { font-size: 11px; color: var(--fg-2); } .yc-speed-val { font-size: 17px; font-weight: 650; color: var(--fg); font-variant-numeric: tabular-nums; letter-spacing: 0.2px; transition: color 140ms ease; } .yc-speed-val.is-hot { color: var(--accent); } /* 滑杆 */ .yc-range { -webkit-appearance: none; appearance: none; width: 100%; height: 18px; background: transparent; cursor: pointer; display: block; margin: 0; } .yc-range::-webkit-slider-runnable-track { height: 4px; border-radius: 99px; background: linear-gradient( 90deg, var(--accent) 0%, var(--accent) var(--yc-fill, 40%), rgba(255, 255, 255, 0.15) var(--yc-fill, 40%), rgba(255, 255, 255, 0.15) 100% ); } .yc-range::-moz-range-track { height: 4px; border-radius: 99px; background: rgba(255, 255, 255, 0.15); } .yc-range::-moz-range-progress { height: 4px; border-radius: 99px; background: var(--accent); } .yc-range::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: #fbfdff; border: none; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5); transition: box-shadow 140ms ease, transform 140ms ease; } .yc-range:hover::-webkit-slider-thumb { box-shadow: 0 1px 5px rgba(0, 0, 0, 0.55), 0 0 0 5px rgba(78, 201, 184, 0.18); } .yc-range:active::-webkit-slider-thumb { transform: scale(1.08); } .yc-range::-moz-range-thumb { width: 13px; height: 13px; border-radius: 50%; background: #fbfdff; border: none; box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5); } .yc-range:focus-visible { outline: none; } .yc-range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 5px rgba(78, 201, 184, 0.3); } /* 倍速快捷 */ .yc-chips { display: flex; gap: 4px; margin-top: 8px; } .yc-chip { flex: 1 1 0; min-width: 0; height: 25px; padding: 0; border-radius: 7px; border: 1px solid var(--line); background: var(--plate); color: var(--fg-2); font: inherit; font-size: 11px; font-variant-numeric: tabular-nums; cursor: pointer; transition: background 140ms ease, color 140ms ease, border-color 140ms ease; } .yc-chip:hover { color: var(--fg); background: var(--plate-hi); } .yc-chip.is-on { color: var(--ink); background: var(--accent); border-color: transparent; font-weight: 650; } .yc-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; } /* 动作 */ .yc-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 5px; } .yc-actions-2 { grid-template-columns: repeat(2, 1fr); } .yc-act { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; height: 46px; padding: 0; border-radius: 10px; border: 1px solid var(--line); background: var(--plate); color: var(--fg-2); font: inherit; font-size: 10px; cursor: pointer; transition: background 140ms ease, color 140ms ease, border-color 140ms ease; } .yc-act svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; } .yc-act:hover { color: var(--fg); background: var(--plate-hi); } .yc-act:active { opacity: 0.75; } .yc-act.is-on { color: var(--accent); border-color: rgba(78, 201, 184, 0.4); background: rgba(78, 201, 184, 0.1); } .yc-act:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; } /* 更多设置 */ .yc-more { display: flex; align-items: center; justify-content: space-between; width: 100%; height: 30px; padding: 0 10px; border: none; border-radius: 9px; background: transparent; color: var(--fg-2); font: inherit; font-size: 11px; cursor: pointer; transition: background 140ms ease, color 140ms ease; } .yc-more:hover { background: var(--plate); color: var(--fg-2); } .yc-more:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; } .yc-more .yc-caret { font-size: 9px; transition: transform 180ms ease; } .yc-more.is-open .yc-caret { transform: rotate(180deg); } .yc-extras { display: none; flex-direction: column; gap: 8px; margin-top: -2px; } .yc-extras.is-open { display: flex; animation: yc-fade 160ms ease-out both; } @keyframes yc-fade { from { opacity: 0; transform: translateY(-3px); } to { opacity: 1; transform: none; } } /* 外观切换 */ .yc-seg { display: flex; gap: 4px; } .yc-seg button { flex: 1 1 0; height: 25px; border-radius: 7px; border: 1px solid var(--line); background: var(--plate); color: var(--fg-2); font: inherit; font-size: 10.5px; cursor: pointer; transition: background 140ms ease, color 140ms ease; } .yc-seg button:hover { background: var(--plate-hi); color: var(--fg); } .yc-seg button.is-on { color: var(--accent); background: rgba(78, 201, 184, 0.12); border-color: rgba(78, 201, 184, 0.45); } /* 开关 */ .yc-switches { display: flex; flex-direction: column; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03); overflow: hidden; } .yc-sw { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 9px; border: none; border-bottom: 1px solid var(--line); background: transparent; color: var(--fg); font: inherit; text-align: left; cursor: pointer; transition: background 140ms ease; } .yc-sw:last-child { border-bottom: none; } .yc-sw:hover { background: var(--plate); } .yc-sw:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; } .yc-sw-txt { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; } .yc-sw-txt b { font-size: 11.5px; font-weight: 500; color: var(--fg); } .yc-sw-txt i { font-size: 10px; font-style: normal; color: var(--fg-3); } .yc-toggle { flex: 0 0 auto; width: 30px; height: 17px; border-radius: 99px; background: rgba(255, 255, 255, 0.16); position: relative; transition: background 180ms ease; } .yc-toggle::after { content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35); transition: transform 180ms ease; } .yc-sw[data-on="1"] .yc-toggle { background: var(--accent); } .yc-sw[data-on="1"] .yc-toggle::after { transform: translateX(13px); } /* ---------- 底栏 ---------- */ .yc-foot { position: relative; z-index: 5; padding: 0 12px 9px; font-size: 10px; color: var(--fg-3); } .yc-stat { display: flex; align-items: center; gap: 5px; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .yc-dot { flex: 0 0 auto; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); } .yc-dot.is-idle { background: var(--fg-3); } /* ---------- 提示条 ---------- */ .yc-toast { position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 20; display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; font-size: 11px; color: var(--fg); background: rgba(18, 22, 30, 0.96); border: 1px solid rgba(255, 255, 255, 0.16); box-shadow: 0 12px 28px -14px rgba(0, 0, 0, 0.8); opacity: 0; transform: translateY(6px); pointer-events: none; transition: opacity 160ms ease, transform 160ms ease; } .yc-toast.is-show { opacity: 1; transform: none; pointer-events: auto; } .yc-panel[data-tone="light"] .yc-toast { background: rgba(252, 253, 255, 0.98); border-color: rgba(18, 24, 33, 0.1); color: var(--fg); box-shadow: 0 12px 28px -16px rgba(15, 23, 42, 0.4); } .yc-toast-msg { flex: 1 1 auto; min-width: 0; line-height: 1.35; } .yc-toast-btn { flex: 0 0 auto; height: 22px; padding: 0 9px; border: none; border-radius: 7px; background: var(--accent); color: var(--ink); font: inherit; font-size: 10.5px; font-weight: 600; cursor: pointer; } /* ---------- 收起后的胶囊 ---------- */ .yc-pill { display: none; align-items: center; gap: 7px; height: 36px; padding: 0 12px 0 6px; border-radius: 99px; cursor: pointer; color: #edf1f5; border: 1px solid rgba(255, 255, 255, 0.22); background: linear-gradient(160deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.05)), rgba(16, 20, 26, 0.66); backdrop-filter: blur(20px) saturate(170%); -webkit-backdrop-filter: blur(20px) saturate(170%); box-shadow: 0 10px 26px -12px rgba(0, 0, 0, 0.7), inset 0 1px 0 rgba(255, 255, 255, 0.22); user-select: none; touch-action: none; } .yc-dock[data-tone="light"] .yc-pill { color: #121821; border-color: rgba(255, 255, 255, 0.9); background: linear-gradient(160deg, rgba(255, 255, 255, 0.82), rgba(255, 255, 255, 0.62)), rgba(255, 255, 255, 0.4); box-shadow: 0 10px 26px -16px rgba(15, 23, 42, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.95); } .yc-pill:hover { transform: translateY(-1px); } .yc-pill .yc-mark { width: 24px; height: 24px; border-radius: 50%; } .yc-pill b { font-size: 11.5px; font-weight: 600; white-space: nowrap; } .yc-pill em { font-style: normal; font-size: 10.5px; color: rgba(237, 241, 245, 0.55); font-variant-numeric: tabular-nums; } .yc-dock[data-tone="light"] .yc-pill em { color: rgba(18, 24, 33, 0.5); } .yc-dock.is-collapsed .yc-panel { display: none; } .yc-dock.is-collapsed .yc-pill { display: flex; } .yc-dock.is-hidden { display: none; } /* ---------- 窄屏与动效降级 ---------- */ @media (max-width: 560px) { .yc-dock { width: var(--yc-w, 300px); } .yc-act { height: 42px; font-size: 9.5px; } } @media (prefers-reduced-motion: reduce) { .yc-panel, .yc-extras.is-open { animation: none; } .yc-toast, .yc-toggle::after, .yc-caret { transition: none; } } `; var VERSION = '1.1.0'; var NAME = '视频面板'; var PFX = 'vp.'; /* ---------------------------------------------------------------- 存储 */ var hasGM = typeof GM_getValue === 'function' && typeof GM_setValue === 'function'; var store = { get: function (k, dv) { try { if (hasGM) { var v = GM_getValue(PFX + k); return v === undefined || v === null ? dv : v; } var raw = localStorage.getItem(PFX + k); return raw === null ? dv : JSON.parse(raw); } catch (e) { return dv; } }, set: function (k, v) { try { if (hasGM) GM_setValue(PFX + k, v); else localStorage.setItem(PFX + k, JSON.stringify(v)); } catch (e) {} } }; /* ---------------------------------------------------------------- 站点 */ var SITES = [ { id: 'bilibili', label: '哔哩哔哩', re: /(^|\.)bilibili\.com$/i }, { id: 'iqiyi', label: '爱奇艺', re: /(^|\.)(iqiyi|iq)\.com$/i }, { id: 'tencent', label: '腾讯视频', re: /(^|\.)qq\.com$/i }, { id: 'youku', label: '优酷', re: /(^|\.)youku\.com$/i }, { id: 'youtube', label: 'YouTube', re: /(^|\.)youtube\.com$/i } ]; var site = (function () { var h = location.hostname; for (var i = 0; i < SITES.length; i++) if (SITES[i].re.test(h)) return SITES[i]; return { id: 'page', label: location.hostname.replace(/^www\./, '') || '本地页面' }; })(); // 界面净化只处理页面外围的推荐位与浮层,不碰播放器内部 var CLEAN = { bilibili: [ '.ad-report', '.video-card-ad-small', '.slide-ad-exp', '.bili-guide', '.pop-live-small-mode', '.bpx-player-row-dm-wrap > .bpx-player-ad', '.fixed-sdanav' ], iqiyi: ['.qy-player-ad', '[class*="qy-player-ad"]', '.qy-player-guide', '.iqp-ad'], tencent: ['.txp_ad', '.txp_adv', '.mod_ad', '[class*="player-ad"]'], youku: ['.youku-ad', '.h5-ext-layer', '[class*="ad-banner"]'], youtube: ['#masthead-ad', 'ytd-display-ad-renderer', '#player-ads'] }; /* ---------------------------------------------------------------- 状态 */ var S = { speed: 1, tone: store.get('tone', 'auto'), collapsed: store.get('collapsed', false), hidden: false, extras: false, sw: { resume: store.get('sw.resume', true), clean: store.get('sw.clean', false), keys: store.get('sw.keys', true), remember: store.get('sw.remember', false) }, pos: store.get('pos', null) }; // 记下启动时是否有存过的位置:没有的话每次重新贴角都要重新算,否则会把没测量准的高度算进去 var posFromStore = !!(S.pos && typeof S.pos.x === 'number'); var video = null; var pendingResume = null; var cleanStyle = null; var restoreFS = null; var restoreMirror = null; var saveTimer = 0; var toastTimer = 0; var lastStat = ''; /* ---------------------------------------------------------------- 小工具 */ function clamp(v, a, b) { return v < a ? a : v > b ? b : v; } function fmtTime(t) { if (!isFinite(t) || t < 0) return '--:--'; t = Math.floor(t); var h = Math.floor(t / 3600); var m = Math.floor((t % 3600) / 60); var s = t % 60; var mm = (m < 10 ? '0' : '') + m; var ss = (s < 10 ? '0' : '') + s; return h > 0 ? h + ':' + mm + ':' + ss : mm + ':' + ss; } function fmtSpeed(v) { if (v >= 10) return v.toFixed(1) + '×'; return v.toFixed(2).replace(/(\.\d)0$/, '$1') + '×'; } /* ---------------------------------------------------------------- 播放器 */ function pickVideo() { var list = document.querySelectorAll('video'); var best = null; var area = -1; for (var i = 0; i < list.length; i++) { var r = list[i].getBoundingClientRect(); var a = Math.max(0, r.width) * Math.max(0, r.height); if (a > area) { area = a; best = list[i]; } } return best && area > 0 ? best : list[0] || null; } function bindVideo(v) { if (!v || v === video) return; if (video) { video.removeEventListener('loadedmetadata', onMeta); video.removeEventListener('ratechange', onRate); video.removeEventListener('timeupdate', onTick); } video = v; v.addEventListener('loadedmetadata', onMeta); v.addEventListener('ratechange', onRate); v.addEventListener('timeupdate', onTick); if (S.sw.remember && S.speed !== 1) v.playbackRate = S.speed; onMeta(); } function progKey() { return location.origin + location.pathname; } function onMeta() { if (!video) return; updateStat(); if (!S.sw.resume) return; var rec = store.get('prog.' + progKey(), null); if (!rec || !rec.t) return; var d = video.duration; if (!isFinite(d) || d < 60) return; if (rec.t < 15 || d - rec.t < 30) return; if (Date.now() - (rec.ts || 0) > 30 * 24 * 3600 * 1000) return; pendingResume = rec.t; toast('上次看到 ' + fmtTime(rec.t), { action: { label: '接着看', fn: function () { try { video.currentTime = pendingResume; } catch (e) {} pendingResume = null; toast('已跳到 ' + fmtTime(video.currentTime)); } }, timeout: 9000 }); } function onRate() { if (!video || !S.sw.remember) return; if (Math.abs(video.playbackRate - S.speed) > 0.01) { try { video.playbackRate = S.speed; } catch (e) {} } } function onTick() { updateStat(); if (!S.sw.resume) return; var now = Date.now(); if (now - saveTimer < 5000) return; saveTimer = now; if (!video || video.paused) return; store.set('prog.' + progKey(), { t: Math.round(video.currentTime), d: Math.round(video.duration || 0), ts: now }); } function updateStat() { if (!el.stat) return; var txt; if (!video) { txt = site.label + ' · 未找到播放器'; el.dot.classList.add('is-idle'); } else { var w = video.videoWidth || 0; var h = video.videoHeight || 0; txt = (w && h ? w + '×' + h : site.label) + ' · ' + fmtTime(video.currentTime) + ' / ' + fmtTime(video.duration); el.dot.classList.toggle('is-idle', video.paused); } if (txt !== lastStat) { lastStat = txt; el.stat.textContent = txt; } } /* ---------------------------------------------------------------- 图标 */ var ICONS = { pip: '', shot: '', full: '', mute: '', loop: '', mirror: '' }; function actHTML(k, icon, label) { return ( '' ); } var PRESETS = [0.5, 1, 1.5, 2, 3]; var host = document.createElement('div'); host.id = 'video-panel-host'; host.setAttribute('data-version', VERSION); [ ['position', 'fixed'], ['left', '0'], ['top', '0'], ['width', '0'], ['height', '0'], ['display', 'block'], ['z-index', '2147483000'] ].forEach(function (kv) { host.style.setProperty(kv[0], kv[1], 'important'); }); var root = host.attachShadow({ mode: 'open' }); var styleTag = document.createElement('style'); styleTag.textContent = __YC_CSS__; root.appendChild(styleTag); var MARK = ''; var wrap = document.createElement('div'); wrap.className = 'yc-dock'; wrap.innerHTML = '
' + '
' + '
' + MARK + '
' + '
' + NAME + '
' + '
' + '' + '' + '
' + '
' + '
' + '
播放速度1×
' + '' + '
' + PRESETS.map(function (p) { return ''; }).join('') + '
' + '
' + actHTML('pip', 'pip', '画中画') + actHTML('shot', 'shot', '截图') + actHTML('full', 'full', '全屏') + actHTML('mute', 'mute', '静音') + '
' + '' + '
' + '
' + actHTML('loop', 'loop', '循环播放') + actHTML('mirror', 'mirror', '画面镜像') + '
' + '
' + '' + '' + '' + '
' + '
' + '' + '' + '' + '' + '
' + '
' + '
' + '
检测中
' + '
' + '
' + '
' + '
' + '
' + '
' + MARK + '
' + NAME + '1×' + '
'; root.appendChild(wrap); function $(sel) { return wrap.querySelector(sel); } var el = { dock: wrap, panel: $('.yc-panel'), head: $('.yc-head'), range: $('.yc-range'), val: $('.yc-speed-val'), chips: $('.yc-chips'), actions: $('.yc-actions'), extras: $('.yc-extras'), more: $('.yc-more'), seg: $('.yc-seg'), stat: $('.yc-stat-txt'), dot: $('.yc-dot'), toast: $('.yc-toast'), toastMsg: $('.yc-toast-msg'), pill: $('.yc-pill'), pillSpeed: $('.yc-pill em') }; /* ---------------------------------------------------------------- 外观 */ function resolvedTone() { if (S.tone === 'light' || S.tone === 'dark') return S.tone; try { var bg = getComputedStyle(document.body || document.documentElement).backgroundColor; var m = /rgba?\(([\d.]+),\s*([\d.]+),\s*([\d.]+)(?:,\s*([\d.]+))?/.exec(bg); if (m) { var alpha = m[4] === undefined ? 1 : parseFloat(m[4]); if (alpha > 0.2) { var lum = (0.299 * +m[1] + 0.587 * +m[2] + 0.114 * +m[3]) / 255; return lum > 0.6 ? 'light' : 'dark'; } } } catch (e) {} try { return matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'; } catch (e) {} return 'dark'; } function applyTone() { var t = resolvedTone(); el.panel.setAttribute('data-tone', t); wrap.setAttribute('data-tone', t); var btns = el.seg.querySelectorAll('button'); for (var i = 0; i < btns.length; i++) { btns[i].classList.toggle('is-on', btns[i].dataset.toneSet === S.tone); } } /* ---------------------------------------------------------------- 提示 */ function toast(msg, opt) { opt = opt || {}; el.toastMsg.textContent = msg; var old = el.toast.querySelector('.yc-toast-btn'); if (old) old.remove(); if (opt.action) { var b = document.createElement('button'); b.className = 'yc-toast-btn'; b.type = 'button'; b.textContent = opt.action.label; b.onclick = function () { opt.action.fn(); hideToast(); }; el.toast.appendChild(b); } el.toast.classList.add('is-show'); clearTimeout(toastTimer); toastTimer = setTimeout(hideToast, opt.timeout || 2400); } function hideToast() { el.toast.classList.remove('is-show'); } /* ---------------------------------------------------------------- 位置 */ function measure() { var r = el.dock.getBoundingClientRect(); return { w: r.width || 340, h: r.height || 300 }; } function place(x, y) { var m = measure(); var maxX = Math.max(8, window.innerWidth - m.w - 8); var maxY = Math.max(8, window.innerHeight - m.h - 8); S.pos = { x: Math.round(clamp(x, 8, maxX)), y: Math.round(clamp(y, 8, maxY)) }; wrap.style.setProperty('--yc-x', S.pos.x + 'px'); wrap.style.setProperty('--yc-y', S.pos.y + 'px'); } function dockToCorner() { var m = measure(); place(window.innerWidth - m.w - 20, window.innerHeight - m.h - 20); } // 尺寸变化(展开设置、收起胶囊)时,让靠近视口边缘的那一条边保持不动 function placeKeeping(prev) { var m = measure(); var keepRight = prev.right > window.innerWidth / 2; var keepBottom = prev.bottom > window.innerHeight / 2; place(keepRight ? prev.right - m.w : prev.left, keepBottom ? prev.bottom - m.h : prev.top); } function initPos() { if (posFromStore) place(S.pos.x, S.pos.y); else dockToCorner(); } function dragify(node) { var start = null; node.addEventListener('pointerdown', function (e) { if (e.button !== 0) return; if (e.target.closest('button')) return; if (!e.target.closest('[data-drag="1"]') && !e.target.closest('.yc-pill')) return; var base = S.pos || { x: 0, y: 0 }; start = { px: e.clientX, py: e.clientY, x: base.x, y: base.y }; el.head.classList.add('is-dragging'); try { node.setPointerCapture(e.pointerId); } catch (err) {} e.preventDefault(); }); node.addEventListener('pointermove', function (e) { if (!start) return; place(start.x + (e.clientX - start.px), start.y + (e.clientY - start.py)); }); function end() { if (!start) return; start = null; el.head.classList.remove('is-dragging'); store.set('pos', S.pos); } node.addEventListener('pointerup', end); node.addEventListener('pointercancel', end); } /* ---------------------------------------------------------------- 倍速 */ function sliderToSpeed(t) { return 0.1 * Math.pow(160, t); } function speedToSlider(v) { return Math.log(clamp(v, 0.1, 16) / 0.1) / Math.log(160); } function paintSpeed() { var t = speedToSlider(S.speed); el.range.value = String(Math.round(t * 1000)); el.range.style.setProperty('--yc-fill', (t * 100).toFixed(1) + '%'); el.val.textContent = fmtSpeed(S.speed); el.pillSpeed.textContent = fmtSpeed(S.speed); var chips = el.chips.querySelectorAll('.yc-chip'); for (var i = 0; i < chips.length; i++) { chips[i].classList.toggle('is-on', Math.abs(parseFloat(chips[i].dataset.speed) - S.speed) < 0.005); } } function setSpeed(v, quiet) { v = Math.round(clamp(v, 0.1, 16) * 100) / 100; S.speed = v; if (video) { try { video.playbackRate = v; } catch (e) {} } paintSpeed(); el.val.classList.add('is-hot'); setTimeout(function () { el.val.classList.remove('is-hot'); }, 280); if (!quiet && S.sw.remember) store.set('speed', v); } function stepSpeed(dir) { var v = S.speed; if (dir > 0) v = v < 3.99 ? v + 0.25 : v * 1.5; else v = v <= 4.01 ? v - 0.25 : v / 1.5; setSpeed(v); toast(fmtSpeed(S.speed), { timeout: 1000 }); } /* ---------------------------------------------------------------- 动作 */ function needVideo() { bindVideo(pickVideo()); if (!video) { toast('这个页面没有播放器'); return null; } return video; } function setAct(k, on) { var b = el.actions.querySelector('[data-act="' + k + '"]'); if (b) b.classList.toggle('is-on', !!on); } function togglePip() { var v = needVideo(); if (!v) return; try { if (document.pictureInPictureElement) { document.exitPictureInPicture(); setAct('pip', false); return; } var p = v.requestPictureInPicture(); if (p && p.then) { p.then(function () { setAct('pip', true); }).catch(function () { toast('这个浏览器不支持画中画'); }); } } catch (e) { toast('这个浏览器不支持画中画'); } } function shoot() { var v = needVideo(); if (!v) return; var w = v.videoWidth; var h = v.videoHeight; if (!w || !h) return toast('画面还没加载完'); var c = document.createElement('canvas'); c.width = w; c.height = h; try { c.getContext('2d').drawImage(v, 0, 0, w, h); } catch (e) { return toast('画面受跨域限制,取不到'); } try { c.toBlob(function (blob) { if (!blob) return toast('截图失败'); var url = URL.createObjectURL(blob); var a = document.createElement('a'); a.href = url; a.download = site.id + '-' + fmtTime(v.currentTime).replace(/:/g, '') + '.png'; document.body.appendChild(a); a.click(); a.remove(); setTimeout(function () { URL.revokeObjectURL(url); }, 5000); toast('已保存 ' + w + '×' + h); }, 'image/png'); } catch (e) { toast('画面受跨域限制,存不下来'); } } function toggleFull() { var v = needVideo(); if (!v) return; if (restoreFS) { restoreFS(); restoreFS = null; setAct('full', false); return; } var s = v.style; var prev = { position: s.position, inset: s.inset, left: s.left, top: s.top, width: s.width, height: s.height, maxWidth: s.maxWidth, maxHeight: s.maxHeight, objectFit: s.objectFit, background: s.background, zIndex: s.zIndex, transform: s.transform, margin: s.margin }; s.position = 'fixed'; s.inset = '0px'; s.left = '0px'; s.top = '0px'; s.width = '100vw'; s.height = '100vh'; s.maxWidth = 'none'; s.maxHeight = 'none'; s.objectFit = 'contain'; s.background = '#000'; s.zIndex = '2147483100'; s.margin = '0'; if (restoreMirror) s.transform = 'scaleX(-1)'; restoreFS = function () { for (var k in prev) s[k] = prev[k]; }; setAct('full', true); } function toggleMute() { var v = needVideo(); if (!v) return; v.muted = !v.muted; setAct('mute', v.muted); toast(v.muted ? '已静音' : '已开启声音', { timeout: 1000 }); } function toggleLoop() { var v = needVideo(); if (!v) return; v.loop = !v.loop; var b = el.extras.querySelector('[data-act="loop"]'); if (b) b.classList.toggle('is-on', v.loop); toast(v.loop ? '循环播放' : '取消循环', { timeout: 1000 }); } function toggleMirror() { var v = needVideo(); if (!v) return; var b = el.extras.querySelector('[data-act="mirror"]'); if (restoreMirror) { restoreMirror(); restoreMirror = null; if (b) b.classList.remove('is-on'); return; } var s = v.style; var prev = s.transform; s.transform = 'scaleX(-1)'; restoreMirror = function () { s.transform = prev; }; if (b) b.classList.add('is-on'); } /* ---------------------------------------------------------------- 净化 */ function applyClean(on) { S.sw.clean = on; store.set('sw.clean', on); if (!cleanStyle) { cleanStyle = document.createElement('style'); cleanStyle.id = 'video-panel-clean'; document.head.appendChild(cleanStyle); } var sel = (CLEAN[site.id] || []).slice(); if (!on || !sel.length) { cleanStyle.textContent = ''; return; } cleanStyle.textContent = sel.join(',\n') + '{display:none !important;}'; } /* ---------------------------------------------------------------- 键盘 */ function isEditable(t) { if (!t) return false; var n = (t.tagName || '').toLowerCase(); return n === 'input' || n === 'textarea' || n === 'select' || t.isContentEditable; } function onKey(e) { if (!S.sw.keys) return; if (e.ctrlKey || e.altKey || e.metaKey || !e.shiftKey) return; if (isEditable(e.target)) return; var handled = true; switch (e.code) { case 'Comma': stepSpeed(-1); break; case 'Period': stepSpeed(1); break; case 'KeyD': shoot(); break; case 'KeyP': togglePip(); break; case 'KeyF': toggleFull(); break; case 'KeyH': setHidden(!S.hidden); break; default: handled = false; } if (handled) { e.preventDefault(); e.stopPropagation(); } } /* ---------------------------------------------------------------- 显隐 */ function setHidden(h) { if (h && !S.hidden) { toast('已隐藏,Shift+H 恢复', { timeout: 1500 }); S.hidden = true; setTimeout(function () { if (S.hidden) wrap.classList.add('is-hidden'); }, 800); return; } S.hidden = h; wrap.classList.toggle('is-hidden', h); } function setCollapsed(c) { var before = el.dock.getBoundingClientRect(); S.collapsed = c; wrap.classList.toggle('is-collapsed', c); store.set('collapsed', c); placeKeeping(before); store.set('pos', S.pos); } function setExtras(on) { var before = el.dock.getBoundingClientRect(); S.extras = on; el.extras.classList.toggle('is-open', on); el.more.classList.toggle('is-open', on); el.more.setAttribute('aria-expanded', on ? 'true' : 'false'); placeKeeping(before); store.set('pos', S.pos); } /* ---------------------------------------------------------------- 事件 */ wrap.addEventListener('click', function (e) { var t = e.target.closest('button'); if (!t) { if (e.target.closest('.yc-pill')) setCollapsed(false); return; } var act = t.dataset.act; if (act) { if (act === 'more') setExtras(!S.extras); else if (act === 'collapse') setCollapsed(!S.collapsed); else if (act === 'hide') setHidden(true); else if (act === 'pip') togglePip(); else if (act === 'shot') shoot(); else if (act === 'full') toggleFull(); else if (act === 'mute') toggleMute(); else if (act === 'loop') toggleLoop(); else if (act === 'mirror') toggleMirror(); return; } if (t.dataset.speed) { setSpeed(parseFloat(t.dataset.speed)); return; } if (t.dataset.toneSet) { S.tone = t.dataset.toneSet; store.set('tone', S.tone); applyTone(); return; } var sw = t.dataset.sw; if (sw) { var on = t.dataset.on !== '1'; t.dataset.on = on ? '1' : '0'; S.sw[sw] = on; store.set('sw.' + sw, on); if (sw === 'clean') applyClean(on); if (sw === 'resume' && !on) pendingResume = null; if (sw === 'remember') { if (on) store.set('speed', S.speed); else { S.speed = 1; if (video) video.playbackRate = 1; paintSpeed(); } } toast((on ? '已开启 ' : '已关闭 ') + t.querySelector('b').textContent, { timeout: 1200 }); } }); el.range.addEventListener('input', function () { setSpeed(sliderToSpeed(parseInt(el.range.value, 10) / 1000), true); }); el.range.addEventListener('change', function () { if (S.sw.remember) store.set('speed', S.speed); }); el.range.addEventListener( 'wheel', function (e) { e.preventDefault(); stepSpeed(e.deltaY < 0 ? 1 : -1); }, { passive: false } ); dragify(el.dock); ['click', 'pointerdown', 'pointerup', 'mousedown', 'mouseup', 'dblclick'].forEach(function (ev) { host.addEventListener(ev, function (e) { e.stopPropagation(); }); }); window.addEventListener('keydown', onKey, true); window.addEventListener('resize', function () { wrap.style.setProperty('--yc-w', (window.innerWidth < 560 ? Math.min(300, window.innerWidth - 24) : 340) + 'px'); if (S.pos) place(S.pos.x, S.pos.y); }); // 换页后重新识别播放器;面板被站点清掉时挂回去 setInterval(function () { if (!host.isConnected) (document.body || document.documentElement).appendChild(host); var v = pickVideo(); if (v && v !== video) bindVideo(v); }, 2000); /* ---------------------------------------------------------------- 启动 */ wrap.style.setProperty('--yc-w', (window.innerWidth < 560 ? Math.min(300, window.innerWidth - 24) : 340) + 'px'); (document.body || document.documentElement).appendChild(host); applyTone(); var savedSpeed = store.get('speed', 1); if (S.sw.remember && typeof savedSpeed === 'number') S.speed = clamp(savedSpeed, 0.1, 16); paintSpeed(); applyClean(!!S.sw.clean); bindVideo(pickVideo()); initPos(); if (S.collapsed) wrap.classList.add('is-collapsed'); requestAnimationFrame(function () { initPos(); updateStat(); }); if (typeof GM_registerMenuCommand === 'function') { try { GM_registerMenuCommand('显示 / 隐藏面板', function () { setHidden(!S.hidden); }); GM_registerMenuCommand('展开 / 收起面板', function () { setCollapsed(!S.collapsed); }); GM_registerMenuCommand('面板归位', function () { S.pos = null; store.set('pos', null); dockToCorner(); }); } catch (e) {} } })();