Repository navigation
feat(AnimeVault): add presence #11478
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
mwkoah
wants to merge
3
commits into
PreMiD:main
Choose a base branch
from
mwkoah:feat/add-animevault
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
3 commits
Select commit
Hold shift + click to select a range
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,40 @@ | ||
| { | ||
| "$schema": "https://schemas.premid.app/metadata/1.17", | ||
| "apiVersion": 1, | ||
| "author": { | ||
| "id": "1521564654491402330", | ||
| "name": "bunbongonvl" | ||
| }, | ||
| "service": "AnimeVault", | ||
| "description": { | ||
| "en": "Watch Anime and movies with AI Japanese subtitle learning and Watch Party rooms.", | ||
| "vi": "Xem phim Anime và phim chất lượng cao tích hợp phòng xem chung và hỗ trợ học tiếng Nhật AI." | ||
| }, | ||
| "url": "bunbongonvl.online", | ||
| "regExp": "^https?[:][/][/]([a-z0-9-]+[.])*bunbongonvl[.]online[/]", | ||
| "version": "1.0.0", | ||
| "logo": "https://files.catbox.moe/ghuz3s.png", | ||
| "thumbnail": "https://files.catbox.moe/854obg.png", | ||
| "color": "#060810", | ||
| "category": "anime", | ||
| "tags": [ | ||
| "anime", | ||
| "movies", | ||
| "japanese", | ||
| "watchparty" | ||
| ], | ||
| "settings": [ | ||
| { | ||
| "id": "timestamps", | ||
| "title": "Show Timestamps", | ||
| "icon": "fad fa-stopwatch", | ||
| "value": true | ||
| }, | ||
| { | ||
| "id": "buttons", | ||
| "title": "Show Buttons", | ||
| "icon": "fas fa-compress-arrows-alt", | ||
| "value": true | ||
| } | ||
| ] | ||
| } |
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,158 @@ | ||
| import { ActivityType, Assets, getTimestamps } from 'premid' | ||
|
|
||
| const presence = new Presence({ | ||
| clientId: '1521564654491402330', | ||
| }) | ||
|
|
||
| enum ActivityAssets { | ||
| Logo = 'https://files.catbox.moe/ghuz3s.png', | ||
| } | ||
|
|
||
| const browsingTimestamp = Math.floor(Date.now() / 1000) | ||
|
|
||
| presence.on('UpdateData', async () => { | ||
| const { pathname, href } = document.location | ||
| const video = document.querySelector<HTMLVideoElement>('video') | ||
|
|
||
| const [showButtons, showTimestamps] = await Promise.all([ | ||
| presence.getSetting<boolean>('buttons'), | ||
| presence.getSetting<boolean>('timestamps'), | ||
| ]) | ||
|
|
||
| const presenceData: PresenceData = { | ||
| type: ActivityType.Watching, | ||
| largeImageKey: ActivityAssets.Logo, | ||
| largeImageText: 'AnimeVault - bunbongonvl.online', | ||
| } | ||
|
|
||
| if (showTimestamps) { | ||
| presenceData.startTimestamp = browsingTimestamp | ||
| } | ||
|
|
||
| const pageFirstTitle = document.title ? (document.title.split('-')[0]?.trim() ?? '') : '' | ||
|
|
||
| switch (true) { | ||
| case pathname.startsWith('/xem/'): { | ||
| const heading = document.querySelector('h1')?.textContent?.trim() || '' | ||
| const cleanTitle = heading.replace(/^(?:Xem Phim|Phim)\s+/i, '') || pageFirstTitle | ||
|
|
||
| presenceData.details = cleanTitle || 'Đang xem phim' | ||
|
|
||
| if (video && !Number.isNaN(video.duration) && video.duration > 0) { | ||
| if (showTimestamps) { | ||
| [presenceData.startTimestamp, presenceData.endTimestamp] = getTimestamps( | ||
| Math.floor(video.currentTime), | ||
| Math.floor(video.duration), | ||
| ) | ||
| } | ||
|
|
||
| if (video.paused) { | ||
| presenceData.smallImageKey = Assets.Pause | ||
| presenceData.smallImageText = 'Tạm dừng' | ||
| delete presenceData.startTimestamp | ||
| delete presenceData.endTimestamp | ||
| } | ||
| else { | ||
| presenceData.smallImageKey = Assets.Play | ||
| presenceData.smallImageText = 'Đang phát' | ||
| } | ||
| } | ||
| else { | ||
| presenceData.state = 'Đang tải trình phát...' | ||
| } | ||
|
|
||
| if (showButtons) { | ||
| presenceData.buttons = [ | ||
| { | ||
| label: 'Cùng Xem Phim Này', | ||
| url: href, | ||
| }, | ||
| ] | ||
| } | ||
| break | ||
| } | ||
|
|
||
| case pathname.startsWith('/xem-chung/'): { | ||
| const roomTitle = document.querySelector('.wp-room-header h1')?.textContent?.trim() || 'Phòng chiếu VIP' | ||
| presenceData.details = 'Phòng Xem Chung' | ||
| presenceData.state = roomTitle | ||
|
|
||
| if (video && !Number.isNaN(video.duration) && video.duration > 0) { | ||
| if (showTimestamps) { | ||
| [presenceData.startTimestamp, presenceData.endTimestamp] = getTimestamps( | ||
| Math.floor(video.currentTime), | ||
| Math.floor(video.duration), | ||
| ) | ||
| } | ||
|
|
||
| if (video.paused) { | ||
| presenceData.smallImageKey = Assets.Pause | ||
| presenceData.smallImageText = 'Tạm dừng' | ||
| delete presenceData.startTimestamp | ||
| delete presenceData.endTimestamp | ||
| } | ||
| else { | ||
| presenceData.smallImageKey = Assets.Play | ||
| presenceData.smallImageText = 'Đang phát' | ||
| } | ||
| } | ||
|
|
||
| if (showButtons) { | ||
| presenceData.buttons = [ | ||
| { | ||
| label: 'Tham Gia Phòng Chiếu', | ||
| url: href, | ||
| }, | ||
| ] | ||
| } | ||
| break | ||
| } | ||
|
|
||
| case pathname === '/xem-chung': { | ||
| presenceData.details = 'Sảnh Xem Chung' | ||
| presenceData.state = 'Tìm kiếm phòng chiếu' | ||
| break | ||
| } | ||
|
|
||
| case pathname.startsWith('/quiz'): { | ||
| presenceData.details = 'Luyện Tập Tiếng Nhật AI' | ||
| presenceData.state = 'Quiz từ vựng Anime' | ||
| break | ||
| } | ||
|
|
||
| case pathname.startsWith('/lich-chieu'): { | ||
| presenceData.details = 'Lịch Chiếu Anime' | ||
| presenceData.state = 'Xem lịch phát sóng' | ||
| break | ||
| } | ||
|
|
||
| case pathname.startsWith('/phim/'): { | ||
| const movieTitle = document.querySelector('h1')?.textContent?.trim() || pageFirstTitle | ||
| presenceData.details = 'Thông tin phim' | ||
| presenceData.state = movieTitle || 'Chi tiết tác phẩm' | ||
|
|
||
| if (showButtons) { | ||
| presenceData.buttons = [ | ||
| { | ||
| label: 'Xem Chi Tiết Phim', | ||
| url: href, | ||
| }, | ||
| ] | ||
| } | ||
| break | ||
| } | ||
|
|
||
| default: { | ||
| presenceData.details = 'Khám phá kho phim' | ||
| presenceData.state = 'Trang chủ' | ||
| break | ||
| } | ||
| } | ||
|
|
||
| if (!showTimestamps) { | ||
| 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.