您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
:zh-cn
当前为
// ==UserScript== // @name bilibili增强 // @namespace http://tampermonkey.net/ // @version 2024-05-29 // @description :zh-cn // @author zyieng // @match https://www.bilibili.com/* // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== // @grant none // @license MIT // ==/UserScript== (function() { 'use strict'; // Your code here... // 目标元素的选择器 var targetSelector = '.cur-page'; // 根据实际情况修改选择器 // 定义观察函数 function observeInnerHTMLChange(selector, callback) { var targetElement = document.querySelector(selector); if (!targetElement) { console.error(`Element with selector "${selector}" not found.`); return; } // 创建MutationObserver实例并传入回调函数 var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if (mutation.type === 'childList' || mutation.type === 'subtree' || mutation.type === 'characterData') { callback(); } }); }); // 配置MutationObserver var config = { childList: true, characterData: true, subtree: true }; // 启动观察 observer.observe(targetElement, config); } // 定义当innerHTML变化时触发的回调函数 function onInnerHTMLChange() { console.log('InnerHTML content has changed.'); // 你可以在这里调用其他方法或进行其他操作 updateProgress(); } // 调用观察函数 observeInnerHTMLChange(targetSelector, onInnerHTMLChange); // 定义更新进度的函数 function updateProgress() { // 获取目标元素 var curPageElement = document.querySelector('.cur-page'); if (curPageElement) { // 获取父元素 var parentElement = curPageElement.parentNode; // 检查是否已经有进度百分比元素,避免重复添加 var existingProgressElement = parentElement.querySelector('.progress-percentage'); if (existingProgressElement) { existingProgressElement.remove(); } // 获取元素内容,假设内容格式为 "12/123" var content = curPageElement.textContent.trim(); // 正则表达式提取当前观看的视频序列和总视频数量 var match = content.match(/(\d+)\/(\d+)/); if (match) { var current = parseInt(match[1], 10); var total = parseInt(match[2], 10); // 计算进度百分比 var progress = (current / total) * 100; // 创建一个新的span元素来显示百分比 var progressElement = document.createElement('span'); progressElement.className = 'progress-percentage'; progressElement.style.marginLeft = '10px'; progressElement.style.color = 'green'; // 可以根据需要调整样式 progressElement.textContent = `(${progress.toFixed(2)}%)`; // 将新的span元素添加到cur-page元素的父元素 parentElement.appendChild(progressElement); } } } // 初始调用以确保在脚本加载时立即执行一次 updateProgress(); })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址