// ==UserScript== // ==UserScript== // @name b站累计观看计数器(b站蓝/仅计数) // @icon https://www.bilibili.com/favicon.ico // @version 1.9.5 // @description B站蓝色mini计数器 // @author 你的名字 // @match *://*.bilibili.com/video/* // @match *://*.bilibili.com/video/*?* // @grant GM_getValue // @grant GM_setValue // @run-at document-body // ==/UserScript== // ==/UserScript== (function() { 'use strict'; // B站蓝配置 const CONFIG = { bgColor: 'rgba(0, 161, 214, 0.9)', // B站蓝 textColor: 'white', // 白字 fontSize: '12px', // 清晰字号 borderRadius: '8px', // 适中圆角 padding: '4px 12px', // 舒适内边距 fontWeight: '500', boxShadow: '0 2px 6px rgba(0,161,214,0.2)', backdropFilter: 'blur(6px)', border: '1px solid rgba(0, 161, 214, 0.3)' }; // 1. 获取或初始化计数 function getAndIncrementCount(bvId) { let count = GM_getValue(bvId, 0); count++; GM_setValue(bvId, count); return count; } // 2. 创建B站蓝气泡 function createBubbleElement(bvId, count) { const bubble = document.createElement('div'); bubble.id = 'bili-watch-counter-bubble'; // B站蓝样式 bubble.style.cssText = ` display: inline-block; background: ${CONFIG.bgColor}; color: ${CONFIG.textColor}; font-size: ${CONFIG.fontSize}; padding: ${CONFIG.padding}; border-radius: ${CONFIG.borderRadius}; font-weight: ${CONFIG.fontWeight}; box-shadow: ${CONFIG.boxShadow}; backdrop-filter: ${CONFIG.backdropFilter}; border: ${CONFIG.border}; margin: 4px; vertical-align: middle; transition: all 0.2s ease; line-height: 1.3; white-space: nowrap; `; // 保持"观看 X 次"文字 bubble.innerHTML = `观看 ${count} 次`; // 悬停效果 bubble.onmouseenter = () => { bubble.style.opacity = '0.95'; bubble.style.transform = 'scale(1.03)'; bubble.style.boxShadow = '0 3px 8px rgba(0,161,214,0.3)'; }; bubble.onmouseleave = () => { bubble.style.opacity = '1'; bubble.style.transform = 'scale(1)'; bubble.style.boxShadow = CONFIG.boxShadow; }; return bubble; } // 3. 主逻辑 function main() { const url = window.location.href; const bvMatch = url.match(/\/(BV[a-zA-Z0-9]+)/); if (!bvMatch) return; const bvId = bvMatch[1]; const count = getAndIncrementCount(bvId); // 移除旧气泡 const oldBubble = document.getElementById('bili-watch-counter-bubble'); if (oldBubble) oldBubble.remove(); const bubble = createBubbleElement(bvId, count); // 智能插入位置 const insertionPoints = [ // 1. 视频标题右侧 () => { const title = document.querySelector('.video-title, h1.title'); if (title && title.parentNode) { title.parentNode.insertBefore(bubble, title.nextSibling); bubble.style.marginLeft = '10px'; return true; } return false; }, // 2. 视频信息行 () => { const infoRow = document.querySelector('.video-data, .video-toolbar, .video-info'); if (infoRow) { infoRow.prepend(bubble); bubble.style.marginRight = '12px'; return true; } return false; }, // 3. 固定右上角(备用) () => { bubble.style.position = 'fixed'; bubble.style.top = '80px'; bubble.style.right = '20px'; bubble.style.zIndex = '9999'; document.body.appendChild(bubble); return true; } ]; for (let attempt of insertionPoints) { if (attempt()) { console.log(`🔵 B站蓝计数器:${bvId} 观看第${count}次`); return; } } } // 4. 延迟执行 setTimeout(main, 1800); })();