吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 368|回复: 6
收起左侧

[其他求助] 帮忙制作油猴脚本,B站评论区点击下一页返回此楼层顶部

[复制链接]
q7634356 发表于 2024-2-2 16:24
35吾爱币
帮我制作一个油猴插件,我的需求是这样的:B站评论区某一个楼层里点击下一页返回此楼层顶部

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

Takitooru 发表于 2024-2-2 20:36
方便的话,大概什么位置截个图吧
 楼主| q7634356 发表于 2024-2-3 08:22
Takitooru 发表于 2024-2-2 20:36
方便的话,大概什么位置截个图吧



图一点击下一页后是图二的样子,我想点击下一页到自动回到图三的位置
的账号 发表于 2024-2-4 03:11
// ==UserScript==
// @name         B站楼层跳转
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @AuThor       You
// @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.children[0].innerText.match(/[1-9]\d*/)[0] > 10) {
                                    // 添加点击事件
                                    nodes.addEventListener('click', function(event) {
                                        // 如果点击的是 `下一页` 按钮
                                        if (event.target && event.target.className == "pagination-btn") {
                                            // 滚动到指定节点
                                            nodes.scrollIntoView({
                                                behavior: 'smooth',
                                            });
                                        }
                                    });
                                }
                            }
                        }
                    }
                })
            }
        }
    });

    // 配置观察选项
    const config = { childList: true, subtree: true };

    // 传入目标节点和观察选项
    observer.observe(document.body, config);

})();
 楼主| q7634356 发表于 2024-2-4 08:23
的账号 发表于 2024-2-4 03:11
// ==UserScript==
// @name         B站楼层跳转
// @namespace    http://tampermonkey.net/

点击下一页没反应呢
 楼主| q7634356 发表于 2024-2-4 11:04
已经有大神做出来了。分享一下

// ==UserScript==
// @name         B站翻页
// @namespace    http://tampermonkey.net/
// @version      3.5
// @description  try to take over the world!
// @AuThor       qq806350554
// @match        https://www.bilibili.com/video/*
// @require      https://code.jquery.com/jquery-3.6.1.js
// @require      https://scriptcat.org/lib/513/2.0.0/ElementGetter.js
// @Icon         https://www.google.com/s2/favicons?sz=64&domain=bilibili.com
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    var head = document.getElementsByTagName('head')[0];
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = 'https://code.jquery.com/jquery-3.6.1.js';
    head.appendChild(script);

    elmGetter.get('.reply-warp').then(div1 => {
        div1.addEventListener("DOMNodeInserted", function (event) {
            $(".view-more-pagination").click(function(){window.scrollTo(0,$(this).parent().parent().parent().parent().offset().top)})
        });

    });
})();
的账号 发表于 2024-2-4 13:52
q7634356 发表于 2024-2-4 08:23
点击下一页没反应呢

我自己测试没毛病哈哈 你有了就好了
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-16 17:46

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表