Greasy Fork

Greasy Fork is available in English.

FMHY Base64 Rentry Decoder-Linkifier

Decode base64-encoded links in some pastebins and make URLs clickable

当前为 2024-01-28 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         FMHY Base64 Rentry Decoder-Linkifier
// @version      1.1
// @description  Decode base64-encoded links in some pastebins and make URLs clickable
//
// @include      /^https:\/\/rentry\.(?:co|org)\/fmhybase64(?:#.*)?/
//
// @match        https://pastes.fmhy.net/*
// @match        https://rentry.co/*
// @match        https://rentry.org/*
//
// @grant        none
// @icon         https://www.google.com/s2/favicons?sz=64&domain=fmhy.pages.dev
// @namespace http://greasyfork.icu/users/980489
// ==/UserScript==


(function() {
    'use strict';

    // Regular expression to match base64-encoded strings
    const base64Regex = /^[A-Za-z0-9+/]+={0,2}$/;

    // Function to decode base64 string
    function decodeBase64(encodedString) {
        return atob(encodedString);
    }

    // Function to check if a string is a URL
    function isURL(string) {
        try {
            new URL(string);
            return true;
        } catch (_) {
            return false;
        }
    }

    // Regex pattern to match the specified URLs (case-insensitive)
    var FMHYmainBase64PageRegex = /^https:\/\/rentry\.(?:co|org)\/fmhybase64(?:#.*)?/i;

    // Check if the current URL matches the regex pattern
    var currentUrl = window.location.href;
    var isFMHYmainBase64PageMatched = FMHYmainBase64PageRegex.test(currentUrl);

    // Select appropriate tags based on the URL matching
    var elementsToCheck = isFMHYmainBase64PageMatched ? document.querySelectorAll('code') : document.querySelectorAll('code, p');

    // Loop through each selected element
    elementsToCheck.forEach(function(element) {
        // Get the content of the element
        var content = element.textContent.trim();

        // Check if the content matches the base64 regex
        if (base64Regex.test(content)) {
            // Decode the base64-encoded string
            var decodedString = decodeBase64(content);

            // If the decoded string is a URL, create a clickable link
            if (isURL(decodedString)) {
                var link = document.createElement('a');
                link.href = decodedString;
                link.textContent = decodedString;
                link.target = '_blank'; // Open link in a new tab
                element.textContent = ''; // Clear the content of the element
                element.appendChild(link); // Append the link to the element
            } else {
                // Replace the content of the element with the decoded string
                element.textContent = decodedString;
            }
        }
    });
})();