<input type="text" id="urlInput" placeholder="Introduce la URL aquí">
<input value='3' type="text" id="nInput" placeholder="N veces de decodificación">
<button id="decodeButton">Decodificar</button>
<div id="resultado"></div>
JavaScript
// Función para decodificar el fragmento de Base64 n cantidad de veces
function decodificarBase64(fragment, n) {
for (var i = 0; i < n; i++) {
fragment = atob(fragment); // Decodifica de Base64
}
return fragment;
}
// Obtiene los elementos HTML por sus IDs
var decodeButton = document.getElementById('decodeButton');
var urlInput = document.getElementById('urlInput');
var nInput = document.getElementById('nInput');
var resultado = document.getElementById('resultado');
// Agrega un manejador de eventos al botón
decodeButton.addEventListener('click', function () {
var url = urlInput.value;
var n = parseInt(nInput.value); // Convierte el valor de n a un número entero
// Busca el índice del símbolo "#" en la URL
var hashIndex = url.indexOf('#');
// Verifica si el símbolo "#" se encuentra en la URL
if (hashIndex !== -1) {
// Obtiene el fragmento de la URL después del símbolo "#"
var fragment = url.substring(hashIndex + 1);
// Decodifica el fragmento de Base64 n cantidad de veces
var valorDecodificado = decodificarBase64(fragment, n);
// Muestra el valor decodificado en el elemento HTML
resultado.innerHTML = 'Valor decodificado: ' + valorDecodificado;
} else {
resultado.innerHTML = 'No se encontró ningún fragmento en la URL.';
}
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.