Reddit notifications dropdown

add notifications dropdown to reddit

当前为 2025-09-25 提交的版本,查看 最新版本

// ==UserScript==
// @name                Reddit notifications dropdown
// @namespace           https://greasyfork.org/users/821661
// @version             1.0
// @description         add notifications dropdown to reddit
// @author              hdyzen
// @require             https://update.greasyfork.org/scripts/526417/1666689/USToolkit.js
// @match               https://www.reddit.com/*
// @run-at              document-start
// @grant               GM_addStyle
// @icon                https://www.google.com/s2/favicons?domain=www.reddit.com/&sz=64
// @license             GPL-3.0-only
// ==/UserScript==

const notificationDropdown = createIframeNotifications();

UST.onElement("reddit-header-large #notifications-inbox-button", (node) => {
    if (node.contains(notificationDropdown)) return;

    node.addEventListener("click", (event) => {
        event.preventDefault();
        node.classList.toggle("dropdown-visible");
    });

    node.appendChild(notificationDropdown);
});

function createIframeNotifications() {
    const iframe = document.createElement("iframe");
    iframe.id = "notifications-dropdown";
    iframe.src = "https://www.reddit.com/notifications?dropdown=true";

    document.documentElement.appendChild(iframe);

    return iframe;
}

if (unsafeWindow.location.search.includes("dropdown=true")) {
    GM_addStyle(`
        *:not(:has(notifications-main-manager), 
        notifications-main-manager, 
        notifications-main-manager *), 
        notifications-main-manager h1 {
            display: none !important;
        }
        shreddit-app {
            padding: 0 !important;
        }    
    `);
}

GM_addStyle(`
    #notifications-inbox-button {
        overflow: visible !important;
        position: relative !important;
    }

    #notifications-dropdown {
        display: none;

        position: absolute;
        top: 100%;
        right: 0;

        height: clamp(5rem, 35rem, calc(100vh - var(--shreddit-header-height, 56px)));
        
        border: 1px solid var(--color-inverted-neutral-content);
        border-radius: 1rem;
        box-shadow: var(--elevation-md);
    }

    .dropdown-visible #notifications-dropdown {
        display: block;
    }
`);