Throwbin Logo
>
// ==UserScript==
// @name         Auto Decoder for all sites
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  Decode Base64 encoded links for all sites
// @author       Coder
// @match        *://**/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=reddit.com
// @grant        none
// @license      MIT
// ==/UserScript==
 
(function () {
    'use strict';
    const base64Regex = /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=|[A-Za-z0-9+\/]{20,})$/g
 
    // Must set an interval, otherwise the content that is lazy loaded (e.g. loaded on scrolling) will not get decoded
    setInterval(() => {
        const pTags = document.querySelectorAll('p')
 
        pTags.forEach(pTag => {
            // Split the string into an array and check each element for a base64 encoded string
            const pTagText = pTag.innerText.split(/\s+/);
 
            pTagText.forEach(text => {
                if (base64Regex.test(text)) {
                    // If the string is a base64 encoded string, decode it and replace the p tag with the decoded string
                    pTag.innerText = pTag.innerText.replace(text, atob(text));
                    const txt = pTag.innerText.split("\n");
                    const links = [];
                    txt.forEach(link => {
                        links.push("<a href='" + link + "'>" + link + "</a>");
                    });
                    pTag.outerHTML = links.join("\n");
                }
            });
        })
    }, 500)
})();