Greasy Fork

Greasy Fork is available in English.

右上の通知が居座る。クリックした時のみ消える。

Prevents notifications in Milky Way Idle from disappearing automatically, only hides on click.

// ==UserScript==
// @name         右上の通知が居座る。クリックした時のみ消える。
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Prevents notifications in Milky Way Idle from disappearing automatically, only hides on click.
// @author       Osyaburiman
// @match        https://www.milkywayidle.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    // クリックによる非表示を追跡するフラグ
    let isClickTriggered = false;

    // 通知の自動非表示を防ぐ
    const observer = new MutationObserver((mutations) => {
        mutations.forEach((mutation) => {
            if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
                const target = mutation.target;
                // クリックによる非表示でない場合のみ、隠すクラスの追加を阻止
                if (!isClickTriggered &&
                    target.classList.contains('Notification_notification__3l8oP') &&
                    target.classList.contains('Notification_hidden__3w7ag')) {
                    target.classList.remove('Notification_hidden__3w7ag');
                }
            }
        });
    });

    // 通知コンテナを監視
    const notificationsContainer = document.querySelector('.GamePage_notifications__1xT_i');
    if (notificationsContainer) {
        observer.observe(notificationsContainer, {
            childList: true,
            subtree: true,
            attributes: true,
            attributeFilter: ['class']
        });
    }

    // クリックで通知を非表示にする
    document.addEventListener('click', (event) => {
        const notification = event.target.closest('.Notification_notification__3l8oP');
        if (notification) {
            // クリックによる非表示を許可
            isClickTriggered = true;
            notification.classList.add('Notification_hidden__3w7ag');
            // フラグをリセット(次のMutationObserverのサイクルで影響しないように)
            setTimeout(() => {
                isClickTriggered = false;
            }, 0);
        }
    });
})();