FMHY Base64 Auto Decoder

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

目前為 2024-01-28 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         FMHY Base64 Auto Decoder
// @version      1.4
// @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 https://greasyfork.org/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 = '_self'; // Open link in the same 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;
            }
        }
    });
})();