-
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.
Merge pull request #47 from baloise/main
Polish
- Loading branch information
Showing
4 changed files
with
66 additions
and
60 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
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 |
---|---|---|
@@ -1,18 +1,27 @@ | ||
document.getElementById('downloadBtnDemask').addEventListener('click', function() { | ||
// Get the content of the textarea | ||
const Text = document.getElementById('responseFieldDeanonText').value; | ||
|
||
// Create a Blob from the textarea content | ||
const blobText = new Blob([Text], { type: 'text/plain' }); | ||
const contents = [ | ||
{ content: document.getElementById('responseFieldDeanonText').value, name: 'yoyo-text.txt', type: 'text/plain' }, | ||
]; | ||
|
||
// Download files | ||
async function downloadFiles(files) { | ||
for (const file of files) { | ||
const blob = new Blob([file.content], { type: file.type }); | ||
const url = window.URL.createObjectURL(blob); | ||
|
||
const a = document.createElement('a'); | ||
a.href = url; | ||
a.download = file.name; | ||
document.body.appendChild(a); | ||
a.click(); | ||
a.remove(); | ||
|
||
window.URL.revokeObjectURL(url); | ||
|
||
// Create a link element | ||
const link = document.createElement('a'); | ||
link.href = URL.createObjectURL(blobText); | ||
link.download = 'yoyo-text.txt'; // Specify the file name | ||
|
||
// Programmatically click the link to trigger the download | ||
link.click(); | ||
|
||
// Clean up and revoke the object URL | ||
URL.revokeObjectURL(link.href); | ||
await new Promise(resolve => setTimeout(resolve, 100)); | ||
}; | ||
} | ||
|
||
downloadFiles(contents); | ||
}); |
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
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 |
---|---|---|
@@ -1,28 +1,28 @@ | ||
document.getElementById('downloadBtn').addEventListener('click', function() { | ||
// Get the content of the textarea | ||
const foundEntities = document.getElementById('responseFieldEntities').value; | ||
const newText = document.getElementById('responseFieldAnonText').value; | ||
|
||
// Create a Blob from the textarea content | ||
const blobEntities = new Blob([foundEntities], { type: 'application/json' }); | ||
const blobNewText = new Blob([newText], { type: 'text/plain' }); | ||
|
||
// Create a link element | ||
const linkE = document.createElement('a'); | ||
linkE.href = URL.createObjectURL(blobEntities); | ||
linkE.download = 'yoyo-entities.json'; // Specify the file name | ||
|
||
const linkNT = document.createElement('a'); | ||
linkNT.href = URL.createObjectURL(blobNewText); | ||
linkNT.download = 'yoyo-anonymizedText.txt'; // Specify the file name | ||
const contents = [ | ||
{ content: document.getElementById('responseFieldEntities').value, name: 'yoyo-entities.json', type: 'application/json' }, | ||
{ content: document.getElementById('responseFieldAnonText').value, name: 'yoyo-anonymizedText.txt', type: 'text/plain' }, | ||
]; | ||
|
||
setTimeout(function() { | ||
linkE.click(); | ||
URL.revokeObjectURL(linkE.href); | ||
}, 50); | ||
// Download files | ||
async function downloadFiles(files) { | ||
for (const file of files) { | ||
const blob = new Blob([file.content], { type: file.type }); | ||
const url = window.URL.createObjectURL(blob); | ||
|
||
const a = document.createElement('a'); | ||
a.href = url; | ||
a.download = file.name; | ||
document.body.appendChild(a); | ||
a.click(); | ||
a.remove(); | ||
|
||
window.URL.revokeObjectURL(url); | ||
|
||
await new Promise(resolve => setTimeout(resolve, 100)); | ||
}; | ||
} | ||
|
||
setTimeout(function() { | ||
linkNT.click(); | ||
URL.revokeObjectURL(linkNT.href) | ||
}, 50); | ||
downloadFiles(contents); | ||
}); |