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 = ' Redacted!'; feather.replace(); setTimeout(() => { btn.innerHTML = ' 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 = ' Copied!'; feather.replace(); setTimeout(() => { btn.innerHTML = ' 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 = ' Downloaded!'; feather.replace(); setTimeout(() => { btn.innerHTML = ' Download'; feather.replace(); }, 2000); }); });