// ==UserScript== // @name B站哔哩哔哩 - 评论楼层自动滚动 // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author Str_i // @match https://www.bilibili.com/video/* // @icon https://www.google.com/s2/favicons?sz=64&domain=bilibili.com // @grant none // ==/UserScript== (function() { 'use strict'; // 创建一个观察器实例 const observer = new MutationObserver(function(mutations) { // 遍历所有的变化记录 for (const mutation of mutations) { // 如果有新的节点添加到页面 if (mutation.addedNodes.length > 0) { // 遍历新节点 mutation.addedNodes.forEach(nodes => { // 如果新节点是评论 if(nodes.className == "reply-item"){ // 尝试获取 `点击查看` 那一行的节点 const view_more_defalut = nodes.getElementsByClassName("view-more-default"); // 如果 `点击查看` 那一行的节点存在 if (view_more_defalut.length > 0) { // 遍历 节点 for(let i = 0; i < view_more_defalut.length; i++) { // 如果评论回复数量大于10 if(view_more_defalut[i].children[0].innerText.match(/[1-9]\d*/)[0] > 10) { // 添加点击事件 nodes.addEventListener('click', function(event) { // 如果点击的是 `上一页` `页码` `下一页` if (event.target && (event.target.className == "pagination-btn" || event.target.className.includes("pagination-page-number"))) { // 滚动到指定节点 nodes.scrollIntoView({ behavior: 'smooth', }); } }); } } } } }) } } }); // 配置观察选项 const config = { childList: true, subtree: true }; // 传入目标节点和观察选项 observer.observe(document.body, config); })();