// ==UserScript== // @name Bilibili 评论区等级过滤器 // @namespace https://github.com/Misasasasasaka // @version 2.1 // @description 优雅地过滤Bilibili评论区,支持拖动调节等级阈值与自动隐藏功能 // @author Misasasasasaka // @match https://www.bilibili.com/* // @grant GM_setValue // @grant GM_getValue // @grant GM_addStyle // @grant unsafeWindow // @license MIT // @downloadURL https://update.greasyfork.icu/scripts/533316/Bilibili%20%E8%AF%84%E8%AE%BA%E5%8C%BA%E7%AD%89%E7%BA%A7%E8%BF%87%E6%BB%A4%E5%99%A8.user.js // @updateURL https://update.greasyfork.icu/scripts/533316/Bilibili%20%E8%AF%84%E8%AE%BA%E5%8C%BA%E7%AD%89%E7%BA%A7%E8%BF%87%E6%BB%A4%E5%99%A8.meta.js // ==/UserScript== ;(function() { 'use strict'; // 存储键和全局配置 const CONFIG = { storageKey: 'bili_comment_level_threshold', defaultThreshold: 0, colors: { primary: '#fb7299', // B站粉色 secondary: '#23ade5', // B站蓝色 background: '#ffffff', text: '#333333', border: '#e1e1e1' }, animation: { duration: '0.3s' } }; // 获取用户设置 let threshold = GM_getValue(CONFIG.storageKey, CONFIG.defaultThreshold); // 核心样式定义 const styleDefinition = ` @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500&display=swap'); #bili-level-filter-container { position: fixed; bottom: 20px; right: 20px; z-index: 9999; font-family: 'Noto Sans SC', sans-serif; transition: all ${CONFIG.animation.duration} ease; opacity: 0.3; } #bili-level-filter-container:hover { opacity: 1; } #bili-level-filter-container.panel-open { opacity: 1; } #bili-level-filter-toggle { width: 36px; height: 36px; background: ${CONFIG.colors.primary}; border-radius: 50%; box-shadow: 0 2px 8px rgba(0,0,0,0.15); color: white; border: none; cursor: pointer; display: flex; align-items: center; justify-content: center; outline: none; transition: transform ${CONFIG.animation.duration} ease, background ${CONFIG.animation.duration} ease; position: relative; z-index: 10001; } #bili-level-filter-toggle:hover { background: ${CONFIG.colors.secondary}; transform: scale(1.1); } #bili-level-filter-toggle svg { width: 18px; height: 18px; fill: white; } #bili-level-filter-panel { position: absolute; bottom: 50px; right: 0; background: ${CONFIG.colors.background}; border-radius: 8px; box-shadow: 0 3px 15px rgba(0,0,0,0.12); padding: 16px; width: 260px; border: 1px solid ${CONFIG.colors.border}; display: flex; flex-direction: column; gap: 12px; opacity: 0; visibility: hidden; transform: translateY(10px); transition: opacity ${CONFIG.animation.duration} ease, visibility ${CONFIG.animation.duration} ease, transform ${CONFIG.animation.duration} ease; } #bili-level-filter-panel.visible { opacity: 1; visibility: visible; transform: translateY(0); } #bili-level-filter-panel h4 { margin: 0 0 8px; color: ${CONFIG.colors.primary}; display: flex; align-items: center; font-size: 15px; font-weight: 500; } #bili-level-filter-panel h4 svg { margin-right: 6px; } .level-filter-row { display: flex; flex-direction: column; margin-bottom: 12px; } .level-filter-row label { display: block; margin-bottom: 6px; font-size: 13px; color: ${CONFIG.colors.text}; } .slider-container { display: flex; align-items: center; gap: 10px; } .range-slider { flex: 1; height: 5px; -webkit-appearance: none; appearance: none; background: #e6e6e6; outline: none; border-radius: 3px; } .range-slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 16px; height: 16px; background: ${CONFIG.colors.primary}; border-radius: 50%; cursor: pointer; transition: all 0.15s ease; } .range-slider::-webkit-slider-thumb:hover { transform: scale(1.2); background: ${CONFIG.colors.secondary}; } .value-display { background: ${CONFIG.colors.primary}22; min-width: 35px; height: 24px; border-radius: 4px; display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 500; color: ${CONFIG.colors.primary}; } .button-row { display: flex; justify-content: space-between; margin-top: 8px; } .bili-btn { padding: 6px 14px; border: none; border-radius: 4px; font-size: 13px; cursor: pointer; transition: all 0.2s ease; font-weight: 500; font-family: inherit; } .bili-btn-primary { background: ${CONFIG.colors.primary}; color: white; } .bili-btn-primary:hover { background: #e45f84; transform: translateY(-1px); box-shadow: 0 2px 5px rgba(0,0,0,0.1); } .bili-btn-secondary { background: transparent; color: ${CONFIG.colors.text}; border: 1px solid #ddd; } .bili-btn-secondary:hover { border-color: #ccc; background: #f9f9f9; } .filter-status { padding: 6px 10px; border-radius: 4px; background: #f0f9ff; border: 1px solid #e0f0ff; font-size: 12px; color: #0077cc; margin-top: 6px; text-align: center; transition: all ${CONFIG.animation.duration} ease; } .filter-active { background: #ecfaf0; border: 1px solid #d5f0db; color: #00a651; } #bili-toast { position: fixed; bottom: 80px; right: 20px; background: rgba(0,0,0,0.7); color: white; padding: 8px 16px; border-radius: 4px; font-size: 13px; opacity: 0; transform: translateY(10px); transition: all 0.3s ease; z-index: 10000; pointer-events: none; } #bili-toast.show { opacity: 1; transform: translateY(0); } .hidden { display: none !important; } @media (max-width: 768px) { #bili-level-filter-panel { width: 220px; } } `; // 创建并添加插件UI function createFilterUI() { // 添加样式 GM_addStyle(styleDefinition); // 创建主容器 const container = document.createElement('div'); container.id = 'bili-level-filter-container'; // 添加切换按钮(小图标按钮) const toggleButton = document.createElement('button'); toggleButton.id = 'bili-level-filter-toggle'; toggleButton.setAttribute('aria-label', '打开评论过滤器设置'); toggleButton.innerHTML = ` `; // 创建设置面板 const panel = document.createElement('div'); panel.id = 'bili-level-filter-panel'; // 面板标题和图标 panel.innerHTML = `