summaryrefslogtreecommitdiff
path: root/dist/callback.html
blob: 8eab4d67a3e0adbc0d41a0d5fda2e476f90a312b (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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
  font-family: "Lato", sans-serif;
}

.sidenav {
  height: 100%;
  width: 160px;
  position: fixed;
  z-index: 1;
  top: 0;
  left: 0;
  background-color: #111;
  overflow-x: hidden;
  padding-top: 20px;
}

.sidenav a {
  padding: 6px 8px 6px 16px;
  text-decoration: none;
  font-size: 25px;
  color: #818181;
  display: block;
}
.sidenav h1 {
  padding: 6px 8px 6px 16px;
  text-decoration: none;
  font-size: 20px;
  color: #FFFFFF;
  display: block;
}

.sidenav a:hover {
  color: #f1f1f1;
}

.main {
  margin-left: 160px; /* Same as the width of the sidenav */
  font-size: 28px; /* Increased text to enable scrolling */
  padding: 0px 10px;
}

@media screen and (max-height: 450px) {
  .sidenav {padding-top: 15px;}
  .sidenav a {font-size: 18px;}
}
</style>
</head>
<body onload="populate_users()">
    <div class="sidenav">
    <a>Current Users</a>
    <h1 id="userlist"></h1>
</div>
<div class="main">
    <h1>Spotify Intersect</h1>
    <button id="Load_button" onclick="load_songs()">Load songs to database</button>
    <p id="status"></p>
    <input type="text" id="name1" value="First name">
    <input type="text" id="name2" value="Second name">
    <button id="Match_button" onclick="match_users()">Match users</button>
    <h1 id="output"></h1>
</div>
    <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";
            document.getElementById("Load_button").disabled = true;
            let token = sessionStorage.getItem('token');
            fetch("https://kobert.dev/spotify-api/callback/" + token + "/" + getParameterByName("code"))
            .then(function(response) {
              if (!response.ok) {
                  document.getElementById("status").innerHTML = `Error occured while loading songs: ${response.status}`;
                throw new Error(`HTTP error! status: ${response.status}`);
              }
            document.getElementById("status").innerHTML = "Loaded songs";
            });
            //window.location = "https://kobert.dev/spotify-api/token/" + token;
        }
function match_users() {
        let name1 = document.getElementById("name1").value;
        let name2 = document.getElementById("name2").value;

            fetch("https://kobert.dev/spotify-api/match/" + name1 + "/" + name2)
            .then(function(response) {
              if (!response.ok) {
                  document.getElementById("status").innerHTML = `Error occured while loading songs: ${response.status}`;
                throw new Error(`HTTP error! status: ${response.status}`);
              }
                response.text().then(function(message) {
                document.getElementById("output").innerHTML = message.replace(/\n/g, '<br>\n');
                });
            });    
}
        function populate_users() {
            fetch("https://kobert.dev/spotify-api/user")
            .then(function(response) {
              if (!response.ok) {
                  document.getElementById("status").innerHTML = `Error occured while loading songs: ${response.status}`;
                throw new Error(`HTTP error! status: ${response.status}`);
              }
                response.text().then(function(message) {
                    document.getElementById("userlist").innerHTML = message.replace(/\n/g, '<br>\n');
                });
            });    
            
        }
    </script>
</body>
</html>