Spaces:
Running
Running
Create a program that uses Microsoft Presido to redact PII from documents but using an Australian context
0d4afe5
verified
| document.addEventListener('DOMContentLoaded', function() { | |
| // Mock redaction function - in a real app this would call Microsoft Presidio API | |
| function redactText(text) { | |
| // Sample Australian PII patterns | |
| const patterns = { | |
| tfn: /\b\d{3}-\d{3}-\d{3}\b/g, // TFN: 123-456-789 | |
| medicare: /\b\d{4}\s?\d{5}\s?\d{1}\b/g, // Medicare: 1234 56789 1 | |
| phone: /\b(\+?61|0)4\d{2}\s?\d{3}\s?\d{3}\b/g, // AU mobile: 0412 345 678 | |
| abn: /\b\d{2}\s?\d{3}\s?\d{3}\s?\d{3}\b/g, // ABN: 12 345 678 910 | |
| address: /\b\d{1,4}\s[\w\s]+\b,\s(?:NSW|VIC|QLD|SA|WA|TAS|NT|ACT)/gi | |
| }; | |
| let redacted = text; | |
| // Replace each pattern with [REDACTED] | |
| for (const [type, regex] of Object.entries(patterns)) { | |
| redacted = redacted.replace(regex, `[REDACTED_${type.toUpperCase()}]`); | |
| } | |
| return redacted; | |
| } | |
| // Handle redact button click | |
| document.getElementById('redact-btn').addEventListener('click', function() { | |
| const inputText = document.getElementById('input-text').value; | |
| const redactedText = redactText(inputText); | |
| document.getElementById('output-text').value = redactedText; | |
| // Show success notification | |
| const btn = this; | |
| btn.innerHTML = '<i data-feather="check" class="mr-2"></i> Redacted!'; | |
| feather.replace(); | |
| setTimeout(() => { | |
| btn.innerHTML = '<i data-feather="shield" class="mr-2"></i> Redact PII'; | |
| feather.replace(); | |
| }, 2000); | |
| }); | |
| // Handle copy button click | |
| document.getElementById('copy-btn').addEventListener('click', function() { | |
| const outputText = document.getElementById('output-text'); | |
| outputText.select(); | |
| document.execCommand('copy'); | |
| // Show copied notification | |
| const btn = this; | |
| btn.innerHTML = '<i data-feather="check" class="mr-2"></i> Copied!'; | |
| feather.replace(); | |
| setTimeout(() => { | |
| btn.innerHTML = '<i data-feather="copy" class="mr-2"></i> Copy'; | |
| feather.replace(); | |
| }, 2000); | |
| }); | |
| // Handle download button click | |
| document.getElementById('download-btn').addEventListener('click', function() { | |
| const redactedText = document.getElementById('output-text').value; | |
| if (!redactedText) return; | |
| const blob = new Blob([redactedText], { type: 'text/plain' }); | |
| const url = URL.createObjectURL(blob); | |
| const a = document.createElement('a'); | |
| a.href = url; | |
| a.download = 'redacted-document.txt'; | |
| document.body.appendChild(a); | |
| a.click(); | |
| document.body.removeChild(a); | |
| URL.revokeObjectURL(url); | |
| // Show downloaded notification | |
| const btn = this; | |
| btn.innerHTML = '<i data-feather="check" class="mr-2"></i> Downloaded!'; | |
| feather.replace(); | |
| setTimeout(() => { | |
| btn.innerHTML = '<i data-feather="download" class="mr-2"></i> Download'; | |
| feather.replace(); | |
| }, 2000); | |
| }); | |
| }); |