<script language="javascript"><script>
function openUrlShortener() {
Swal.fire({
html: `
<div class="container">
<div class="form-group">
<label for="longUrl">Acortador URL</label>
<input type="text" id="longUrl" name="longUrl">
</div>
<div class="form-group">
<button1 type="button" onclick="shortenUrl()">Acortar URL</button1>
</div>
</div>
`,
showCloseButton: true, // Muestra el botón de cerrar
showConfirmButton: false, // Oculta el botón de confirmar
customClass: {
container: 'swal2-container' // Agrega la clase al contenedor
}
});
}
function shortenUrl() {
var longUrl = document.getElementById('longUrl').value;
fetch('https://is.gd/create.php?format=json&url=' + encodeURIComponent(longUrl))
.then(response => response.json())
.then(data => {
if(data.shorturl) {
// Mostrar un mensaje modal de éxito usando SweetAlert2
Swal.fire({
icon: 'success',
title: 'URL acortada exitosamente',
text: 'La URL ha sido acortada correctamente.',
html: '<input type="text" id="shortUrlResult" value="' + data.shorturl + '" readonly><br><br><button class="copy-button" type="button" onclick="copyShortUrl()">Copiar</button>',
showCancelButton: false,
showConfirmButton: false // Ocultamos el botón de "Aceptar"
});
} else {
// Mostrar un mensaje modal de error usando SweetAlert2
Swal.fire({
icon: 'error',
title: 'Error al acortar la URL',
text: 'Por favor, intenta nuevamente.'
});
}
})
.catch(error => {
console.error('Error:', error);
// Mostrar un mensaje modal de error usando SweetAlert2
Swal.fire({
icon: 'error',
title: 'Error al acortar la URL',
text: 'Por favor, intenta nuevamente.'
});
});
}
function copyShortUrl() {
var shortUrlInput = document.getElementById('shortUrlResult');
// Selecciona el texto dentro del campo de entrada
shortUrlInput.select();
shortUrlInput.setSelectionRange(0, 99999); // Para dispositivos móviles
// Copia el texto seleccionado al portapapeles
document.execCommand('copy');
// Deselecciona el texto para que el usuario no lo vea seleccionado
window.getSelection().removeAllRanges();
// Muestra una alerta o mensaje indicando que el URL corto ha sido copiado
Swal.fire({
icon: 'success',
title: 'URL corto copiado',
text: 'El URL corto ha sido copiado al portapapeles.',
showCancelButton: false,
showConfirmButton: true,
confirmButtonText: 'Cerrar'
});
}
</script></script>
© 2023 Quttera Ltd. All rights reserved.