Reddit Dropdown Menu

Adds a dropdown menu with links to r/all and r/popular

目前为 2023-11-13 提交的版本。查看 最新版本

// ==UserScript==
// @license MIT
// @name         Reddit Dropdown Menu
// @namespace    http://tampermonkey.net/
// @version      0.1.6-Beta
// @description  Adds a dropdown menu with links to r/all and r/popular
// @author       Daniel Vasquez
// @match        https://*.reddit.com/*
// @grant        none
// ==/UserScript==
(function() {
    'use strict';

    // Create dropdown menu container
    let dropdown = document.createElement("div");
    dropdown.style.position = "fixed";
    dropdown.style.top = "6px";
    dropdown.style.right = "10px";
    dropdown.style.zIndex = "999";
    dropdown.style.backgroundColor = "#FF4500";
    dropdown.style.borderRadius = "5px";
    dropdown.style.padding = "10px";
    dropdown.style.cursor = "pointer";

    // Style for the dropdown content
    let dropdownContentStyle = "display: none; position: absolute; background-color: #f9f9f9; min-width: 160px; box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2); z-index: 1000;";

    // Create dropdown content
    let dropdownContent = document.createElement("div");
    dropdownContent.style = dropdownContentStyle;

    // Create menu items
    function createMenuItem(text, href) {
        let item = document.createElement("a");
        item.textContent = text;
        item.href = href;
        item.style.color = "black";
        item.style.padding = "12px 16px";
        item.style.textDecoration = "none";
        item.style.display = "block";
        item.onmouseover = function() { this.style.backgroundColor = "#f1f1f1"; };
        item.onmouseout = function() { this.style.backgroundColor = "#f9f9f9"; };
        return item;
    }

    // Append items to dropdown content
    dropdownContent.appendChild(createMenuItem("Go to r/all", "https://www.reddit.com/r/all/"));
    dropdownContent.appendChild(createMenuItem("Go to r/popular", "https://www.reddit.com/r/popular/"));

    // Show dropdown content on hover
    dropdown.onmouseover = function() { dropdownContent.style.display = "block"; };
    dropdown.onmouseout = function() { dropdownContent.style.display = "none"; };

    // Append dropdown content to dropdown
    dropdown.appendChild(dropdownContent);

    // Append dropdown to the body
    document.body.appendChild(dropdown);
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址