-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
212 lines (176 loc) · 7.54 KB
/
Copy pathscript.js
File metadata and controls
212 lines (176 loc) · 7.54 KB
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
207
208
209
210
211
212
// Function to fetch current season anime data from MAL
async function fetchMALData() {
const response = await fetch("https://api.jikan.moe/v4/seasons/now");
const data = await response.json();
return data.data; // Return the anime data
}
// Function to fetch anime data from AniList using GraphQL
async function fetchAniListData(malID) {
const query = `
query ($malID: Int) {
Media(idMal: $malID, type: ANIME) {
id
title {
romaji
}
coverImage {
large
}
averageScore
popularity
favourites
}
}`;
const variables = { malID: malID }; // Define query variables
const response = await fetch("https://graphql.anilist.co", {
method: "POST",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
},
body: JSON.stringify({ query, variables }), // Send request body with query and variables
});
const data = await response.json();
return data.data.Media; // Return the media data from AniList
}
// Function to create a row of anime data
function createAnimeRow(anime, malRating, anilistRating, malPopularity, anilistPopularity, malFavorites, anilistFavourites) {
const row = document.createElement("div");
row.className = "anime-row"; // Create container for anime row
const cover = document.createElement("img");
cover.src = anime.coverImage.large;
cover.alt = anime.title.romaji;
cover.className = "anime-cover"; // Display anime cover image
const info = document.createElement("div");
info.className = "anime-info";
const title = document.createElement("h2");
title.textContent = anime.title.romaji; // Display anime title
const ratingsBar = document.createElement("div");
ratingsBar.className = "rating-bar"; // Create ratings bar
// Create MAL rating bar
const malBar = document.createElement("div");
malBar.className = "subbar mal-rating";
malBar.style.width = `${malRating}%`;
const malBarText = document.createElement("span");
malBarText.textContent = `MAL: ${malRating}`;
malBar.appendChild(malBarText);
// Create AniList rating bar
const anilistBar = document.createElement("div");
anilistBar.className = "subbar anilist-rating";
anilistBar.style.width = `${anilistRating}%`;
const anilistBarText = document.createElement("span");
anilistBarText.textContent = `AniList: ${anilistRating}`;
anilistBar.appendChild(anilistBarText);
// Create popularity text section
const popularityText = document.createElement("div");
popularityText.className = "popularity-text";
const malPopularityText = document.createElement("p");
malPopularityText.textContent = `MAL Popularity: ${malPopularity}`;
const anilistPopularityText = document.createElement("p");
anilistPopularityText.textContent = `AniList Popularity: ${anilistPopularity}`;
// Create favourites text section
const favouritesText = document.createElement("div");
favouritesText.className = "favourites-text";
const malFavoritesText = document.createElement("p");
malFavoritesText.textContent = `MAL Favorites: ${malFavorites}`;
const anilistFavouritesText = document.createElement("p");
anilistFavouritesText.textContent = `AniList Favourites: ${anilistFavourites}`;
// Append elements to their respective containers
popularityText.appendChild(malPopularityText);
popularityText.appendChild(anilistPopularityText);
favouritesText.appendChild(malFavoritesText);
favouritesText.appendChild(anilistFavouritesText)
ratingsBar.appendChild(malBar);
ratingsBar.appendChild(anilistBar);
info.appendChild(title);
info.appendChild(ratingsBar);
info.appendChild(popularityText);
info.appendChild(favouritesText);
row.appendChild(cover);
row.appendChild(info);
return row; // Return the completed row element
}
// Initialize function to fetch and display anime data
async function init() {
const animeList = document.getElementById("anime-list");
let malData = await fetchMALData();
for (const anime of malData) {
try {
const anilistData = await fetchAniListData(anime.mal_id);
if (anilistData) {
const malRating = Math.floor(anime.score * 10) || 0;
const malPopularity = anime.popularity;
const malFavorites = anime.favorites;
const anilistRating = anilistData.averageScore || 0;
const anilistPopularity = anilistData.popularity;
const anilistFavourites = anilistData.favourites;
const row = createAnimeRow(anilistData, malRating, anilistRating, malPopularity, anilistPopularity, malFavorites, anilistFavourites);
animeList.appendChild(row); // Append row to the anime list
}
} catch (error) {
console.error(`Error fetching data for ${anime.title}:`, error);
}
// Add a small delay to avoid rate limiting
await new Promise((resolve) => setTimeout(resolve, 200));
}
}
// Call the init function to start the process
init();
// Event listener for first GIF with sound
document.addEventListener('DOMContentLoaded', () => {
const gif = document.querySelector('.dance2');
const sound = document.getElementById('chikadance');
let isPlaying = false;
let clickTimer = null;
gif.addEventListener('click', () => {
if (clickTimer) {
clearTimeout(clickTimer);
clickTimer = null;
// Double-click detected, restart the audio
sound.currentTime = 0;
sound.play();
isPlaying = true;
} else {
// Single click detected
clickTimer = setTimeout(() => {
if (isPlaying) {
sound.pause(); // Pause the audio
isPlaying = false;
} else {
sound.play(); // Play the audio
isPlaying = true;
}
clickTimer = null; // Reset clickTimer
}, 300); // Time window for double-click detection (300 ms)
}
});
});
// Event listener for second GIF with sound
document.addEventListener('DOMContentLoaded', () => {
const gif = document.querySelector('.dance');
const sound = document.getElementById('9mm');
let isPlaying = false;
let clickTimer = null;
gif.addEventListener('click', () => {
if (clickTimer) {
clearTimeout(clickTimer);
clickTimer = null;
// Double-click detected, restart the audio
sound.currentTime = 0;
sound.play();
isPlaying = true;
} else {
// Single click detected
clickTimer = setTimeout(() => {
if (isPlaying) {
sound.pause(); // Pause the audio
isPlaying = false;
} else {
sound.play(); // Play the audio
isPlaying = true;
}
clickTimer = null; // Reset clickTimer
}, 300); // Time window for double-click detection (300 ms)
}
});
});