小红书自动关闭登录窗

自动检测并关闭小红书的登录弹窗

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         小红书自动关闭登录窗
// @namespace    http://tampermonkey.net/
// @version      3.0
// @description  自动检测并关闭小红书的登录弹窗
// @author       icescat
// @match        *://*.xiaohongshu.com/*
// @grant        none
// @run-at       document-body
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

   // 使用MutationObserver监听DOM变化
var observer = new MutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
        if (!mutation.addedNodes) return;

        // 对于每个添加的节点,检查是否存在关闭按钮
        for (var i = 0; i < mutation.addedNodes.length; i++) {
            var node = mutation.addedNodes[i];
            // 尝试匹配关闭按钮
            var closeButton = node.querySelector ? node.querySelector('div.icon-btn-wrapper.button.close, .icon-btn-wrapper.close-button') : null;
            if (closeButton) {
                closeButton.click();
                // 关闭按钮点击后,断开observer观察,避免不必要的性能消耗
                observer.disconnect();
                return;
            }
        }
    });
});

// 配置observer监视的内容
var config = {
    childList: true,
    subtree: true
};

// 开始对body元素及其子元素进行监视
observer.observe(document.body, config);

})();