正文
增加 104 行删除 23 行
1234537 行未改动4344454647484950515253545556575859606171 行未改动13313413513613713813914050 行未改动19119219319419519619719819967 行未改动267268269270271272273274275241 行未改动全部展开517518519520521522523524525241 行未改动全部展开767768769770771772773774775241 行未改动全部展开10171018101910201021102210231024102547 行未改动107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105116 行未改动全部展开122212231224122512261227122812291230179 行未改动全部展开14101411141214131414141514161417141811 行未改动效果展示(deepseek/atcoder/QQ浏览器-新标签页/洛谷部分页面)37 行未改动- 2026.10.21- 更丝滑的背景转换。- 切换背景时的某些问题。- 按钮的修复。脚本----::::info[有点长]```javascript// ==UserScript==// @name 通用背景// @namespace https://www.luogu.com.cn/user/1486819// @version 1.3.0// @description 在大部分网站设置背景,支持上传/图床URL、手动/自动切换、可拖动按钮// @author ArknightsEndfield// @license MIT// @match *://*/*// @grant GM_addStyle// @run-at document-idle71 行未改动req.onerror = () => reject(req.error);});}async function dbGetAll() {const db = await openDB();const tx = db.transaction(STORE_NAME, 'readonly');const store = tx.objectStore(STORE_NAME);50 行未改动if (typeof media.data === 'string' && media.data.startsWith('data:')) {return media.data;}try {const blob = new Blob([media.data], { type: media.mime });return URL.createObjectURL(blob);} catch (e) {return null;}67 行未改动#ug-bg-panel.collapsed {opacity: 0;pointer-events: none;display: none;}#ug-bg-panel .row { display: flex; gap: 6px; margin: 6px 0; flex-wrap: wrap; align-items: center; }#ug-bg-panel .btn {padding: 6px 12px;border: none;241 行未改动全部展开if (parsed.intervalSeconds === undefined || parsed.intervalSeconds === null) parsed.intervalSeconds = DEFAULT_INTERVAL_SECONDS;return parsed;}} catch (e) {}return {selectedId: null,opacity: DEFAULT_OPACITY,blur: DEFAULT_BLUR,brightness: DEFAULT_BRIGHTNESS,241 行未改动全部展开switchTimer = setInterval(switchToNextBg, totalMs);updateAutoStatus(true, totalMs);} else {state.autoSwitch = false;saveState(state);updateAutoStatus(false, 0);}}}241 行未改动全部展开<button class="btn btn-primary btn-sm" id="ug-upload-video">🎬 视频</button><button class="btn btn-success btn-sm" id="ug-test-video">🎬 测试</button><button class="btn btn-danger btn-sm" id="ug-clear-all">清空</button></div><div class="hint">上传 ≤ 25MB · 点击页面播放视频 · 默认透明度 0.1</div><div style="margin-top:8px;display:flex;gap:6px;align-items:center;flex-wrap:wrap;"><input type="text" id="ug-remote-input" placeholder="图床" class="url-input"><button class="btn btn-success btn-sm" id="ug-remote-add">🌐 添加随机</button>47 行未改动panel.querySelector('#ug-panel-close').addEventListener('click', togglePanel);panel.querySelector('#ug-help-btn').addEventListener('click', showHelp);// 上传图片panel.querySelector('#ug-upload-img').addEventListener('click', () => {const inp = document.createElement('input');inp.type = 'file';inp.accept = 'image/*';inp.onchange = async e => {const f = e.target.files[0];if (!f) return;if (f.size > MAX_SIZE) {alert(`文件 ${formatSize(f.size)} 超过 25MB`);return;}try {const dataUrl = await fileToDataURL(f);const id = await dbSave(dataUrl, 'image', f.type);const state = loadState();state.selectedId = id;saveState(state);const all = await dbGetAll();const media = all.find(m => m.id === id);renderBg(media);await showPanel(state);showToast('✅ 图片已保存');} catch (err) {showToast('❌ 图片保存失败: ' + err.message);}};inp.click();});116 行未改动全部展开state.selectedId = null;saveState(state);renderBg(null);}await showPanel(state);});});// 透明度滑块179 行未改动全部展开showHelp();localStorage.setItem(SEEN_AD_KEY, 'true');}console.log('[初始化] 🎨 通用背景 v1.2.4 已启动');} catch (e) {console.error('[初始化] 启动失败:', e);}}11 行未改动1234567837 行未改动46474849505152535455565758596061626364656671 行未改动13813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217350 行未改动22422522622722822923023123223323423567 行未改动303304305306307308309310311241 行未改动全部展开553554555556557558559560561241 行未改动全部展开803804805806807808809810811241 行未改动全部展开10531054105510561057105810591060106147 行未改动110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186116 行未改动全部展开130313041305130613071308130913101311179 行未改动全部展开14911492149314941495149614971498149911 行未改动~~话说这玩意到底投哪个板块啊,投太多不会被封号吧qwq~~2026.11.27效果展示(deepseek/atcoder/QQ浏览器-新标签页/洛谷部分页面)---37 行未改动- 2026.10.21- 更丝滑的背景转换。- 切换背景时的某些问题。- 按钮的修复。- 2026.11.27- 可以一次性上传大量的图片,不用再一个一个上传了。然后给大家一个很好的图源。[出门右转](https://www.luogu.com.cn/article/ldmeupsj)脚本----::::info[有点长]```javascript// ==UserScript==// @name 通用背景(pro)// @namespace https://www.luogu.com.cn/user/1486819// @version 1.4.0// @description 在大部分网站设置背景,支持批量上传图片、上传视频/图床URL、手动/自动切换、可拖动按钮// @author XiArk// @license MIT// @match *://*/*// @grant GM_addStyle// @run-at document-idle71 行未改动req.onerror = () => reject(req.error);});}// 批量保存:所有图片共用一个 IndexedDB 事务,避免逐张打开事务、逐张刷新界面。async function dbSaveMany(items) {const db = await openDB();return new Promise((resolve, reject) => {const tx = db.transaction(STORE_NAME, 'readwrite');const store = tx.objectStore(STORE_NAME);const ids = [];let requestError = null;for (const item of items) {const req = store.add({data: item.data,type: item.type,mime: item.mime,timestamp: Date.now()});req.onsuccess = () => { ids.push(req.result); };req.onerror = () => {requestError = req.error || new Error('写入失败');};}tx.oncomplete = () => resolve(ids);tx.onerror = () => reject(requestError || tx.error || new Error('批量保存失败'));tx.onabort = () => reject(requestError || tx.error || new Error('批量保存已中止'));});}async function dbGetAll() {const db = await openDB();const tx = db.transaction(STORE_NAME, 'readonly');const store = tx.objectStore(STORE_NAME);50 行未改动if (typeof media.data === 'string' && media.data.startsWith('data:')) {return media.data;}try {// 新上传的图片直接以 Blob 存储,避免转成 Base64 带来的额外耗时和体积。const blob = media.data instanceof Blob? media.data: new Blob([media.data], { type: media.mime });return URL.createObjectURL(blob);} catch (e) {return null;}67 行未改动#ug-bg-panel.collapsed {opacity: 0;pointer-events: none;display: none;}#ug-bg-panel .row { display: flex; gap: 6px; margin: 6px 0; flex-wrap: wrap; align-items: center; }#ug-bg-panel .btn {padding: 6px 12px;border: none;241 行未改动全部展开if (parsed.intervalSeconds === undefined || parsed.intervalSeconds === null) parsed.intervalSeconds = DEFAULT_INTERVAL_SECONDS;return parsed;}} catch (e) {}return {selectedId: null,opacity: DEFAULT_OPACITY,blur: DEFAULT_BLUR,brightness: DEFAULT_BRIGHTNESS,241 行未改动全部展开switchTimer = setInterval(switchToNextBg, totalMs);updateAutoStatus(true, totalMs);} else {state.autoSwitch = false;saveState(state);updateAutoStatus(false, 0);}}}241 行未改动全部展开<button class="btn btn-primary btn-sm" id="ug-upload-video">🎬 视频</button><button class="btn btn-success btn-sm" id="ug-test-video">🎬 测试</button><button class="btn btn-danger btn-sm" id="ug-clear-all">清空</button></div><div class="hint">支持一次多选图片 · 单张 ≤ 25MB · 点击页面播放视频 · 默认透明度 0.1</div><div style="margin-top:8px;display:flex;gap:6px;align-items:center;flex-wrap:wrap;"><input type="text" id="ug-remote-input" placeholder="图床" class="url-input"><button class="btn btn-success btn-sm" id="ug-remote-add">🌐 添加随机</button>47 行未改动panel.querySelector('#ug-panel-close').addEventListener('click', togglePanel);panel.querySelector('#ug-help-btn').addEventListener('click', showHelp);// 批量上传图片:文件选择器支持多选,保存完成后只刷新一次面板。panel.querySelector('#ug-upload-img').addEventListener('click', () => {const inp = document.createElement('input');inp.type = 'file';inp.accept = 'image/*';inp.multiple = true;inp.onchange = async e => {const selected = Array.from(e.target.files || []);if (selected.length === 0) return;const validFiles = [];const rejected = [];for (const file of selected) {if (!file.type || !file.type.startsWith('image/')) {rejected.push(`${file.name}(不是图片)`);} else if (file.size > MAX_SIZE) {rejected.push(`${file.name}(${formatSize(file.size)},超过 25MB)`);} else {validFiles.push(file);}}if (validFiles.length === 0) {showToast(`❌ 没有可上传的图片(已跳过 ${rejected.length} 个文件)`, 3500);return;}const uploadBtn = panel.querySelector('#ug-upload-img');if (uploadBtn) {uploadBtn.disabled = true;uploadBtn.textContent = `⏳ 保存中 0/${validFiles.length}`;}try {// IndexedDB 可直接保存 Blob,无需逐张 FileReader 转 Base64。const ids = await dbSaveMany(validFiles.map(file => ({data: file,type: 'image',mime: file.type})));const state = loadState();const lastId = ids[ids.length - 1];state.selectedId = lastId;saveState(state);const all = await dbGetAll();const media = all.find(m => m.id === lastId);if (media) renderBg(media);await showPanel(state);let message = `✅ 已批量保存 ${ids.length} 张图片`;if (rejected.length) message += `,跳过 ${rejected.length} 个文件`;showToast(message, 3500);if (rejected.length) {console.warn('[背景脚本] 以下文件未上传:', rejected);}} catch (err) {console.error('[背景脚本] 批量图片保存失败:', err);showToast('❌ 批量图片保存失败: ' + (err.message || err), 4000);await showPanel(loadState());} finally {const currentBtn = document.querySelector('#ug-upload-img');if (currentBtn) {currentBtn.disabled = false;currentBtn.textContent = '📷 图片';}}};inp.click();});116 行未改动全部展开state.selectedId = null;saveState(state);renderBg(null);}await showPanel(state);});});// 透明度滑块179 行未改动全部展开showHelp();localStorage.setItem(SEEN_AD_KEY, 'true');}console.log('[初始化] 🎨 通用背景 v1.4.0 已启动');} catch (e) {console.error('[初始化] 启动失败:', e);}}11 行未改动