File size: 3,171 Bytes
0d4afe5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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);
    });
});