-
Notifications
You must be signed in to change notification settings - Fork 0
/
mylist.html
206 lines (198 loc) · 9.29 KB
/
mylist.html
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="author" content="Robert Planas Jimenez">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>MList</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-giJF6kkoqNQ00vy+HMDP7azOuL0xtbfIcaT9wjKHr8RbDVddVHyTfAAsrekwKmP1" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<link rel="stylesheet" href="style.css">
</head>
<body class="d-flex flex-column min-vh-100">
<header class="sticky-top">
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="/logo.png" alt="" width="30" height="24">
</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav me-auto mb-2 mb-lg-0">
<li class="nav-item">
<a class="nav-link" aria-current="page" href="/index.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/mylist.html">My List</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/faq.html" tabindex="-1" aria-disabled="true">FAQ</a>
</li>
</ul>
<form class="d-flex" action="/signin.html">
<button class="btn btn-primary" type="submit" id="nav-sign">Sign In / Up</button>
</form>
</div>
</div>
</nav>
</header>
<main class="mt-lg-3">
<h1 class="text-center display-1 mt-3">My list</h1>
<h4 class="text-center">Customize as you see fit.</h4>
<div class="container mt-4 mb-4" id="main">
<div class="input-group mb-3">
<span class="input-group-text">Search</span>
<input type="text" class="form-control" placeholder="#id or name" id="user-search">
<button class="btn btn-outline-secondary" type="button" id="user-insert">Insert</button>
</div>
<div class="row justify-content-center" id="top-data">
<div class="spinner-border" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
</div>
</main>
<footer class="bg-light text-center text-lg-start mt-auto">
<div class="container p-4">
<div class="row">
<div class="col-lg-6 col-md-12 mb-4 mb-md-0">
<h5 class="text-uppercase">What is MList?</h5>
<p>
MList is a brand new clone of MyAnimeList. Use it to keep track of you anime, manga or other media.
You can rate them, sort them as you want and get specific notificiation when there are new avaliable episodes.
</p>
</div>
<div class="col-lg-6 col-md-12 mb-4 mb-md-0">
<h5 class="text-uppercase">Why should you use MList?</h5>
<p>
MList is the only web based anime traking app that allows to add you own private items to the database (WIP).
It is also the tracker with most useful customization features for their users.
</p>
</div>
</div>
</div>
<div class="text-center p-3" style="background-color: rgba(0, 0, 0, 0.2)">
© 2021 Copyright:
<a class="text-dark" href="#">Robert Planas Jimenez</a>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta1/dist/js/bootstrap.bundle.min.js" integrity="sha384-ygbV9kiqUc6oa4msXn9868pTtWMgiQaeYH7/t7LECLbyPA2x65Kgf80OJFdroafW" crossorigin="anonymous"></script>
<script>
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
const baseurl = 'https://jedi-web-api-mlist.herokuapp.com'
const userid = getCookie('userid')
if (userid) {
const navsign = document.getElementById('nav-sign')
navsign.classList.remove('btn-primary')
navsign.classList.add('btn-link')
navsign.innerHTML = 'Log Out'
navsign.onclick = (e) => {
setCookie('userid', '', 1)
}
}
function addEntry(entry) {
const container = document.getElementById('top-data')
const element = document.createElement('DIV')
element.classList.add('col-lg-4')
element.classList.add('col-md-6')
element.innerHTML = `
<div class="card mb-3">
<div class="row no-gutters">
<div class="col-4">
<img src="${entry.image.portrait}" class="card-img">
</div>
<div class="col-8">
<div class="card-body">
<h5 class="card-title">${entry.name}</h5>
<p class="card-text">${entry.description.slice(0, Math.max(30, 100 - 2*entry.name.length))}...</p>
<p class="card-text"><small class="text-muted">Last updated 3 mins ago</small></p>
</div>
</div>
</div>
</div>
`
container.appendChild(element)
}
function loadData() {
if (userid === '') {
document.getElementById('main').innerHTML = `<div style="text-align:center">You need to log in.</div>`
return false
}
axios.get(baseurl + '/user?id=' + userid)
.then(function (response) {
document.getElementById('top-data').innerHTML = ''
if (response.data[0].bookmark.length === 0) {
document.getElementById('top-data').innerHTML = 'Nothing to see here. Try adding some anime.'
}
response.data[0].bookmark.forEach(id => {
axios.get(baseurl + '/data?id=' + id)
.then((response) => {
addEntry(response.data[0])
})
.catch((error) => {
console.log(error)
})
});
})
.catch(function (error) {
console.log(error);
})
}
let getId = async (input) => {
let id = -1;
if (input[0] === '#') {
id = await axios.get(baseurl + '/data?id=' + input.slice(1)).then(response => response.data[0] ? parseInt(input.slice(1)) : -1)
} else {
id = await axios.get(baseurl + '/data?name=' + input).then(response => response.data[0].id)
}
return id
}
document.getElementById('user-insert').onclick = function (element) {
const input = document.getElementById('user-search').value
getId(input).then(id => {
axios.get(baseurl + '/user?id=' + userid)
.then(function (response) {
let data = response.data[0]
if (!data.bookmark.includes(id)) {
data.bookmark = [...data.bookmark, id]
axios.put(baseurl + '/user/' + userid, data)
.then(function (response) {
console.log(response);
setTimeout(loadData, 100)
})
.catch(function (error) {
console.log(error);
});
}
})
.catch(function (error) {
console.log(error);
})
})
}
loadData()
</script>
</body>
</html>