// ==UserScript== // @name bili直播助手 // @namespace https://github.com/wakefun // @author 醒悦哥哥 // @description 浏览器去除直播页面遮挡块。绕过b站强制直播姬开播限制,修复OBS无法获取推流码的问题。自动点赞功能。 // @version 3.1.0 // @match https://link.bilibili.com/p/center/index* // @match https://live.bilibili.com/* // @icon https://i1.hdslb.com/bfs/face/ec3c19295a9ce487bdf670174fd7eaa1da690923.jpg@256w_256h.jpg // @run-at document-idle // @grant none // ==/UserScript== (function () { 'use strict'; const MASK_ID = 'web-player-module-area-mask-panel'; const START_LIVE_URL = 'room/v1/Room/startLive'; // --- 去除直播播放器遮挡 --- function observeMask() { const player = document.getElementById('live-player'); if (!player) return; // 先清除已存在的遮挡 document.getElementById(MASK_ID)?.remove(); new MutationObserver((mutations) => { for (const { addedNodes } of mutations) { for (const node of addedNodes) { if (node.nodeType !== Node.ELEMENT_NODE) continue; const mask = node.id === MASK_ID ? node : node.querySelector?.(`#${MASK_ID}`); if (mask) { mask.remove(); console.log('[bili-live] 已去除遮挡'); } } } }).observe(player, { childList: true, subtree: true }); } // DOM 可能尚未完全就绪,延迟重试 if (document.getElementById('live-player')) { observeMask(); } else { const retry = setInterval(() => { if (document.getElementById('live-player')) { clearInterval(retry); observeMask(); } }, 500); // 30s 后放弃 setTimeout(() => clearInterval(retry), 30000); } // --- 自动点赞(挂在礼物区第一个位置) --- const AUTO_LIKE_MAX = 1000; const AUTO_LIKE_INTERVAL = 666; const LIKE_WRAPPER_ID = '__auto-like-gift__'; const GIFT_LIST_SELECTOR = '#gift-control-vm .gift-list'; const LIKE_WATCH_INTERVAL = 3000; const LIKE_STYLE_ID = '__auto-like-gift-style__'; const LIKE_THUMB_SVG = ''; const LIKE_HEART_SVG = ''; let _likeTimer = null; let _likeCount = 0; let _likeObserver = null; let _likeObserveRoot = null; let _likeWatchTimer = null; function ensureLikeStyle() { if (document.getElementById(LIKE_STYLE_ID)) return; const style = document.createElement('style'); style.id = LIKE_STYLE_ID; style.textContent = ` #${LIKE_WRAPPER_ID} { position: relative; display: inline-block; vertical-align: top; width: 78px; height: 84px; cursor: pointer; user-select: none; -webkit-user-select: none; } #${LIKE_WRAPPER_ID} .al-badge { position: relative; width: 34px; height: 34px; margin: 7px auto 0; border-radius: 50%; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #ff5f8f 0%, #ff9d5c 100%); box-shadow: 0 4px 12px rgba(255, 95, 143, .38), 0 0 0 4px rgba(255, 95, 143, .12); transition: transform .18s ease, box-shadow .18s ease; } #${LIKE_WRAPPER_ID}:hover .al-badge { transform: scale(1.08); box-shadow: 0 6px 16px rgba(255, 95, 143, .5), 0 0 0 5px rgba(255, 95, 143, .14); } #${LIKE_WRAPPER_ID} .al-badge svg { width: 19px; height: 19px; fill: #fff; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .15)); } #${LIKE_WRAPPER_ID}.al-running .al-badge { animation: __al-pulse 1.4s ease-in-out infinite; } #${LIKE_WRAPPER_ID} .al-label { margin: 3px 0 0; color: #18191c; font-size: 12px; line-height: 17px; text-align: center; white-space: nowrap; } #${LIKE_WRAPPER_ID} .al-count { color: #9499a0; font-size: 10px; line-height: 14px; text-align: center; white-space: nowrap; } #${LIKE_WRAPPER_ID}.al-running .al-count { color: #ff5f8f; } @keyframes __al-pulse { 0%, 100% { box-shadow: 0 4px 12px rgba(255, 95, 143, .38), 0 0 0 3px rgba(255, 95, 143, .12); } 50% { box-shadow: 0 4px 18px rgba(255, 95, 143, .6), 0 0 0 8px rgba(255, 95, 143, .08); } } @keyframes __al-ripple { from { transform: scale(.86); opacity: .75; } to { transform: scale(1.9); opacity: 0; } } @keyframes __al-float { 0% { opacity: 0; transform: translate(0, 2px) scale(.5); } 18% { opacity: 1; transform: translate(calc(var(--dx) / 3), -8px) scale(1.05); } 100% { opacity: 0; transform: translate(var(--dx), -54px) scale(.8); } } .__auto-like-ripple { position: absolute; inset: -4px; border: 2px solid rgba(255, 95, 143, .7); border-radius: 50%; pointer-events: none; animation: __al-ripple .55s ease-out forwards; } .__auto-like-particle { position: fixed; width: 16px; height: 16px; z-index: 2147483647; pointer-events: none; animation: __al-float .95s ease-out forwards; will-change: transform, opacity; } .__auto-like-particle svg { width: 100%; height: 100%; fill: #ff5f8f; filter: drop-shadow(0 1px 2px rgba(255, 95, 143, .45)); } .__auto-like-particle:nth-of-type(2n) svg { fill: #ff9d5c; } `; document.head.appendChild(style); } function simulateLikeKey() { const opts = { key: 'k', code: 'KeyK', bubbles: true }; document.dispatchEvent(new KeyboardEvent('keydown', opts)); document.dispatchEvent(new KeyboardEvent('keyup', opts)); } function spawnLikeParticle() { const badge = document.querySelector(`#${LIKE_WRAPPER_ID} .al-badge`); if (!badge) return; const rect = badge.getBoundingClientRect(); const particle = document.createElement('div'); particle.className = '__auto-like-particle'; particle.innerHTML = LIKE_HEART_SVG; particle.style.left = `${Math.round(rect.left + rect.width / 2 - 8 + (Math.random() * 10 - 5))}px`; particle.style.top = `${Math.round(rect.top + 2)}px`; particle.style.setProperty('--dx', `${Math.round(Math.random() * 26 - 13)}px`); document.body.appendChild(particle); const remove = () => particle.remove(); particle.addEventListener('animationend', remove); setTimeout(remove, 1500); const ripple = document.createElement('span'); ripple.className = '__auto-like-ripple'; badge.appendChild(ripple); setTimeout(() => ripple.remove(), 650); } function updateLikeButton() { const wrapper = document.getElementById(LIKE_WRAPPER_ID); if (!wrapper) return; const label = wrapper.querySelector('.al-label'); const count = wrapper.querySelector('.al-count'); if (label) label.textContent = _likeTimer ? '自动点赞中' : '自动点赞'; if (count) count.textContent = (_likeTimer || _likeCount) ? `${_likeCount} 次` : '点击开始'; wrapper.classList.toggle('al-running', !!_likeTimer); wrapper.title = _likeTimer ? '点击停止自动点赞(发弹幕时会自动暂停)' : '点击开始自动点赞'; } function stopLike() { clearInterval(_likeTimer); _likeTimer = null; console.log(`[bili-live] 自动点赞停止,共点赞 ${_likeCount} 次`); updateLikeButton(); } function isLikePaused() { const el = document.activeElement; return !!el && (el.tagName === 'INPUT' || el.tagName === 'TEXTAREA' || el.isContentEditable); } function startLike() { _likeCount = 0; _likeTimer = setInterval(() => { if (_likeCount >= AUTO_LIKE_MAX) return stopLike(); if (isLikePaused()) return; simulateLikeKey(); _likeCount++; updateLikeButton(); spawnLikeParticle(); }, AUTO_LIKE_INTERVAL); updateLikeButton(); } function injectLikeBtn() { if (document.getElementById(LIKE_WRAPPER_ID)) return; const list = document.querySelector(GIFT_LIST_SELECTOR); if (!list) return; ensureLikeStyle(); const wrapper = document.createElement('div'); wrapper.id = LIKE_WRAPPER_ID; wrapper.className = 'gift-item dp-i-block p-relative v-top'; wrapper.innerHTML = `
自动点赞