File size: 2,096 Bytes
6e7360e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c38c77c
b7dc9f5
c38c77c
 
 
6e7360e
 
 
 
 
 
 
 
 
 
 
c38c77c
 
6e7360e
 
 
 
 
 
 
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
function clipbd(res) {
    navigator.clipboard.writeText(res)
        .then(() => {
            console.log('File type: ' + res.substr(5, res.indexOf(';') - 5));
            alert('The content has successfully been copied onto clipboard!');
        })
        .catch(err => {
            console.error('Could not copy text: ', err);
            alert('Copy failed: [' + err + ']');
        });
}

function openTab(evt, tabName) {
    var i, tabcontent, tablinks;
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablinks");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active", "");
    }
    document.getElementById(tabName).style.display = "block";
    evt.currentTarget.className += " active";
}

function toBase64() {
    let fileInput = document.getElementById('fileInput');
    fileInput.onchange = function () {
        if (this.files.length <= 0) return;

        if (this.files[0].size > 5242880) {
            console.log('File size larger than 5M');
            alert('Your chosen file is too large!');
            return;
        }

        let file = this.files[0];
        let reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function () { clipbd(reader.result); };
    };
}

function countWords(text) {
    const words = text.match(/(\b[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*\b)|[a-zA-Z0-9]+/g) || [];
    return words.length;
}

$(function () {
    toBase64();

    $('#gen').click(function () {
        $('#md5').val(hex_md5($('#plain').val()));
    });
    $('#cp').click(function () {
        clipbd($('#md5').val());
    });

    $('textarea').bind('input propertychange', function () {
        $('#len').text($(this).val().length);
        $('#words').text(countWords($(this).val()));
    });
    $('text').click(function () {
        clipbd($(this).text());
    });

    document.getElementById("defaultOpen").click();
});