<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="../style.css">
    <link rel="stylesheet" href="/fa/css/all.min.css">
    <meta property="og:title" content="THE Bin" />
    <meta property="og:type" content="website" />
    <meta property="og:url" content="http://bin.got-hacked.rip/" />
    <meta property="og:description" content="An open-source, uncensored bin.\nPaste #<%= id %>" />
    <meta name="theme-color" content="#5D67FF">
    <title>Paste #<%= id %></title>
    <script>
        function alert(text) {
            if(document.getElementsByClassName('alert').length > 0) {
                Object.keys(document.getElementsByClassName('alert')).forEach(item => {
                    if(item != 'length') {
                        document.body.removeChild(document.getElementsByClassName('alert')[item]);
                    }
                })
            }
            var alert = document.createElement("div");
            alert.className = "alert";
            alert.innerHTML = text;
            document.body.appendChild(alert);
            setTimeout(function() {
                document.body.removeChild(alert);
            }, 3000);
        }
        function copyPaste() {
            /* Get the text field */
            var copyText = document.getElementById("editor");

            /* Select the text field */
            copyText.select();
            copyText.setSelectionRange(0, 99999); /* For mobile devices */

            /* Copy the text inside the text field */
            navigator.clipboard.writeText(copyText.value);
            alert("Copied text to clipboard!");
        }

        function copyLink() {
            /* Get the text field */
            var copyText = window.location.href;

            /* Copy the text inside the text field */
            navigator.clipboard.writeText(copyText);
            alert("Copied link to clipboard!");
        }
        function goToHome() {
            window.location.href = "/";
        }

        function replaceAll(string, string1, string2) {
            // Replace every string1 in string with string2
            return string.split(string1).join(string2);
        }

        function replaceLinks() {
            let regex = /((?:http|https|ftp|sftp|ws|wss):\/\/.+?(?:\/^.|^\n|(?=\s)|$))/gm;
            // Replace all links in editor with a link to the link
            let editor = document.getElementById("editor");
            editor.innerHTML = editor.innerHTML.replace(regex, function(match) {
                // Create a new a element
                let a = document.createElement("a");
                a.href = match;
                a.innerText = match;
                a.target = "_blank";
                // Make it a link which actually works in the text area
                return a.outerHTML;
                // return a;
            });
        }
    </script>
</head>
<body style="overflow-y:hidden">
    <div class="material-editor-box">
        <div class="material-editor-topbar">
            <div class="material-editor-name-div"><i class="fa-solid fa-file"></i><input class="material-editor-name-force" type="text" id="name" placeholder="Here goes the paste name!" readonly value="<%= name %>"/></div>
            <button class="material-button-toggle" onclick="goToHome()"><i class="fa-solid fa-house"></i>Go back to Home</button>
            <button class="material-button-toggle" onclick="copyLink()"><i class="fa-solid fa-clipboard"></i>Copy Link</button>
            <button class="material-button-toggle-on-force" id="encryption-button" style='<%= (status == "Link Encryption Enabled" || status == "Public") ? "color:black;" : "color: #FF5F89!important" %>'><i class="fa-solid fa-<%= status == "Link Encryption Enabled" ? 'lock' : 'unlock' %>"></i><%= status %></button>
        </div>
        <div class="material-editor-textbox">
            <div placeholder="Enter some text to get started!" id="editor" spellcheck="false" autofocus="true" autocomplete="false" readonly><%= text %></div>
        </div>
    </div>
</body>
<script defer>
    replaceLinks();
    document.getElementById("editor").innerHTML = replaceAll(document.getElementById("editor").innerHTML, "\n", "<br>");
</script>
</html>