-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9516b16
Showing
3 changed files
with
135 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<!DOCTYPE html> | ||
<html lang="pt-br"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Arrumando texto em UTF-8 de uma API</title> | ||
</head> | ||
|
||
<body style="text-align: center; font-family: sans-serif; color: white; background-color: #282828;"> | ||
<section> | ||
<h1 style="font-size: 2rem;">Recodificando texto em UTF-8 a partir de uma API</h1> | ||
|
||
<label for="urlInput">URL:</label> | ||
<input style="width: 50%;" type="url" id="urlInput"> | ||
<button onclick="decodeFromUrl()">Obter da URL</button> | ||
<br> | ||
<br> | ||
<div style="font-size: 2rem; font-weight: bold; color: brown; " | ||
id="errorMessages"> | ||
</div> | ||
</section> | ||
|
||
<section> | ||
<article style="text-align: justify;"> | ||
<div style="text-align: center;"> | ||
<h3> | ||
Para aqueles que frequentemente lidam com textos obtidos por APIs e enfrentam o desafio de acentos e caracteres especiais truncados. | ||
</h3> | ||
<h3> | ||
Nosso pequeno programa foi desenvolvido para resolver esse problema, garantindo que você possa acessar facilmente os | ||
textos em seu formato original UTF-8. | ||
</h3> | ||
</div> | ||
<br> | ||
<h3 style="text-align: center;"> | ||
Como usar: | ||
</h3> | ||
<div style="text-align: center;"> | ||
<p> | ||
Cole a URL do texto na caixa de entrada fornecida e clique no botão "Obter da URL". | ||
</p> | ||
|
||
<p> | ||
Nosso aplicativo cuidará do resto, arumando os acentos e apresentando-o em uma nova aba do navegador, pronto para visualização e download. | ||
</p> | ||
|
||
<p> | ||
Nunca mais se preocupe com acentos truncados ou codificados incorretamente! | ||
</p> | ||
|
||
<p> | ||
Experimente agora e elimine os problemas de acentos truncado para sempre! | ||
</p> | ||
</div> | ||
</article> | ||
</section> | ||
|
||
<br><br> | ||
|
||
<script src="script.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## Para aqueles que frequentemente lidam com textos obtidos por APIs e enfrentam o desafio de acentos e caracteres especiais truncados. <br> <br> Nosso pequeno programa foi desenvolvido para resolver esse problema, garantindo que você possa acessar facilmente os textos em seu formato original UTF-8. | ||
|
||
### Como usar: | ||
- Cole a URL do texto na caixa de entrada fornecida e clique no botão "Obter da URL". | ||
|
||
- Nosso aplicativo cuidará do resto, arumando os acentos e apresentando-o em uma nova aba do navegador, pronto para visualização e download. | ||
|
||
- Nunca mais se preocupe com acentos truncados ou codificados incorretamente! | ||
|
||
- Experimente agora e elimine os problemas de acentos truncado para sempre! | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
function decodeFromUrl() { | ||
const url = document.getElementById('urlInput').value; | ||
|
||
if (!url) { | ||
displayError('Por favor, insira uma URL'); | ||
return; | ||
} | ||
|
||
fetch(url) | ||
.then(response => { | ||
if (!response.ok) { | ||
throw new Error('Erro ao obter o texto da URL'); | ||
} | ||
return response.arrayBuffer(); | ||
}) | ||
.then(arrayBuffer => { | ||
const decoder = new TextDecoder('utf-8'); | ||
const texto_utf8 = decoder.decode(arrayBuffer); | ||
displayText(texto_utf8); | ||
}) | ||
.catch(error => { | ||
displayError(error.message); | ||
}); | ||
} | ||
|
||
function displayText(texto_utf8) { | ||
clearError(); | ||
// Abrir uma nova aba do navegador para exibir o resultado | ||
const newWindow = window.open(); | ||
newWindow.document.write('<pre style="padding: 10px;">' + texto_utf8 + '</pre>'); | ||
newWindow.document.head.innerHTML = '<title>Arrumado!</title>'; | ||
newWindow.document.body.style.backgroundColor = '#282828'; | ||
newWindow.document.body.style.color = 'white'; | ||
|
||
// Adicionar um botão para fazer o download do arquivo | ||
const downloadButton = newWindow.document.createElement('button'); | ||
downloadButton.textContent = 'Baixar arquivo'; | ||
downloadButton.onclick = function () { | ||
const blob = new Blob([texto_utf8], { type: 'text/plain;charset=utf-8' }); | ||
const fileName = 'resultado.txt'; | ||
const downloadLink = newWindow.document.createElement('a'); | ||
downloadLink.href = URL.createObjectURL(blob); | ||
downloadLink.download = fileName; | ||
newWindow.document.body.appendChild(downloadLink); | ||
downloadLink.click(); | ||
URL.revokeObjectURL(downloadLink.href); | ||
newWindow.document.body.removeChild(downloadLink); | ||
}; | ||
newWindow.document.body.insertBefore(downloadButton, newWindow.document.body.firstChild); | ||
} | ||
|
||
function displayError(errorMessage) { | ||
const errorMessages = document.getElementById('errorMessages'); | ||
errorMessages.textContent = errorMessage; | ||
} | ||
|
||
function clearError() { | ||
const errorMessages = document.getElementById('errorMessages'); | ||
errorMessages.textContent = ''; | ||
} |