賣貨便-"交易規範及慎防詐騙提醒"彈跳視窗之自動點擊

自動點"我知道了"

// ==UserScript==
// @name         賣貨便-"交易規範及慎防詐騙提醒"彈跳視窗之自動點擊
// @namespace    http://tampermonkey.net/
// @version      2025-02-24
// @description  自動點"我知道了"
// @author       紫弦
// @match        https://myship.7-11.com.tw/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=7-11.com.tw
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function clickConfirmButton() {
        let modal = document.getElementById('BulletinModal_4');
        if (!modal) return;

        let confirmButton = modal.querySelector('button, .btn, .confirm');
        if (confirmButton) {
            confirmButton.click();
            console.log('已自動點擊「我知道了」');
        }
    }

    // **使用 setInterval 每 1ms 檢查一次,確保更快點擊**
    let interval = setInterval(() => {
        if (document.getElementById('BulletinModal_4')) {
            clickConfirmButton();
        }
    }, 1); // 每 1ms 檢查一次,比 MutationObserver 觸發更快

    // **使用 MutationObserver 監聽 BulletinModal_4 是否加入 DOM**
    const observer = new MutationObserver((mutationsList) => {
        for (let mutation of mutationsList) {
            if (mutation.addedNodes.length) {
                let modal = document.getElementById('BulletinModal_4');
                if (modal) {
                    clickConfirmButton();
                }
            }
        }
    });

    // **只監聽 body 內部的子元素變化**
    observer.observe(document.body, { childList: true, subtree: false });

})();