@@ -57,6 +57,27 @@ function getCleanAnimeTitle(): string | undefined {
5757 return clone . textContent ?. trim ( ) || undefined
5858}
5959
60+ /**
61+ * Gets the anime cover URL from the poster element - ONLY for anime pages
62+ */
63+ function getAnimeCoverUrl ( ) : string | undefined {
64+ // Only try to get cover if we're on an anime-related page
65+ const url = document . location . pathname
66+ if ( ! url . includes ( '/catalog/' ) )
67+ return undefined
68+
69+ const poster = document . querySelector < HTMLImageElement > ( '.m-catalog-item__poster img' )
70+ if ( poster ?. src )
71+ return poster . src
72+
73+ // Fallback to og:image if poster not found (only on anime pages)
74+ const ogImage = document . querySelector < HTMLMetaElement > ( 'meta[property="og:image"]' )
75+ if ( ogImage ?. content && url . includes ( '/catalog/' ) )
76+ return ogImage . content
77+
78+ return undefined
79+ }
80+
6081/**
6182 * Determines page type and extracts relevant data from URL and DOM
6283 */
@@ -70,6 +91,11 @@ function getPageData(): PageData {
7091 }
7192 // All anime-related pages are under /catalog/
7293 else if ( url . includes ( '/catalog/' ) ) {
94+ // Try to get anime cover (only for anime pages)
95+ const coverUrl = getAnimeCoverUrl ( )
96+ if ( coverUrl )
97+ data . coverUrl = coverUrl
98+
7399 // Check if this is a video watching page (contains pattern like /1-seriya-9604/)
74100 if ( url . match ( / \/ \d + - s e r i y a - \d + \/ / ) ) {
75101 data . type = 'watching'
@@ -102,25 +128,13 @@ function getPageData(): PageData {
102128 if ( episodeMatch )
103129 data . episode = episodeMatch [ 1 ]
104130 }
105-
106- // Get cover image from Open Graph meta tag
107- const ogImage = document . querySelector < HTMLMetaElement > ( 'meta[property="og:image"]' )
108- if ( ogImage ) {
109- data . coverUrl = ogImage . content
110- }
111131 }
112132 else {
113133 // This is an anime information page (not watching)
114134 data . type = 'anime'
115135
116136 // Get anime title
117137 data . animeName = getCleanAnimeTitle ( )
118-
119- // Get cover image from poster element
120- const poster = document . querySelector < HTMLImageElement > ( '.m-catalog-item__poster img' )
121- if ( poster ) {
122- data . coverUrl = poster . src
123- }
124138 }
125139 }
126140 // Search page
@@ -156,12 +170,18 @@ presence.on('UpdateData', async () => {
156170 type : ActivityType . Watching ,
157171 }
158172
173+ // Use anime cover ONLY on anime-related pages and if enabled
174+ if ( showCover && ( pageData . type === 'anime' || pageData . type === 'watching' ) ) {
175+ if ( pageData . coverUrl && pageData . coverUrl !== ActivityAssets . Logo ) {
176+ presenceData . largeImageKey = pageData . coverUrl
177+ }
178+ }
179+
159180 // Set presence data based on page type
160181 switch ( pageData . type ) {
161182 case 'home' :
162183 presenceData . details = 'On the homepage'
163184 presenceData . state = 'Browsing new releases'
164- presenceData . largeImageKey = ActivityAssets . Logo
165185 presenceData . smallImageKey = Assets . Search
166186 presenceData . smallImageText = 'Homepage'
167187 if ( showTimestamp )
@@ -181,11 +201,6 @@ presence.on('UpdateData', async () => {
181201 presenceData . details = pageData . animeName || 'Anime page'
182202 presenceData . state = 'Reading description'
183203
184- // Use anime cover if enabled and available
185- if ( showCover && pageData . coverUrl && pageData . coverUrl !== ActivityAssets . Logo ) {
186- presenceData . largeImageKey = pageData . coverUrl
187- }
188-
189204 presenceData . smallImageKey = Assets . Reading
190205 presenceData . smallImageText = 'Reading description'
191206
@@ -208,10 +223,6 @@ presence.on('UpdateData', async () => {
208223 presenceData . state = `Episode ${ pageData . episode } `
209224 }
210225
211- if ( showCover && pageData . coverUrl && pageData . coverUrl !== ActivityAssets . Logo ) {
212- presenceData . largeImageKey = pageData . coverUrl
213- }
214-
215226 // Use iframe data for play/pause and timestamps
216227 if ( iframeVideo . exists ) {
217228 if ( iframeVideo . paused ) {
@@ -275,9 +286,8 @@ presence.on('UpdateData', async () => {
275286
276287 default :
277288 // Unknown/other pages
278- presenceData . details = 'On anime-365 website'
289+ presenceData . details = 'On website'
279290 presenceData . state = 'Exploring content'
280- presenceData . smallImageKey = ActivityAssets . Logo
281291 presenceData . smallImageText = 'On website'
282292 if ( showTimestamp )
283293 presenceData . startTimestamp = browsingTimestamp
0 commit comments