-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselector.html
80 lines (69 loc) · 2.25 KB
/
selector.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Watchlist</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
h1, h2 {
text-align: center;
}
button {
padding: 10px;
margin: 5px;
cursor: pointer;
}
#watched-list {
margin-top: 20px;
}
</style>
</head>
<body>
<h1>Watchlist</h1>
<h2>Choose Category</h2>
<button onclick="selectTitle('movies')">Movies</button>
<button onclick="selectTitle('series')">Series</button>
<h2>Selected Title</h2>
<p id="selected-title"></p>
<button onclick="addToWatched()">Watched</button>
<button onclick="selectRandomTitle()">Watch Random Title</button>
<h2>Watched List</h2>
<ul id="watched-list"></ul>
<script>
let titles = {
movies: ['Movie 1', 'Movie 2', 'Movie 3'],
series: ['Series 1', 'Series 2', 'Series 3']
};
let watchedTitles = [];
function selectTitle(category) {
const titleArray = titles[category];
const selectedTitle = titleArray[Math.floor(Math.random() * titleArray.length)];
document.getElementById('selected-title').innerText = selectedTitle;
}
function addToWatched() {
const selectedTitle = document.getElementById('selected-title').innerText;
if (selectedTitle && !watchedTitles.includes(selectedTitle)) {
watchedTitles.push(selectedTitle);
updateWatchedList();
}
}
function selectRandomTitle() {
const category = Math.random() < 0.5 ? 'movies' : 'series';
selectTitle(category);
}
function updateWatchedList() {
const watchedList = document.getElementById('watched-list');
watchedList.innerHTML = '';
watchedTitles.forEach(title => {
const listItem = document.createElement('li');
listItem.textContent = title;
watchedList.appendChild(listItem);
});
}
</script>
</body>
</html>