<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css" />
</head>

<body>
    <main class="container">
        <h1>Patched digitalrock data</h1>
        <p>This tool can be used to get some more information about the digitalrock data. Just paste the digitalrock
            url:</p>
        <input type="text" id="input" placeholder="Paste the digitalrock url here!">
        <small id="invalid-helper" style="display: none;">
            The link is invalid!
        </small>
        <button id="submit" onclick="parseUrlAndRedirect()">Submit</button>

        <h2>Where to get the link?</h2>
        <p>To get the link, go to <a href="https://digitalrock.de">digitalrock</a>, find the competition and category
            you want to view, right click it and select "copy link".</p>
        <img src="copy-link.png" alt="How to get the link">
    </main>
</body>

<script>
    function parseUrlAndRedirect() {
        const input = document.getElementById("input");
        const url = input.value;
        if (!url.includes("digitalrock.de") || !url.includes("#") || !url.includes("eliste.html")) {
            document.getElementById("invalid-helper").style.display = "block";
            input.setAttribute("aria-invalid", "true")
            input.setAttribute("aria-describedby", "invalid-helper")
            return;
        }
        const urlHash = url.split("#")[1];
        const newUrl = `https://bluerock.itsblue.page/eliste/eliste.html#${urlHash}`;
        window.location.href = newUrl;
    }
</script>

</html>