-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(anikoto): new basic activity function for anikototv.to #11000
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
dovjay
wants to merge
5
commits into
PreMiD:main
Choose a base branch
from
dovjay:feat/anikoto
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 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f432140
feat(anikoto): new basic activity function for anikototv.to
dovjay 387b8fd
Merge branch 'main' into feat/anikoto
dovjay 7fb5a74
change default image link
dovjay e41b9b9
Merge branch 'feat/anikoto' of https://github.com/dovjay/Activities i…
dovjay fe8b3cb
Merge branch 'main' into feat/anikoto
dovjay 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,24 @@ | ||
| { | ||
| "$schema": "https://schemas.premid.app/metadata/1.17", | ||
| "apiVersion": 1, | ||
| "author": { | ||
| "id": "467289851012841474", | ||
| "name": "dovjay" | ||
| }, | ||
| "service": "Anikoto", | ||
| "description": { | ||
| "en": "AniKoto is a free anime streaming destination where fans can watch high-quality anime series and movies with English subtitles or dubbed audio. With a constantly growing collection, discovering your favorite anime takes just a moment." | ||
| }, | ||
| "url": "anikototv.to", | ||
| "regExp": "^https?[:][/][/]([a-z0-9-]+[.])*anikototv[.]to[/]", | ||
| "version": "1.0.0", | ||
| "logo": "https://i.imgur.com/FYh2IFE.png", | ||
| "thumbnail": "https://i.imgur.com/WeU62dg.png", | ||
| "color": "#26A3D6", | ||
| "category": "anime", | ||
| "tags": [ | ||
| "anime", | ||
| "video", | ||
| "iframe" | ||
| ] | ||
| } |
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,90 @@ | ||
| import { ActivityType } from 'premid' | ||
|
|
||
| const presence = new Presence({ | ||
| clientId: '1526425052944273408', | ||
| }) | ||
|
|
||
| enum ActivityAssets { // Other default assets can be found at index.d.ts | ||
| Logo = 'https://i.imgur.com/FYh2IFE.png', | ||
| } | ||
|
|
||
| // Create timestamps outside UpdateData to maintain consistent timing | ||
| let browsingTimestamp = Math.floor(Date.now() / 1000) | ||
| let watchTimestamp = Math.floor(Date.now() / 1000) | ||
| let wasWatchingVideo = false | ||
| let lastHref = '' | ||
|
|
||
| presence.on('UpdateData', async () => { | ||
| const { href } = document.location | ||
| const presenceData: MediaPresenceData = { | ||
| type: ActivityType.Watching, | ||
| largeImageKey: ActivityAssets.Logo, | ||
| } | ||
|
|
||
| // 1. Check if the parent wrapper exists | ||
| const watchMain = document.querySelector('#watch-main') | ||
|
|
||
| // 2. Check if the actual iframe player has loaded into the DOM | ||
| const playerIframe = document.querySelector<HTMLIFrameElement>('#w-player iframe') | ||
|
|
||
| // If both the wrapper and the iframe exist, the user is watching | ||
| if (watchMain && playerIframe && playerIframe.src) { | ||
| // Reset the watch timer if they just transitioned to watching or swapped episodes | ||
| if (!wasWatchingVideo || href !== lastHref) { | ||
| watchTimestamp = Math.floor(Date.now() / 1000) | ||
| wasWatchingVideo = true | ||
| lastHref = href | ||
| } | ||
|
|
||
| // Extract Title from the h1 element | ||
| const titleEl = document.querySelector('h1.title.d-title') | ||
| const title = titleEl ? titleEl.textContent?.trim() : 'Unknown Anime' | ||
|
|
||
| // Extract Episode Number from the wrapper data attribute | ||
| const epNum = watchMain.getAttribute('data-ep-name') | ||
| const episodeText = epNum ? `Episode ${epNum}` : 'Watching' | ||
|
|
||
| // Extract the Anime Cover image | ||
| const posterEl = document.querySelector('.binfo .poster img[itemprop="image"]') | ||
| const posterUrl = posterEl ? posterEl.getAttribute('src') : null | ||
|
|
||
| // Build the Watching state | ||
| presenceData.type = ActivityType.Watching | ||
| presenceData.details = title | ||
| presenceData.state = episodeText | ||
| presenceData.largeImageKey = posterUrl || 'https://example.com/logo.png' | ||
Check failureCode scanning / PMD Makes sure all images (logo and URLs) are exactly 512x512 pixels Error
Failed to validate image URL (https://example.com/logo.png): Request failed with status code 404 (Not Found): GET https://example.com/logo.png
|
||
| presenceData.largeImageText = title | ||
|
|
||
| // Use an elapsed timer since we cannot read the iframe's internal video timeline | ||
| presenceData.startTimestamp = watchTimestamp | ||
|
|
||
| presenceData.buttons = [ | ||
| { | ||
| label: 'Watch Anime', | ||
| url: href, | ||
| }, | ||
| ] | ||
| } | ||
| else { | ||
| // User is browsing the home page or menus (iframe not found) | ||
| if (wasWatchingVideo) { | ||
| browsingTimestamp = Math.floor(Date.now() / 1000) | ||
| wasWatchingVideo = false | ||
| } | ||
|
|
||
| // Build the Browsing state | ||
| presenceData.largeImageKey = 'https://example.com/logo.png' | ||
Check failureCode scanning / PMD Makes sure all images (logo and URLs) are exactly 512x512 pixels Error
Failed to validate image URL (https://example.com/logo.png): Request failed with status code 404 (Not Found): GET https://example.com/logo.png
|
||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
|
||
| presenceData.largeImageText = 'Anikoto' | ||
| presenceData.details = 'Browsing Anime' | ||
| presenceData.state = 'Looking for something to watch' | ||
| presenceData.startTimestamp = browsingTimestamp | ||
| } | ||
|
|
||
| // Set or clear the activity | ||
| if (presenceData.details) { | ||
| presence.setActivity(presenceData) | ||
| } | ||
| else { | ||
| presence.clearActivity() | ||
| } | ||
| }) | ||
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.