File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ async function loadAniList ( ) {
2+ const query = `
3+ query {
4+ MediaListCollection(
5+ userName: "notmithun",
6+ type: ANIME,
7+ status: CURRENT
8+ ) {
9+ lists {
10+ entries {
11+ progress
12+ media {
13+ episodes
14+ title {
15+ english
16+ romaji
17+ }
18+ }
19+ }
20+ }
21+ }
22+ }
23+ ` ;
24+
25+ try {
26+ const response = await fetch ( "https://graphql.anilist.co" , {
27+ method : "POST" ,
28+ headers : {
29+ "Content-Type" : "application/json" ,
30+ Accept : "application/json" ,
31+ } ,
32+ body : JSON . stringify ( { query } ) ,
33+ } ) ;
34+
35+ const data = await response . json ( ) ;
36+
37+ const anime =
38+ data ?. data ?. MediaListCollection ?. lists
39+ ?. flatMap ( ( list ) => list . entries )
40+ ?. map ( ( entry ) => {
41+ const title = entry . media . title . english || entry . media . title . romaji ;
42+
43+ const current = entry . progress ?? "?" ;
44+ const total = entry . media . episodes ?? "?" ;
45+
46+ return `${ title } (${ current } /${ total } )` ;
47+ } ) || [ ] ;
48+
49+ document . getElementById ( "anime_watching_now" ) . textContent = anime . length
50+ ? anime . join ( ", " )
51+ : "Nothing right now" ;
52+ } catch ( err ) {
53+ document . getElementById ( "anime_watching_now" ) . textContent =
54+ "Unable to load" ;
55+ console . error ( err ) ;
56+ }
57+ }
58+
59+ loadAniList ( ) ;
You can’t perform that action at this time.
0 commit comments