Finviz Redirect to robinhood

Adds buttons linking you to Robinhood from both the single stock page and the screener list.

目前為 2025-09-02 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Finviz Redirect to robinhood
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Adds buttons linking you to Robinhood from both the single stock page and the screener list.
// @author       Game Abuse Studios
// @match        https://elite.finviz.com/*
// @license MIT
// @grant        GM_addStyle
// @grant        window.open
// @run-at       document-idle
// ==/UserScript==

(function() {
    'use strict';

    // --- Inject Global Styles with Gradient Border ---
    GM_addStyle(`
        @keyframes scanline {
            0% { transform: translateY(-100%); }
            100% { transform: translateY(100%); }
        }

        .tech-btn {
            /* Gradient Border Technique */
            border: 2px solid transparent;
            background: linear-gradient(#1a1f2b, #1a1f2b) padding-box,
                        linear-gradient(to right, royalblue, blueviolet) border-box;

            color: #c9d1d9; /* Light text for contrast */
            font-family: 'monospace', 'Lucida Console', Monaco, Consolas;
            font-weight: bold;
            box-shadow: 0 2px 5px rgba(0,0,0,0.4);
            transition: all 0.2s ease-in-out;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }

        .tech-btn:hover {
            /* Brighter gradient on hover */
            background: linear-gradient(#2a2f3b, #2a2f3b) padding-box,
                        linear-gradient(to right, dodgerblue, mediumorchid) border-box;
            color: #ffffff;
            transform: scale(1.03);
        }

        /* Scan line animation on hover */
        .tech-btn::after {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: linear-gradient(to bottom, transparent 0%, rgba(138, 43, 226, 0.1) 50%, transparent 100%);
            opacity: 0;
            transform: translateY(-100%);
            transition: opacity 0.2s ease;
        }

        .tech-btn:hover::after {
            opacity: 1;
            animation: scanline 0.6s linear;
        }
    `);

    // --- Script for Single Stock Page ---
    function setupSingleStockButton() {
        const DESTINATION_URL = "https://robinhood.com/stocks/";

        function waitForElement(selector, callback) {
            if (document.querySelector(selector)) {
                callback();
            } else {
                const observer = new MutationObserver(() => {
                    if (document.querySelector(selector)) {
                        observer.disconnect();
                        callback();
                    }
                });
                observer.observe(document.body, { childList: true, subtree: true });
            }
        }

        function addButton() {
            const tickerElement = document.querySelector('.js-recent-quote-ticker');
            if (!tickerElement) return;

            const ticker = tickerElement.textContent.trim();
            const cleanedTicker = ticker.replace(/-/g, '.');

            const button = document.createElement('button');
            button.className = 'tech-btn';
            button.textContent = `Open ${cleanedTicker} In Robinhood`;
            button.title = `Go to ${cleanedTicker} on Robinhood`;

            // Apply specific positioning and sizing
            button.style.cssText = `
                position: fixed;
                bottom: 20px;
                left: 20px;
                z-index: 1000;
                padding: 14px 28px;
                font-size: 20px;
                border-radius: 9999px;
            `;

            button.addEventListener('click', () => {
                window.open(`${DESTINATION_URL}${cleanedTicker}`, '_blank');
            });

            document.body.appendChild(button);
        }
        waitForElement('.js-recent-quote-ticker', addButton);
    }

    // --- Script for Screener Page ---
    function setupScreenerButtons() {
        // Additional styles for the SMALL screener buttons
        GM_addStyle(`
            .rh-floating-btn {
                position: absolute;
                height: 18px;
                width: 30px;
                font-size: 12px;
                border-radius: 9999px;
                padding: 0;
                display: flex;
                align-items: center;
                justify-content: center;
                z-index: 9998;
                border-width: 1px;
            }
            .rh-floating-btn:hover {
                transform: scale(1.05);
            }
        `);

        const buttonContainer = document.createElement('div');
        document.body.appendChild(buttonContainer);

        function updateFloatingButtons() {
            buttonContainer.innerHTML = '';
            const screenerTable = document.getElementById('screener-views-table');
            if (!screenerTable) return;

            const tableRect = screenerTable.getBoundingClientRect();
            const leftPosition = window.scrollX + tableRect.left - 30 - 5;

            const tickerLinks = document.querySelectorAll('a.tab-link[href*="quote.ashx?t="]');

            tickerLinks.forEach(link => {
                const originalTicker = link.textContent.trim();
                if (!originalTicker.match(/^[A-Z-]+$/)) return;

                const robinhoodTicker = originalTicker.replace('-', '.');
                const parentRow = link.closest('tr');
                if (!parentRow) return;

                const rowRect = parentRow.getBoundingClientRect();
                const topPosition = window.scrollY + rowRect.top + (rowRect.height / 2) - (18 / 2);

                const button = document.createElement('button');
                button.className = 'tech-btn rh-floating-btn';
                button.textContent = 'RH';
                button.style.top = `${topPosition}px`;
                button.style.left = `${leftPosition}px`;

                button.onclick = (e) => {
                    e.stopPropagation();
                    window.open(`https://robinhood.com/stocks/${robinhoodTicker}`, '_blank');
                };
                buttonContainer.appendChild(button);
            });
        }

        function observeTickerTable() {
            const screenerTable = document.getElementById('screener-views-table');
            if (!screenerTable) return;
            const observer = new MutationObserver(() => setTimeout(updateFloatingButtons, 50));
            observer.observe(screenerTable, { childList: true, subtree: true });
        }

        function debounce(func, wait) {
            let timeout;
            return (...args) => {
                clearTimeout(timeout);
                timeout = setTimeout(() => func.apply(this, args), wait);
            };
        }

        window.addEventListener('resize', debounce(updateFloatingButtons, 100));

        const setupInterval = setInterval(() => {
            if (document.getElementById('screener-views-table')) {
                clearInterval(setupInterval);
                updateFloatingButtons();
                observeTickerTable();
            }
        }, 100);
    }

    // --- Main Logic ---
    if (window.location.href.includes('screener.ashx')) {
        setupScreenerButtons();
    } else {
        setupSingleStockButton();
    }
})();

QingJ © 2025

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