FMHY Base64 Rentry Decoder-Linkifier

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

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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*
// @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;
        }
    });
})();