-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(YummyAnime): add activity #10356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 8 commits
084da7f
89ddd56
e0e3d3a
f032bce
45c1711
663a614
8be87a3
a7afa4c
231a01a
9646c29
80408ad
35e578b
6848173
225657c
128bf3d
76bdd76
bef1b56
554d7c6
1b07b70
8c61c19
ba3d933
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| const iframe = new iFrame() | ||
|
|
||
| iframe.on('UpdateData', async () => { | ||
| const video = document.querySelector('video') | ||
|
|
||
| if (video && !Number.isNaN(video.duration)) { | ||
| iframe.send({ | ||
| duration: video.duration, | ||
| currentTime: video.currentTime, | ||
| paused: video.paused, | ||
| }) | ||
| } | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "$schema": "https://schemas.premid.app/metadata/1.16", | ||
| "apiVersion": 1, | ||
| "author": { | ||
| "id": "1045800378228281345", | ||
| "name": "harryys" | ||
| }, | ||
| "service": "YummyAnime", | ||
| "description": { | ||
| "en": "Displays anime you are watching on YummyAnime." | ||
|
||
| }, | ||
| "url": "yummyani.me", | ||
| "regExp": "^https?://(www\\.)?(site\\.)?(en\\.)?yummyani\\.me/.*", | ||
ch1kulya marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "version": "1.0.0", | ||
| "logo": "https://i.imgur.com/6XnAGga.jpeg", | ||
| "thumbnail": "https://i.imgur.com/Z7z6N5g.png", | ||
| "color": "#FF5722", | ||
| "category": "anime", | ||
| "tags": ["anime", "video"], | ||
| "iframe": true, | ||
| "iFrameRegExp": "kodik" | ||
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,133 @@ | ||
| const presence = new Presence({ | ||
| clientId: '1045800378228281345', | ||
| }) | ||
|
|
||
| let videoData = { | ||
| duration: 0, | ||
| currentTime: 0, | ||
| paused: true, | ||
| hasData: false, | ||
| } | ||
|
|
||
| presence.on('iFrameData', (data: any) => { | ||
| videoData = { ...data, hasData: true } | ||
| }) | ||
|
|
||
| presence.on('UpdateData', async () => { | ||
| const { pathname } = document.location | ||
|
|
||
| const presenceData: any = { | ||
| largeImageKey: 'https://i.imgur.com/6XnAGga.jpeg', | ||
| largeImageText: 'YummyAnime', | ||
| type: 3, | ||
harryys-dev marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| if (pathname === '/' || pathname === '/index.html') { | ||
| presenceData.details = 'На главной странице' | ||
| presenceData.state = 'Выбирает аниме' | ||
| presence.setActivity(presenceData) | ||
| return | ||
| } | ||
|
|
||
| const isAnimePage = document.querySelector('.poster-block') | ||
|
|
||
| if (!isAnimePage) { | ||
| presenceData.details = 'На сайте YummyAnime' | ||
|
|
||
| const pageTitle = document.querySelector('h1')?.textContent?.trim() | ||
|
|
||
| if (pageTitle) { | ||
| presenceData.state = pageTitle | ||
| } | ||
| else { | ||
| delete presenceData.state | ||
| } | ||
|
|
||
| delete presenceData.startTimestamp | ||
| delete presenceData.endTimestamp | ||
|
|
||
| presence.setActivity(presenceData) | ||
| return | ||
| } | ||
|
|
||
| const titleHeader = document.querySelector('h1') | ||
| if (titleHeader) { | ||
| presenceData.details = titleHeader.textContent?.trim() | ||
| } | ||
| else { | ||
| presenceData.details = 'Смотрит аниме' | ||
| } | ||
|
|
||
| const posterImg = document.querySelector( | ||
| 'div.poster-block img', | ||
| ) as HTMLImageElement | ||
| if (posterImg && posterImg.src) { | ||
| if (posterImg.src.startsWith('//')) { | ||
| presenceData.largeImageKey = `https:${posterImg.getAttribute('src')}` | ||
| } | ||
| else if (posterImg.src.startsWith('/')) { | ||
| presenceData.largeImageKey = `https://site.yummyani.me${posterImg.getAttribute('src')}` | ||
| } | ||
| else { | ||
| presenceData.largeImageKey = posterImg.src | ||
| } | ||
| } | ||
|
|
||
| const activeBtn = document.querySelector('div[class*="pQCG"]') | ||
| let currentEpisode = '' | ||
| if (activeBtn) { | ||
| const text = activeBtn.textContent?.trim() | ||
| if (text && !Number.isNaN(Number(text))) | ||
| currentEpisode = text | ||
| } | ||
|
|
||
| if (videoData.hasData) { | ||
| if (!videoData.paused) { | ||
| // === PLAY === | ||
| presenceData.state = currentEpisode | ||
| ? `Смотрит серию: ${currentEpisode}` | ||
| : 'Смотрит видео' | ||
|
|
||
| const now = Date.now() | ||
| const remainingMs = (videoData.duration - videoData.currentTime) * 1000 | ||
|
|
||
| presenceData.endTimestamp = now + remainingMs | ||
|
|
||
| delete presenceData.startTimestamp | ||
| } | ||
| else { | ||
| presenceData.state = currentEpisode | ||
| ? `Серия ${currentEpisode} (Пауза)` | ||
| : 'На паузе' | ||
|
|
||
| delete presenceData.startTimestamp | ||
| delete presenceData.endTimestamp | ||
| } | ||
| } | ||
| else { | ||
| const videoElement = document.querySelector('#video') | ||
| let isWatchingBlock = false | ||
|
|
||
| if (videoElement) { | ||
| const rect = videoElement.getBoundingClientRect() | ||
| const viewHeight = Math.max( | ||
| document.documentElement.clientHeight, | ||
| window.innerHeight, | ||
| ) | ||
| if (!(rect.bottom < 0 || rect.top - viewHeight >= 0)) | ||
| isWatchingBlock = true | ||
| } | ||
|
|
||
| if (currentEpisode && isWatchingBlock) { | ||
| presenceData.state = `Готовится к просмотру: ${currentEpisode}` | ||
| } | ||
| else { | ||
| presenceData.state = 'Читает описание' | ||
| } | ||
|
|
||
| delete presenceData.startTimestamp | ||
| delete presenceData.endTimestamp | ||
| } | ||
|
|
||
| presence.setActivity(presenceData) | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.