-
-
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
Open
harryys-dev
wants to merge
17
commits into
PreMiD:main
Choose a base branch
from
harryys-dev:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
084da7f
feat(YummyAnime): add new presence
harryys-dev 89ddd56
feat(YummyAnime): add new presence
harryys-dev e0e3d3a
style: fix linting
harryys-dev f032bce
style: fixes
harryys-dev 45c1711
style: fix linting errors
harryys-dev 663a614
fix: api version
harryys-dev 8be87a3
fix: replacing thumbnail
harryys-dev a7afa4c
Merge branch 'main' of https://github.com/gnice225/Activities
harryys-dev 231a01a
Update package.json
harryys-dev 9646c29
fixes
harryys-dev 80408ad
fixes
harryys-dev 35e578b
fixes
harryys-dev 6848173
fix: linter & import errors
ch1kulya 225657c
chore: revert accidentally changed package-lock.json
ch1kulya 128bf3d
Merge branch 'main' into main
harryys-dev 76bdd76
Merge branch 'main' into main
harryys-dev bef1b56
Merge branch 'main' into main
harryys-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| }) | ||
| } | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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/.*", | ||
| "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" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| import { ActivityType } from 'premid' | ||
|
|
||
| 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: ActivityType.Watching, | ||
| } | ||
|
|
||
| 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) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.