以下是一个使用油猴脚本的示例代码,可以监听并修改网页上符合要求的 div 元素的点击事件,实现回到网页顶部的功能:

// ==UserScript==
// @name         Scroll to Top
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Scroll to top when clicking on a specific div element with specified class and style
// @author       Your Name
// @match        http://example.com/*    // 替换成需要应用脚本的网页地址
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // 监听点击事件
    document.addEventListener('click', function(event) {
        var target = event.target;
        
        // 判断点击的元素是否符合条件
        if (target.classList.contains('feedback-ball-wrapper') && target.classList.contains('react-draggable') && target.classList.contains('react-draggable-dragged') && target.style.transform === 'translate(0px, 0px)') {
            // 回到网页顶部
            window.scrollTo(0, 0);
        }
    });
})();

请注意,在脚本中的 @match 行,你需要将 http://example.com/* 替换为你需要应用脚本的网页地址。同时,确保你已经安装了油猴扩展程序,并在其中创建一个新的油猴脚本,然后将以上代码复制粘贴到脚本编辑器中保存即可。

这是一个新需求请给我代码通过油猴脚本监听获取网页上class为feedback-ball-wrapper react-draggable react-draggable-draggedstyle为transform translate0px 0px;的div将此div的事件改为点击这个div则可以实现回到网页顶部

原文地址: https://www.cveoy.top/t/topic/i4cN 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录