summaryrefslogtreecommitdiff
path: root/dist/callback.html
blob: 6960d811d8412db2fc9691c871d681a46141645f (plain)
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
<!DOCTYPE html>
<html>
<body>
    <h1>Spotify Intersect</h1>
    <button onclick="load_songs()">Load songs to database</button>
    <p id="p1"></p>
    <script>
        function getParameterByName(name) {
            let url = window.location.href;
            name = name.replace(/[\[\]]/g, "\\$&");
            var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
                results = regex.exec(url);
            if (!results) return null;
            if (!results[2]) return '';
            return decodeURIComponent(results[2].replace(/\+/g, " "));
        }

        function load_songs() {
            console.log("loading songs");
            document.getElementById("p1").innerHTML = "Loading songs";
            let token = sessionStorage.getItem('token');
            fetch("https://kobert.dev/spotify-api/callback/" + token + "/" + getParameterByName("code"))
            .then(function(response) {
              if (!response.ok) {
                throw new Error(`HTTP error! status: ${response.status}`);
                  document.getElementById("p1").innerHTML = "Error occured while loading songs: ${response.status}";
              }
            document.getElementById("p1").innerHTML = "Loaded songs";
            });
            //window.location = "https://kobert.dev/spotify-api/token/" + token;
        }
    </script>
</body>
</html>