DrownedMods Base64 Auto Decoder

Auto-decodes base64 strings in posts and makes them clickable

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         DrownedMods Base64 Auto Decoder
// @namespace    https://example.com/drownedmods-base64
// @version      1.2
// @description  Auto-decodes base64 strings in posts and makes them clickable
// @author       Adapted from FMHY with help from Grok.ai
// @license MIT 
// @match        https://forum.drownedmods.org/*
// @grant        none
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';

    const base64FullRegex = /^[A-Za-z0-9+/]{40,}(={0,2})?$/;

    function looksLikeUrl(str) {
        str = str.trim();
        return /^(https?:\/\/|magnet:\?|ftp:\/\/)/i.test(str) ||
               /mega\.nz|mediafire\.com|drive\.google\.com|gofile\.io|pixeldrain\.com/i.test(str) ||
               str.endsWith('.torrent') || str.includes('?xt=urn:btih:');
    }

    function processTextNode(node) {
        if (node.nodeType !== Node.TEXT_NODE) return;
        const text = node.textContent.trim();
        if (text.length < 40 || !base64FullRegex.test(text)) return;

        let decoded;
        try {
            decoded = atob(text).trim();
        } catch (e) {
            return;
        }

        if (!looksLikeUrl(decoded) && !decoded.includes('http')) return;

        const fragment = document.createDocumentFragment();

        if (!decoded.includes('\n')) {
            const a = document.createElement('a');
            a.href = decoded;
            a.textContent = decoded;
            a.target = '_blank';
            a.rel = 'noopener noreferrer';
            a.style.color = '#00aaff';
            a.style.fontWeight = 'bold';
            fragment.appendChild(document.createTextNode('→ '));
            fragment.appendChild(a);
        } else {
            decoded.split('\n').forEach((line, idx, arr) => {
                const trimmed = line.trim();
                if (!trimmed) {
                    fragment.appendChild(document.createElement('br'));
                    return;
                }
                if (looksLikeUrl(trimmed)) {
                    const a = document.createElement('a');
                    a.href = trimmed;
                    a.textContent = trimmed;
                    a.target = '_blank';
                    a.rel = 'noopener noreferrer';
                    fragment.appendChild(a);
                } else {
                    fragment.appendChild(document.createTextNode(trimmed));
                }
                if (idx < arr.length - 1) fragment.appendChild(document.createElement('br'));
            });
        }

        node.parentNode.replaceChild(fragment, node);
    }

    function walk(node) {
        if (!node) return;

        if (node.nodeType === Node.ELEMENT_NODE &&
            (node.tagName === 'PRE' || node.tagName === 'CODE' ||
             node.classList.contains('message-body') ||
             node.classList.contains('post-body') ||
             node.classList.contains('message-content') ||
             node.classList.contains('content') ||
             node.classList.contains('post-message') ||
             node.tagName === 'BLOCKQUOTE' ||
             node.tagName === 'DIV' || node.tagName === 'P')) {
            Array.from(node.childNodes).forEach(walk);
        }

        if (node.nodeType === Node.TEXT_NODE) {
            processTextNode(node);
        }
    }

    walk(document.body);

    const observer = new MutationObserver(muts => {
        muts.forEach(mut => {
            mut.addedNodes.forEach(node => {
                if (node.nodeType === Node.ELEMENT_NODE) walk(node);
            });
        });
    });

    observer.observe(document.body, { childList: true, subtree: true });

    console.log('[DrownedMods Base64 Decoder] Running – looking for encoded links');
})();