Decode Base64-encoded text in Reddit posts and convert URLs to clickable links.
目前為
// ==UserScript==
// @name Reddit B64 Decoder
// @namespace https://greasyfork.org/es/scripts/476028
// @version 1.1
// @description Decode Base64-encoded text in Reddit posts and convert URLs to clickable links.
// @author Shu2Ouma
// @icon https://www.redditstatic.com/shreddit/assets/favicon/192x192.png
// @license MIT
// @match https://*.reddit.com/r/*
// @grant none
// ==/UserScript==
// Function to decode Base64-encoded text and convert URLs to clickable links
// Función para decodificar texto codificado en Base64 y convertir URLs en enlaces clicables
function decodeBase64AndLinkify(domElement) {
const text = domElement.textContent;
// Regular expression to detect and decode Base64
// Expresión regular para detectar y decodificar Base64
const base64Regex = /([A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)*/g;
const decodedText = text.replace(base64Regex, match => {
try {
const decoded = atob(match);
if (decoded.includes('https://') || decoded.includes('http://')) {
return (
decoded
.replace(/[\r\n]+/g, '<br /><br />')
.replace(/(https?:\/\/[^\s<]+)/g, `<a href="$1" target="_blank" style='text-decoration: underline #8989ff dotted; text-underline-offset: 2px;'>$1</a>`)
);
}
} catch (error) {
console.error(`Error decoding Base64: ${match}`, error);
}
return match;
});
domElement.innerHTML = decodedText;
}
// Function to process Reddit posts on the page
// Función para procesar las publicaciones de Reddit en la página
function processRedditPosts() {
const postContents = document.querySelectorAll('p');
postContents.forEach(decodeBase64AndLinkify);
}
// Execute the script with a 2-second delay after the page has finished loading
// Ejecutar el script con un retraso de 2 segundos después de que la página haya terminado de cargar
window.addEventListener('load', () => {
setTimeout(processRedditPosts, 2000); // 2000 milisegundos = 2 segundos
});
// Observe changes in the DOM after the page has loaded
// Observar cambios en el DOM después de que la página se haya cargado
const observer = new MutationObserver(mutationsList => {
mutationsList.forEach(mutation => {
if (mutation.addedNodes.length > 0) {
mutation.addedNodes.forEach(node => {
if (node instanceof HTMLElement) {
const postContents = node.querySelectorAll('p');
postContents.forEach(decodeBase64AndLinkify);
}
});
}
});
});
// Start observing changes in the DOM
// Iniciar la observación de cambios en el DOM
observer.observe(document.body, { childList: true, subtree: true });