Greasy Fork

Greasy Fork is available in English.

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

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==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);
        }
    });
})();