Greasy Fork is available in English.

DrownedMods Base64 Auto Decoder

Auto-decodes base64 strings in posts and makes them clickable

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==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');
})();