// ==UserScript== // @name B站直播间屏蔽底部礼物栏 // @name:zh B站直播间屏蔽底部礼物栏 // @namespace https://live.bilibili.com/ // @version 1.0.0 // @description 隐藏B站网页端直播间下方的礼物快捷栏(防误触),同时保留左侧工坊订单、天选时刻等活动入口;网页全屏/全屏均生效。脚本菜单可临时切换显示。 // @author you // @match *://live.bilibili.com/* // @run-at document-start // @grant GM_registerMenuCommand // @license MIT // ==/UserScript== (function () { 'use strict'; // 需要隐藏的:礼物控制区的“右侧部分”(礼物图标、大航海入口、充值电池等) // 保留 .left-part-ctnr(工坊订单、天选时刻等活动入口)以及与之平级的 .ts-dot-2(天选浮标) const HIDE_CSS = ` #gift-control-vm .section.right-part, #gift-control-vm .right-part { display: none !important; } `; const STYLE_ID = '__us_hide_bili_gift_bar__'; let hidden = true; function getStyleEl() { let el = document.getElementById(STYLE_ID); if (!el) { el = document.createElement('style'); el.id = STYLE_ID; (document.head || document.documentElement).appendChild(el); } return el; } function render() { getStyleEl().textContent = hidden ? HIDE_CSS : ''; } function toggle() { hidden = !hidden; render(); try { GM_registerMenuCommand( hidden ? '✅ 礼物栏已屏蔽(点击恢复显示)' : '⛔ 礼物栏已显示(点击重新屏蔽)', toggle ); } catch (e) { /* 忽略菜单更新失败 */ } } // 首次注入(document-start 时 documentElement 一定存在) render(); // 兜底:若页面脚本移除了注入的 style,则自动补回 new MutationObserver(() => { if (!document.getElementById(STYLE_ID)) render(); }).observe(document.documentElement, { childList: true, subtree: true }); // 菜单开关:需要送礼物时可临时恢复礼物栏 try { GM_registerMenuCommand('✅ 礼物栏已屏蔽(点击恢复显示)', toggle); } catch (e) { /* 某些环境无菜单 API */ } })();