-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(HDrezka): add timestamps, series tracking, and user settings #10332
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
22ee445
feat(HDrezka): add user settings
Dyrdoom 8a09f8e
feat(HDrezka): implement timestamps, series tracking, and settings logic
Dyrdoom a6f998c
presence eslint edited
Dyrdoom eddf6d4
Merge branch 'main' into hdrezka
Dyrdoom 2d61a20
Merge branch 'main' into hdrezka
Dyrdoom 132e4f9
add option title as presence
Dyrdoom 4d153dc
add showTitleAsPresence
Dyrdoom 432b564
eslint fix
Dyrdoom 26c9151
Fix presence details assignment logic
Dyrdoom 5ade9f4
eslint fix
Dyrdoom 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
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 |
|---|---|---|
| @@ -1,56 +1,105 @@ | ||
| import { ActivityType, getTimestampsFromMedia, Assets } from 'premid' | ||
|
|
||
| const presence = new Presence({ | ||
| clientId: '1191450515670843533', | ||
| }) | ||
|
|
||
| presence.on('UpdateData', async () => { | ||
| const presenceData: PresenceData = { | ||
| details: 'Где-то на сайте', | ||
| const [ | ||
| privacyMode, | ||
| showBrowsingStatus, | ||
| showCover, | ||
| showTimestamp, | ||
| showSmallImages, | ||
| showTitleAsPresence, | ||
| ] = await Promise.all([ | ||
| presence.getSetting<boolean>('privacy'), | ||
| presence.getSetting<boolean>('showBrowsingStatus'), | ||
| presence.getSetting<boolean>('showCover'), | ||
| presence.getSetting<boolean>('timestamp'), | ||
| presence.getSetting<boolean>('showSmallImages'), | ||
| presence.getSetting<boolean>('showTitleAsPresence'), | ||
| ]) | ||
|
|
||
| const presenceData: any = { | ||
| largeImageKey: 'https://cdn.rcd.gg/PreMiD/websites/H/HDrezka/assets/logo.png', | ||
| } | ||
| const contentType = document | ||
| .querySelector('meta[property=\'og:url\']') | ||
| ?.getAttribute('content') | ||
| ?.split('/')[3] | ||
| const currentType = contentType === 'films' | ||
| ? 'фильм' | ||
| : contentType === 'series' | ||
| ? 'сериал' | ||
| : contentType === 'cartoons' | ||
| ? 'мультфильм' | ||
| : contentType === 'animation' | ||
| ? 'аниме' | ||
| : 'чего-то' | ||
|
|
||
| if (document.location.pathname === '/') | ||
| presenceData.details = 'На главной странице' | ||
|
|
||
| if ( | ||
| document.location.pathname === '/films' | ||
| || document.location.pathname === '/series' | ||
| || document.location.pathname === '/cartoons' | ||
| || document.location.pathname === '/animation' | ||
| || document.location.pathname.match(/\/(films|series|cartoons|animation)\//) | ||
| ) { | ||
| if (document.location.pathname.match(/\/(?:films|series|cartoons|animation)\/.+/)) { | ||
| presenceData.details = `Смотрит ${currentType}` | ||
| presenceData.state = `${ | ||
| document.querySelector('.b-post__title h1')?.textContent | ||
| }` | ||
| presenceData.largeImageKey = document.querySelector<HTMLImageElement>('.b-sidecover a img')?.src | ||
| presenceData.smallImageKey = 'https://cdn.rcd.gg/PreMiD/websites/H/HDrezka/assets/logo.png' | ||
| presenceData.buttons = [ | ||
| { | ||
| label: 'Открыть страницу', | ||
| url: document | ||
| .querySelector('meta[property=\'og:url\']') | ||
| ?.getAttribute('content') ?? '', | ||
| }, | ||
| ] | ||
|
|
||
| const urlPath = document.location.pathname | ||
| const contentType = document.querySelector('meta[property=\'og:url\']')?.getAttribute('content')?.split('/')[3] | ||
| const isMediaPage = urlPath.match(/\/(films|series|cartoons|animation)\/.+/) | ||
|
|
||
| if (privacyMode && isMediaPage) { | ||
| return presence.setActivity({ | ||
| details: 'Watching something private', | ||
| largeImageKey: 'https://cdn.rcd.gg/PreMiD/websites/H/HDrezka/assets/logo.png', | ||
| }) | ||
| } | ||
|
|
||
| if (document.location.pathname === '/') { | ||
| if (!showBrowsingStatus) | ||
| return presence.clearActivity() | ||
| presenceData.details = 'Browsing the Home Page' | ||
| } | ||
| else if (isMediaPage) { | ||
| const title = document.querySelector('.b-post__title h1')?.textContent?.trim() | ||
| const coverImage = document.querySelector<HTMLImageElement>('.b-sidecover a img')?.src | ||
|
|
||
| presenceData.details = title | ||
| if (showTitleAsPresence && !privacyMode) { | ||
| presenceData.name = title | ||
| } | ||
|
|
||
| presenceData.largeImageKey = (showCover && coverImage) ? coverImage : 'https://cdn.rcd.gg/PreMiD/websites/H/HDrezka/assets/logo.png' | ||
|
|
||
| const video = document.querySelector('video') | ||
|
|
||
| if (video && !video.paused) { | ||
| if (showTimestamp) { | ||
| const [startTimestamp, endTimestamp] = getTimestampsFromMedia(video) | ||
| presenceData.startTimestamp = startTimestamp | ||
| presenceData.endTimestamp = endTimestamp | ||
| } | ||
| presenceData.type = ActivityType.Watching | ||
| if (showSmallImages) { | ||
| presenceData.smallImageKey = Assets.Play | ||
| presenceData.smallImageText = 'Watching' | ||
| } | ||
| } | ||
| else if (showSmallImages) { | ||
| presenceData.smallImageKey = Assets.Pause | ||
| presenceData.smallImageText = 'Paused' | ||
| } | ||
|
|
||
| const isSeries = ['series', 'animation', 'cartoons'].includes(contentType || '') | ||
|
|
||
| if (isSeries) { | ||
| const activeSeason = document.querySelector('.b-simple_season__item.active')?.textContent?.trim() | ||
| const activeEpisode = document.querySelector('.b-simple_episode__item.active')?.textContent?.trim() | ||
|
|
||
| if (activeSeason && activeEpisode) { | ||
| presenceData.state = ` ${activeSeason}, ${activeEpisode}` | ||
| } | ||
| else { | ||
| presenceData.state = 'Watching a series' | ||
| } | ||
| } | ||
| else { | ||
| presenceData.details = `Ищет ${currentType}` | ||
| presenceData.smallImageKey = 'https://cdn.rcd.gg/PreMiD/websites/H/HDrezka/assets/0.png' | ||
| presenceData.state = 'Watching a movie' | ||
| } | ||
|
|
||
| const translator = document.querySelector('.b-translator__item.active')?.textContent?.trim() | ||
| if (translator) { | ||
| presenceData.largeImageText = `Voiceover: ${translator}` | ||
| } | ||
|
|
||
| presenceData.buttons = [{ label: 'Watch on Rezka', url: document.location.href }] | ||
| } | ||
| else { | ||
| if (!showBrowsingStatus) | ||
| return presence.clearActivity() | ||
| presenceData.details = 'Exploring the website' | ||
| } | ||
|
|
||
| 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.