FMHY Base64 Rentry Decoder-Linkifier

Decode base64-encoded the FMHY Rentry page and make URLs clickable

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

您需要先安裝使用者腳本管理器擴展,如 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 Rentry Decoder-Linkifier
// @version      1.0
// @description  Decode base64-encoded the FMHY Rentry page and make URLs clickable
// @match        https://rentry.co/fmhybase64*
// @match        https://rentry.co/FMHYBase64*
// @match        https://rentry.org/fmhybase64*
// @match        https://rentry.org/FMHYBase64*
// @grant        none
// @namespace https://greasyfork.org/users/980489
// ==/UserScript==


(function() {
    'use strict';

    // 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;
        }
    }

    // Select all <code> elements
    var codeElements = document.querySelectorAll('code');

    // Loop through each <code> element
    codeElements.forEach(function(codeElement) {
        // Get the content of the <code> element
        var encodedString = codeElement.textContent.trim();

        // Decode the base64-encoded string
        var decodedString = decodeBase64(encodedString);

        // 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
            codeElement.textContent = ''; // Clear the content of <code> element
            codeElement.appendChild(link); // Append the link to the <code> element
        } else {
            // Replace the content of the <code> element with the decoded string
            codeElement.textContent = decodedString;
        }
    });
})();