-
Notifications
You must be signed in to change notification settings - Fork 0
/
yourlibrary.html
70 lines (61 loc) · 2.02 KB
/
yourlibrary.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
<!DOCTYPE html>
<html>
<head>
<title>My Library</title>
<link rel="stylesheet" href="yourlibrary.css">
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
</head>
<body>
<div id="deletebutton">
<button id="deleteall" class="button-30"><img src="images/deleteall.png" id="deleteimg"></button>
</div>
<br><br><br><br><br>
<div id="bookdiv">
<div v-for="book in books" class="books">
<img :src="book.image" :alt="book.name" class="book-image">
<div class="book-name">{{ book.name }}</div>
</div>
</div>
</body>
<script>
document.addEventListener('DOMContentLoaded', () => {
var deleteall = document.querySelector('#deleteall');
var booknames = []
var booklinks = []
var noofbooks = localStorage.getItem('noofbooks')
var booklist;
var base = ['userbooktitle', 'userbookthumb', 'userbookpublish', 'userbookgenre', 'userbookauthor']
deleteall.addEventListener('click', () => {
for (let i = noofbooks; i >= 1; i--) {
for (const baseval of base) {
const val = `${baseval}${i}`;
localStorage.removeItem(val);
}
noofbooks--;
}
localStorage.setItem('noofbooks', noofbooks);
location.reload()
});
function fetchinfo() {
for (let i = 1; i <= noofbooks; i++) {
val1 = localStorage.getItem(base[0] + i)
val2 = localStorage.getItem(base[1] + i)
booknames.push(val1)
booklinks.push(val2)
}
booklist = booknames.map((title, index) => ({
name: title,
image: booklinks[index] || '#'
}))
}
fetchinfo()
Vue.createApp({
data() {
return {
books: booklist
}
}
}).mount('#bookdiv');
});
</script>
</html>