三和一
一次满足
图标
// ==UserScript==
// @name OiClass Logo
// @namespace https://oiclass.com/
// @version 6.0
// @description 替换 OiClass 的导航 Logo 和页面 Logo
// @match https://oiclass.com/*
// @match https://*.oiclass.com/*
// @run-at document-start
// @grant none
// ==/UserScript==
(function () {
'use strict';
//
const NAV_LOGO_SCALE = 0.22;
const PAGE_LOGO_SCALE = 0.09;
// ========================================================
// 【替换图片】
// ========================================================
const NEW_LOGO =
'https://cdn.luogu.com.cn/upload/image_hosting/hwv4k6qk.png';
const NAV_LOGO = 'nav_logo_dark.png';
const PAGE_LOGO = 'logo.jpg';
function getLogoType(src) {
if (!src) {
return null;
}
if (src.includes(NAV_LOGO)) {
return 'nav';
}
if (
src.includes('/file/2/logo.jpg') ||
src.includes(PAGE_LOGO)
) {
return 'page';
}
return null;
}
function getScale(type) {
if (type === 'nav') {
return NAV_LOGO_SCALE;
}
if (type === 'page') {
return PAGE_LOGO_SCALE;
}
return 1;
}
function resizeImage(img, type) {
const scale = getScale(type);
if (!img.naturalWidth || !img.naturalHeight) {
return;
}
const width =
img.naturalWidth * scale;
const height =
img.naturalHeight * scale;
img.style.setProperty(
'width',
`${width}px`,
'important'
);
img.style.setProperty(
'height',
`${height}px`,
'important'
);
img.style.setProperty(
'max-width',
'none',
'important'
);
img.style.setProperty(
'object-fit',
'contain',
'important'
);
}
function replaceImages() {
document.querySelectorAll('img').forEach(img => {
const originalSrc =
img.getAttribute('src') ||
img.getAttribute('data-src') ||
'';
const type =
getLogoType(originalSrc);
if (!type) {
return;
}
img.dataset.oiclassLogoType = type;
if (!img.src.includes(NEW_LOGO)) {
img.src = NEW_LOGO;
}
const resize = () => {
resizeImage(img, type);
};
if (img.complete) {
resize();
} else {
img.addEventListener(
'load',
resize,
{ once: true }
);
}
});
}
function replaceBackgroundImages() {
document.querySelectorAll('*').forEach(el => {
const style =
getComputedStyle(el);
const background =
style.backgroundImage;
if (
!background ||
background === 'none'
) {
return;
}
let type = null;
if (background.includes(NAV_LOGO)) {
type = 'nav';
}
if (background.includes('/file/2/logo.jpg')) {
type = 'page';
}
if (!type) {
return;
}
const scale =
getScale(type);
el.style.setProperty(
'background-image',
`url("${NEW_LOGO}")`,
'important'
);
el.style.setProperty(
'background-repeat',
'no-repeat',
'important'
);
el.style.setProperty(
'background-size',
`${scale * 100}% auto`,
'important'
);
});
}
const observer =
new MutationObserver(() => {
replaceImages();
});
function startObserver() {
if (!document.documentElement) {
requestAnimationFrame(
startObserver
);
return;
}
observer.observe(
document.documentElement,
{
childList: true,
subtree: true
}
);
replaceImages();
}
startObserver();
setInterval(() => {
replaceImages();
replaceBackgroundImages();
}, 500);
})();
还有配套的 !?乐乐?!
// ==UserScript==
// @name OiClass 悬浮音乐播放器
// @namespace https://oiclass.com/
// @version 3.1
// @description OiClass 专用紧凑型音乐播放器
// @match https://oiclass.com/*
// @match https://*.oiclass.com/*
// @run-at document-end
// @grant none
// ==/UserScript==
(function(){
'use strict';
// 🎵 歌曲列表
const PLAYLIST=[
{
name:"Constant Moderato - ミツキヨ",
url:"http://music.163.com/song/media/outer/url?id=2093257373.mp3",
cover:"http://p2.music.126.net/aZ5o_RJeFf4yv7VbUsf8qQ==/109951169003496957.jpg?param=300x300"
}
];
const S={i:'oiclass_music_index',v:'oiclass_music_volume',m:'oiclass_music_mode',p:'oiclass_music_position',x:'oiclass_music_x',y:'oiclass_music_y'};
if(window.top!==window.self||document.getElementById('oiclass-music-player'))return;
const p=document.createElement('div');
p.id='oiclass-music-player';
p.innerHTML=`
<div class="om-main">
<div class="om-cover-box"><img class="om-cover"></div>
<div class="om-right">
<div class="om-top"><div class="om-song-name">暂无歌曲</div><button class="om-list-btn">☰</button></div>
<div class="om-time">00:00 / 00:00</div>
<div class="om-progress"><div class="om-progress-bar"></div></div>
<div class="om-controls">
<button class="om-prev">⏮️</button>
<button class="om-play">▶️</button>
<button class="om-next">⏭️</button>
<button class="om-mode">🔁</button>
</div>
</div>
</div>
<div class="om-volume"><span>🔊</span><input class="om-volume-slider" type="range" min="0" max="1" step="0.01" value="0.7"></div>
<div class="om-playlist"><div class="om-playlist-title">歌曲列表</div><div class="om-songs"></div></div>`;
document.body.appendChild(p);
const st=document.createElement('style');
st.textContent=`
#oiclass-music-player{position:fixed;right:20px;bottom:20px;width:260px;padding:10px;box-sizing:border-box;background:rgba(25,25,30,.94);color:#fff;border-radius:13px;z-index:2147483647;font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Arial,sans-serif;box-shadow:0 6px 25px rgba(0,0,0,.35);backdrop-filter:blur(10px);user-select:none}
.om-main{display:flex;gap:10px}
.om-cover-box{width:72px;height:72px;flex-shrink:0;border-radius:9px;overflow:hidden;background:rgba(255,255,255,.08)}
.om-cover{width:100%;height:100%;object-fit:cover;display:block}
.om-right{flex:1;min-width:0}
.om-top{display:flex;align-items:center;gap:5px;cursor:move}
.om-song-name{flex:1;min-width:0;font-size:13px;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.om-list-btn{width:25px;height:25px;flex-shrink:0;border:0;border-radius:6px;background:rgba(255,255,255,.08);color:#fff;cursor:pointer;font-size:14px}
.om-list-btn:hover{background:rgba(255,255,255,.18)}
.om-time{margin-top:4px;font-size:10px;opacity:.55}
.om-progress{height:4px;margin-top:7px;background:rgba(255,255,255,.15);border-radius:10px;cursor:pointer;overflow:hidden}
.om-progress-bar{width:0;height:100%;background:#fff;border-radius:10px}
.om-controls{display:flex;align-items:center;justify-content:center;gap:3px;margin-top:6px}
.om-controls button{width:29px;height:27px;border:0;border-radius:7px;background:rgba(255,255,255,.08);color:#fff;cursor:pointer;font-size:13px}
.om-controls button:hover{background:rgba(255,255,255,.18)}
.om-play{font-size:15px!important}
.om-volume{display:flex;align-items:center;gap:6px;margin-top:8px;font-size:12px}
.om-volume-slider{flex:1;height:3px;cursor:pointer}
.om-playlist{display:none;margin-top:9px;padding-top:8px;border-top:1px solid rgba(255,255,255,.1)}
.om-playlist.show{display:block}
.om-playlist-title{font-size:11px;opacity:.55;margin-bottom:5px}
.om-songs{max-height:150px;overflow-y:auto}
.om-song-item{display:flex;align-items:center;gap:7px;padding:5px;border-radius:6px;cursor:pointer}
.om-song-item:hover{background:rgba(255,255,255,.1)}
.om-song-item.active{background:rgba(255,255,255,.17)}
.om-song-cover{width:28px;height:28px;border-radius:4px;object-fit:cover;flex-shrink:0}
.om-song-text{min-width:0;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;font-size:11px}`;
document.head.appendChild(st);
const a=document.createElement('audio');
a.preload='auto';
document.body.appendChild(a);
const c=p.querySelector('.om-cover'),n=p.querySelector('.om-song-name'),t=p.querySelector('.om-time'),pr=p.querySelector('.om-progress'),pb=p.querySelector('.om-progress-bar'),play=p.querySelector('.om-play'),prev=p.querySelector('.om-prev'),next=p.querySelector('.om-next'),modeBtn=p.querySelector('.om-mode'),vol=p.querySelector('.om-volume-slider'),listBtn=p.querySelector('.om-list-btn'),list=p.querySelector('.om-playlist'),songs=p.querySelector('.om-songs');
let i=parseInt(localStorage.getItem(S.i));
if(isNaN(i)||i<0||i>=PLAYLIST.length)i=0;
let v=parseFloat(localStorage.getItem(S.v));
if(isNaN(v))v=.7;
let m=localStorage.getItem(S.m)||'list';
a.volume=v;
vol.value=v;
const fmt=s=>!isFinite(s)?'00:00':String(Math.floor(s/60)).padStart(2,'0')+':'+String(Math.floor(s%60)).padStart(2,'0');
function updateList(){
songs.innerHTML='';
PLAYLIST.forEach((q,j)=>{
const e=document.createElement('div');
e.className='om-song-item'+(j===i?' active':'');
e.innerHTML=`<img class="om-song-cover" src="${q.cover}"><div class="om-song-text">${q.name}</div>`;
e.onclick=()=>{
i=j;
localStorage.removeItem(S.p);
load();
playMusic();
};
songs.appendChild(e);
});
}
function load(){
if(!PLAYLIST.length)return;
const q=PLAYLIST[i];
a.src=q.url;
n.textContent=q.name;
c.src=q.cover;
localStorage.setItem(S.i,i);
updateList();
const pos=parseFloat(localStorage.getItem(S.p));
if(!isNaN(pos))a.addEventListener('loadedmetadata',()=>{if(pos<a.duration)a.currentTime=pos},{once:true});
}
async function playMusic(){
try{await a.play();play.textContent='⏸️'}catch(e){console.warn('播放失败:',e)}
}
function pauseMusic(){a.pause();play.textContent='▶️'}
play.onclick=()=>a.paused?playMusic():pauseMusic();
function nextSong(){
i=(i+1)%PLAYLIST.length;
localStorage.removeItem(S.p);
load();
playMusic();
}
next.onclick=nextSong;
prev.onclick=()=>{
i=(i-1+PLAYLIST.length)%PLAYLIST.length;
localStorage.removeItem(S.p);
load();
playMusic();
};
function updateMode(){
modeBtn.textContent=m==='single'?'🔂':'🔁';
modeBtn.title=m==='single'?'单曲循环':'列表循环';
}
modeBtn.onclick=()=>{
m=m==='list'?'single':'list';
localStorage.setItem(S.m,m);
updateMode();
};
updateMode();
a.addEventListener('ended',()=>{
if(m==='single'){
a.currentTime=0;
playMusic();
}else nextSong();
});
a.addEventListener('timeupdate',()=>{
if(!a.duration)return;
pb.style.width=a.currentTime/a.duration*100+'%';
t.textContent=fmt(a.currentTime)+' / '+fmt(a.duration);
localStorage.setItem(S.p,a.currentTime);
});
pr.onclick=e=>{
if(!a.duration)return;
const r=pr.getBoundingClientRect();
a.currentTime=(e.clientX-r.left)/r.width*a.duration;
};
vol.oninput=()=>{
a.volume=vol.value;
localStorage.setItem(S.v,a.volume);
};
listBtn.onclick=()=>list.classList.toggle('show');
const drag=p.querySelector('.om-top');
let dragging=false,ox=0,oy=0;
drag.addEventListener('mousedown',e=>{
if(e.target.closest('button'))return;
dragging=true;
const r=p.getBoundingClientRect();
ox=e.clientX-r.left;
oy=e.clientY-r.top;
p.style.right='auto';
p.style.bottom='auto';
});
document.addEventListener('mousemove',e=>{
if(!dragging)return;
let x=Math.max(0,Math.min(e.clientX-ox,innerWidth-p.offsetWidth));
let y=Math.max(0,Math.min(e.clientY-oy,innerHeight-p.offsetHeight));
p.style.left=x+'px';
p.style.top=y+'px';
localStorage.setItem(S.x,x);
localStorage.setItem(S.y,y);
});
document.addEventListener('mouseup',()=>dragging=false);
const sx=parseFloat(localStorage.getItem(S.x));
const sy=parseFloat(localStorage.getItem(S.y));
if(!isNaN(sx)&&!isNaN(sy)){
p.style.right='auto';
p.style.bottom='auto';
p.style.left=sx+'px';
p.style.top=sy+'px';
}
load();
})();
背景
// ==UserScript==
// @name oiClass 自定义背景
// @namespace http://tampermonkey.net/
// @version 2.0
// @description
// @author You
// @match https://oiclass.com/*
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
// 配置区
const BG_CONFIG = {
bgImg: "https://cdn.luogu.com.cn/upload/image_hosting/c4mir4q7.png",
bgSize: "cover",
bgPos: "center",
bgRepeat: "no-repeat",
bgBlur: "1px",
maskOpacity: 0.00
};
// 插入背景div(不用伪元素,兼容性拉满)
let bgDiv = document.createElement("div");
bgDiv.id = "custom‑bg‑img";
document.body.appendChild(bgDiv);
GM_addStyle(`
#custom‑bg‑img{
position: fixed !important;
top:0;
left:0;
width:100vw;
height:100vh;
background-image:url("${BG_CONFIG.bgImg}");
background-size:${BG_CONFIG.bgSize};
background-position:${BG_CONFIG.bgPos};
background-repeat:${BG_CONFIG.bgRepeat};
filter: blur(${BG_CONFIG.bgBlur});
transform: scale(1.08);
z-index: -99999 !important;
}
body{
background:transparent !important;
}
.slideout-panel, .slideout-overlay {
background: rgba(22,28,36,${BG_CONFIG.maskOpacity}) !important;
}
.nav {
background: rgba(18,22,28,0.75) !important;
backdrop-filter: blur(6px);
}
.section{
background:rgba(30, 36, 48, 0.68) !important;
backdrop-filter: blur(4px);
}
`);
// 页面跳转之后重新挂载背景(该网站是单页应用,切换页面会丢失背景)
new MutationObserver(()=>{
if(!document.querySelector("#custom‑bg‑img")){
document.body.appendChild(bgDiv);
}
}).observe(document.body,{childList:true,subtree:true});
})();
背景 2.0
// ==UserScript==
// @name oiClass 自定义背景
// @namespace http://tampermonkey.net/
// @version 2.1
// @description hyw
// @author You
// @match https://oiclass.com/*
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
// 1. 配置区:在这里修改你的图片链接
const BG_CONFIG = {
// 默认背景图 (用于首页、题目页等)
default: {
img: "https://cdn.luogu.com.cn/upload/image_hosting/c4mir4q7.png", // 你原来的图片
blur: "1px"
},
// 个人主页背景图 (用于 /user/* 页面)
userProfile: {
img: "https://static.kivo.wiki/images/gallery/B2.%E6%9C%AC%E5%9C%B0%E5%8C%96CG/%E7%AE%80%E4%B8%AD%E6%9C%AC%E5%9C%B0%E5%8C%96/bg_aronaroom_night.jpg", // 示例:使用你主页的头像作为背景,可以换成任意图片链接
blur: "1px" // 个人主页背景模糊度可以大一点,防止干扰文字阅读
},
recordProfile: {
img: "https://static.kivo.wiki/images/gallery/1.%E4%B8%BB%E7%BA%BF%E5%89%A7%E6%83%85CG/%E6%9C%80%E7%BB%88%E7%AF%87/BG_CS_S1Final_77.jpg", // 示例:使用你主页的头像作为背景,可以换成任意图片链接
blur: "0.1px" // 个人主页背景模糊度可以大一点,防止干扰文字阅读
}
};
// 2. 逻辑判断:根据当前网址决定使用哪个配置
let currentBg = BG_CONFIG.default;
// 检查 URL 是否包含 "/user/"
if (window.location.pathname.includes("/user/")) {
currentBg = BG_CONFIG.userProfile;
}
if (window.location.pathname.includes("/record/")) {
currentBg = BG_CONFIG.recordProfile;
}
// 3. 创建并插入背景 div
let bgDiv = document.createElement("div");
bgDiv.id = "custom-bg-img";
document.body.appendChild(bgDiv);
// 4. 注入 CSS 样式
GM_addStyle(`
#custom-bg-img {
position: fixed !important;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
/* 使用变量 currentBg.img 动态设置图片 */
background-image: url("${currentBg.img}");
background-size: cover;
background-position: center;
background-repeat: no-repeat;
/* 使用变量 currentBg.blur 动态设置模糊度 */
filter: blur(${currentBg.blur});
transform: scale(1.08);
z-index: -99999 !important;
pointer-events: none; /* 防止背景图阻挡点击事件 */
transition: opacity 0.3s ease; /* 增加一点淡入淡出的过渡效果 */
}
body {
background: transparent !important;
}
/* 侧边栏和导航栏的毛玻璃效果优化 */
.slideout-panel, .slideout-overlay {
background: rgba(22, 28, 36, 0.0) !important;
}
.nav {
background: rgba(18, 22, 28, 0.5) !important;
backdrop-filter: blur(6px);
}
.section {
background: rgba(30, 36, 48, 0.5) !important;
backdrop-filter: blur(4px);
}
`);
// 5. 监听页面变化(针对单页应用)
// 当你在网站内跳转时,重新检查 URL 并更新背景
new MutationObserver(() => {
// 如果背景 div 被移除(页面跳转),重新添加
if (!document.querySelector("#custom-bg-img")) {
document.body.appendChild(bgDiv);
// 重新判断当前应该显示什么背景
let newBg = BG_CONFIG.default;
if (window.location.pathname.includes("/user/")) {
newBg = BG_CONFIG.userProfile;
}
// 更新背景图片样式
bgDiv.style.backgroundImage = `url("${newBg.img}")`;
bgDiv.style.filter = `blur(${newBg.blur})`;
}
}).observe(document.body, { childList: true, subtree: true });
})();
3.0
// ==UserScript==
// @name oiClass 自定义背景
// @namespace http://tampermonkey.net/
// @version 9.1
// @description oiClass 图片/B站视频背景
// @author You
// @match https://oiclass.com/*
// @match http://noica.oiclub.cn/*
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @connect api.bilibili.com
// @run-at document-idle
// ==/UserScript==
(function () {
"use strict";
// ===== 配置区域:新增背景时复制一个对象 =====
const BG_CONFIG = [
{
path: "/record/",
type: "image",
img: "https://static.kivo.wiki/images/gallery/1.%E4%B8%BB%E7%BA%BF%E5%89%A7%E6%83%85CG/%E6%9C%80%E7%BB%88%E7%AF%87/BG_CS_S1Final_77.jpg",
blur: "0.1px",
speed: 1
},
{
path: "/user/",
type: "image",
img: "https://static.kivo.wiki/images/gallery/B2.%E6%9C%AC%E5%9C%B0%E5%8C%96CG/%E7%AE%80%E4%B8%AD%E6%9C%AC%E5%9C%B0%E5%8C%96/bg_aronaroom_night.jpg",
blur: "1px",
speed: 1
}
];
// 默认背景:修改 img 为需要解析的 B 站 BV 号
const DEFAULT_BG = {
type: "bilibili",
img: "BV1U94y1K7ZL",
blur: "1px",
speed: 1.0
};
// 视频解析或播放失败时显示的备用图片
const FALLBACK_BG = {
img: "https://cdn.luogu.com.cn/upload/image_hosting/c4mir4q7.png",
blur: "1px"
};
// ===== 样式:保留原版背景层级与毛玻璃效果 =====
GM_addStyle(`
#custom-bg-img{position:fixed!important;inset:0;width:100vw;height:100vh;overflow:hidden;background-color:#111;background-size:cover;background-position:center;background-repeat:no-repeat;transform:scale(1.08);z-index:-99999!important;pointer-events:none}
#custom-bg-img video{position:absolute;top:0;left:0;width:100%;height:100%;object-fit:cover;object-position:center;pointer-events:none}
body{background:transparent!important}
.slideout-panel,.slideout-overlay{background:rgba(22,28,36,0)!important}
.nav{background:rgba(18,22,28,.5)!important;backdrop-filter:blur(6px)}
.section{background:rgba(30,36,48,.5)!important;backdrop-filter:blur(4px)}
`);
function getBG() { return BG_CONFIG.find(x => location.pathname.includes(x.path)) || DEFAULT_BG; }
function biliRequest(url) {
return new Promise((resolve, reject) => GM_xmlhttpRequest({
method: "GET", url, headers: { Referer: "https://www.bilibili.com/" }, timeout: 12000,
onload: r => { try { resolve(JSON.parse(r.responseText)); } catch (e) { reject(e); } },
onerror: reject, ontimeout: reject
}));
}
function getBVID(value) { return String(value).match(/BV[a-zA-Z0-9]{10}/)?.[0] || null; }
// 逐级尝试清晰度;B站接口实际返回画质仍受账号权限及视频本身限制
async function parseBilibili(value) {
const bv = getBVID(value);
if (!bv) throw Error("BV号无效");
const info = await biliRequest("https://api.bilibili.com/x/web-interface/view?bvid=" + bv);
if (info.code !== 0 || !info.data?.cid) throw Error("获取视频信息失败");
const cid = info.data.cid;
for (const qn of [112, 80, 64, 32, 16]) {
const result = await biliRequest("https://api.bilibili.com/x/player/playurl?" + new URLSearchParams({
bvid: bv, cid: String(cid), qn: String(qn), fnval: "0", fnver: "0", fourk: "1", platform: "html5"
}));
if (result.code === 0 && result.data?.durl?.length) {
return result.data.durl.flatMap(item => [item.url, ...(item.backup_url || [])]);
}
}
throw Error("没有可用的 MP4 视频流");
}
function getBox() {
let box = document.getElementById("custom-bg-img");
if (!box) { box = document.createElement("div"); box.id = "custom-bg-img"; document.body.prepend(box); }
return box;
}
function showImage(bg) {
const box = getBox();
box.replaceChildren();
box.style.filter = `blur(${bg.blur || "0px"})`;
box.style.backgroundImage = `url("${bg.img}")`;
}
function playVideo(urls, speed, requestId) {
const box = getBox();
let index = 0;
function next() {
if (requestId !== activeRequest) return;
if (index >= urls.length) { showImage(FALLBACK_BG); return; }
const video = document.createElement("video");
video.src = urls[index++];
video.autoplay = true; video.loop = true; video.muted = true; video.defaultMuted = true;
video.playsInline = true; video.preload = "auto";
video.playbackRate = Math.max(0.25, Math.min(Number(speed) || 1, 4));
video.onerror = () => { video.remove(); next(); };
box.replaceChildren(video);
const promise = video.play();
if (promise) promise.catch(() => { if (video.isConnected) { video.remove(); next(); } });
}
next();
}
let activeRequest = 0;
let currentKey = "";
async function updateBackground(force = false) {
if (!document.body) return;
const bg = getBG();
const key = `${bg.type}|${bg.img}|${bg.blur}|${bg.speed}`;
if (!force && key === currentKey && document.getElementById("custom-bg-img")) return;
currentKey = key;
const requestId = ++activeRequest;
const box = getBox();
box.replaceChildren();
box.style.backgroundImage = "none";
box.style.filter = `blur(${bg.blur || "0px"})`;
if (bg.type === "image") { showImage(bg); return; }
try {
const urls = await parseBilibili(bg.img);
if (requestId !== activeRequest) return;
playVideo(urls, bg.speed, requestId);
} catch (error) {
if (requestId !== activeRequest) return;
console.warn("[oiClass背景] B站解析失败:", error);
showImage(FALLBACK_BG);
}
}
let lastURL = location.href;
function checkRoute() {
if (location.href !== lastURL) { lastURL = location.href; updateBackground(true); }
else if (!document.getElementById("custom-bg-img")) { currentKey = ""; updateBackground(true); }
}
for (const method of ["pushState", "replaceState"]) {
const original = history[method];
history[method] = function (...args) { const result = original.apply(this, args); checkRoute(); return result; };
}
addEventListener("popstate", checkRoute);
addEventListener("hashchange", checkRoute);
setInterval(checkRoute, 1000);
new MutationObserver(() => { if (!document.getElementById("custom-bg-img")) { currentKey = ""; updateBackground(true); } }).observe(document.documentElement, { childList: true, subtree: true });
updateBackground(true);
})();
4.0(警告,此版本在切换标页签时不会暂停)
// ==UserScript==
// @name oiClass 自定义背景
// @namespace http://tampermonkey.net/
// @version 9.1
// @description oiClass 图片/B站视频背景
// @author You
// @match https://oiclass.com/*
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @connect api.bilibili.com
// @run-at document-idle
// ==/UserScript==
(function () {
"use strict";
// ===== 配置区域:新增背景时复制一个对象 =====
const BG_CONFIG = [
{
path: "/record/",
type: "image",
img: "https://static.kivo.wiki/images/gallery/1.%E4%B8%BB%E7%BA%BF%E5%89%A7%E6%83%85CG/%E6%9C%80%E7%BB%88%E7%AF%87/BG_CS_S1Final_77.jpg",
blur: "0.1px",
speed: 1
},
{
path: "/user/",
type: "image",
img: "https://static.kivo.wiki/images/gallery/B2.%E6%9C%AC%E5%9C%B0%E5%8C%96CG/%E7%AE%80%E4%B8%AD%E6%9C%AC%E5%9C%B0%E5%8C%96/bg_aronaroom_night.jpg",
blur: "1px",
speed: 1
}
];
// 默认背景:修改 img 为需要解析的 B 站 BV 号
const DEFAULT_BG = {
type: "bilibili",
img: "BV1U94y1K7ZL",
blur: "1px",
speed: 1.0
};
// 视频解析或播放失败时显示的备用图片
const FALLBACK_BG = {
img: "https://cdn.luogu.com.cn/upload/image_hosting/c4mir4q7.png",
blur: "1px"
};
//https://www.bilibili.com/video/BV1U94y1K7ZL/?spm_id_from=333.337.search-card.all.click
// ===== 样式:保留原版背景层级与毛玻璃效果 =====
GM_addStyle(`
#custom-bg-img{position:fixed!important;inset:0;width:100vw;height:100vh;overflow:hidden;background-color:#111;background-size:cover;background-position:center;background-repeat:no-repeat;transform:scale(1.08);z-index:-99999!important;pointer-events:none}
#custom-bg-img video{position:absolute;top:0;left:0;width:100%;height:100%;object-fit:cover;object-position:center;pointer-events:none}
body{background:transparent!important}
.slideout-panel,.slideout-overlay{background:rgba(22,28,36,0)!important}
.nav{background:rgba(18,22,28,.5)!important;backdrop-filter:blur(6px)}
.section{background:rgba(30,36,48,.5)!important;backdrop-filter:blur(4px)}
#custom-bg-audio{position:fixed;right:16px;bottom:16px;width:36px;height:36px;border-radius:50%;background:rgba(18,22,28,.65);color:#fff;font-size:18px;display:flex;align-items:center;justify-content:center;cursor:pointer;z-index:9999;user-select:none;backdrop-filter:blur(6px);border:1px solid rgba(255,255,255,.15);pointer-events:auto}
#custom-bg-audio:hover{background:rgba(40,48,60,.85)}
`);
function getBG() { return BG_CONFIG.find(x => location.pathname.includes(x.path)) || DEFAULT_BG; }
function biliRequest(url) {
return new Promise((resolve, reject) => GM_xmlhttpRequest({
method: "GET", url, headers: { Referer: "https://www.bilibili.com/" }, timeout: 12000,
onload: r => { try { resolve(JSON.parse(r.responseText)); } catch (e) { reject(e); } },
onerror: reject, ontimeout: reject
}));
}
function getBVID(value) { return String(value).match(/BV[a-zA-Z0-9]{10}/)?.[0] || null; }
// 逐级尝试清晰度;B站接口实际返回画质仍受账号权限及视频本身限制
async function parseBilibili(value) {
const bv = getBVID(value);
if (!bv) throw Error("BV号无效");
const info = await biliRequest("https://api.bilibili.com/x/web-interface/view?bvid=" + bv);
if (info.code !== 0 || !info.data?.cid) throw Error("获取视频信息失败");
const cid = info.data.cid;
for (const qn of [112, 80, 64, 32, 16]) {
const result = await biliRequest("https://api.bilibili.com/x/player/playurl?" + new URLSearchParams({
bvid: bv, cid: String(cid), qn: String(qn), fnval: "0", fnver: "0", fourk: "1", platform: "html5"
}));
if (result.code === 0 && result.data?.durl?.length) {
return result.data.durl.flatMap(item => [item.url, ...(item.backup_url || [])]);
}
}
throw Error("没有可用的 MP4 视频流");
}
function getBox() {
let box = document.getElementById("custom-bg-img");
if (!box) { box = document.createElement("div"); box.id = "custom-bg-img"; document.body.prepend(box); }
return box;
}
function showImage(bg) {
const box = getBox();
box.replaceChildren();
box.style.filter = `blur(${bg.blur || "0px"})`;
box.style.backgroundImage = `url("${bg.img}")`;
}
let bgMuted = true; // 全局静音状态,默认静音
function applyMuted(video) {
video.muted = bgMuted;
video.defaultMuted = bgMuted;
video.volume = 1;
}
function playVideo(urls, speed, requestId) {
const box = getBox();
let index = 0;
function next() {
if (requestId !== activeRequest) return;
if (index >= urls.length) { showImage(FALLBACK_BG); return; }
const video = document.createElement("video");
video.src = urls[index++];
video.autoplay = true; video.loop = true;
applyMuted(video); // 应用当前静音状态
video.playsInline = true; video.preload = "auto";
video.playbackRate = Math.max(0.25, Math.min(Number(speed) || 1, 4));
video.onerror = () => { video.remove(); next(); };
box.replaceChildren(video);
const promise = video.play();
if (promise) promise.catch(() => { if (video.isConnected) { video.remove(); next(); } });
}
next();
}
let activeRequest = 0;
let currentKey = "";
async function updateBackground(force = false) {
if (!document.body) return;
const bg = getBG();
const key = `${bg.type}|${bg.img}|${bg.blur}|${bg.speed}`;
if (!force && key === currentKey && document.getElementById("custom-bg-img")) return;
currentKey = key;
const requestId = ++activeRequest;
const box = getBox();
box.replaceChildren();
box.style.backgroundImage = "none";
box.style.filter = `blur(${bg.blur || "0px"})`;
if (bg.type === "image") { showImage(bg); return; }
try {
const urls = await parseBilibili(bg.img);
if (requestId !== activeRequest) return;
playVideo(urls, bg.speed, requestId);
} catch (error) {
if (requestId !== activeRequest) return;
console.warn("[oiClass背景] B站解析失败:", error);
showImage(FALLBACK_BG);
}
ensureAudioBtn(); // ← 加这一行
}
let lastURL = location.href;
function checkRoute() {
if (location.href !== lastURL) { lastURL = location.href; updateBackground(true); }
else if (!document.getElementById("custom-bg-img")) { currentKey = ""; updateBackground(true); }
}
for (const method of ["pushState", "replaceState"]) {
const original = history[method];
history[method] = function (...args) { const result = original.apply(this, args); checkRoute(); return result; };
}
addEventListener("popstate", checkRoute);
addEventListener("hashchange", checkRoute);
setInterval(checkRoute, 1000);
new MutationObserver(() => { if (!document.getElementById("custom-bg-img")) { currentKey = ""; updateBackground(true); } }).observe(document.documentElement, { childList: true, subtree: true });
function getAudioBtn() {
let btn = document.getElementById("custom-bg-audio");
if (!btn) {
btn = document.createElement("div");
btn.id = "custom-bg-audio";
btn.textContent = bgMuted ? "🔇" : "🔊";
btn.title = "切换背景视频声音";
btn.addEventListener("click", () => {
bgMuted = !bgMuted;
btn.textContent = bgMuted ? "🔇" : "🔊";
const video = document.querySelector("#custom-bg-img video");
if (video) {
applyMuted(video);
// 用户手势触发,重新 play 以解除自动播放策略限制
const p = video.play();
if (p) p.catch(() => {});
}
});
document.body.appendChild(btn);
}
return btn;
}
// 页面加载及每次背景更新后确保按钮存在
function ensureAudioBtn() {
if (!document.body) return;
const btn = getAudioBtn();
btn.textContent = bgMuted ? "🔇" : "🔊";
}
ensureAudioBtn();
updateBackground(true);
})();
其他
// 🎵 歌曲列表
const PLAYLIST=[
{
name:"Constant Moderato - ミツキヨ",
url:"http://music.163.com/song/media/outer/url?id=2093257373.mp3",
cover:"http://p2.music.126.net/aZ5o_RJeFf4yv7VbUsf8qQ==/109951169003496957.jpg?param=300x300"
},
{
name:"MX Adventure - ミツキヨ",
url:"http://music.163.com/song/media/outer/url?id=2093257353.mp3",
cover:"http://p2.music.126.net/aZ5o_RJeFf4yv7VbUsf8qQ==/109951169003496957.jpg?param=300x300"
},
{
name:"Party time - ミツキヨ",
url:"http://music.163.com/song/media/outer/url?id=2093257536.mp3",
cover:"http://p1.music.126.net/aZ5o_RJeFf4yv7VbUsf8qQ==/109951169003496957.jpg?param=300x300"
},
{
name:"Pixel Time - ミツキヨ",
url:"http://music.163.com/song/media/outer/url?id=2098473565.mp3",
cover:"http://p2.music.126.net/VuNnmdufww-wGkHLQH-wsA==/109951169045277384.jpg?param=300x300"
},
{
name:"RE Aoharu - Nor",
url:"http://music.163.com/song/media/outer/url?id=2098478355.mp3",
cover:"http://p2.music.126.net/0OY08L09cF4UMVnRuHK_BQ==/109951169045313754.jpg?param=300x300"
}
];