-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(monochrome): add activity #10365
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 5 commits
ff7a6cb
cc57692
f8d87e9
01fa26c
347f3a9
0b59839
7d6498b
a486122
dec8b9b
f56a5c4
b1bfd99
138535f
8fea55f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "$schema": "https://schemas.premid.app/metadata/1.16", | ||
| "apiVersion": 1, | ||
| "author": { | ||
| "id": "838652741965971517", | ||
| "name": "red_nael" | ||
| }, | ||
| "service": "Monochrome", | ||
| "description": { | ||
| "en": "TODO" | ||
| }, | ||
| "url": "monochrome.samidy.com", | ||
| "regExp": "^https?[:][/][/]([a-z0-9-]+[.])*monochrome[.]samidy[.]com[/]", | ||
| "version": "1.0.0", | ||
| "logo": "https://i.imgur.com/XHf3H8Y.png", | ||
| "thumbnail": "https://i.imgur.com/XHf3H8Y.png", | ||
| "color": "#000000", | ||
| "category": "music", | ||
| "tags": [ | ||
| "music", | ||
| "tidal" | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| // @ts-ignore | ||
Check failureCode scanning / ESLint Disallow `@ts-<directive>` comments or require descriptions after directives Error
Use "@ts-expect-error" instead of "@ts-ignore", as "@ts-ignore" will do nothing if the following line is error-free.
|
||
|
|
||
| declare const Presence: any; | ||
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
|
|
||
|
|
||
| // Static Asset Configuration | ||
Check failureCode scanning / ESLint Disallow multiple empty lines Error
More than 1 blank line not allowed.
|
||
| enum ActivityAssets { | ||
| Logo = 'https://i.imgur.com/XHf3H8Y.png', | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 2 spaces but found 4.
|
||
| Play = 'https://i.imgur.com/ryNutI5.png', | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 2 spaces but found 4.
|
||
| Pause = 'https://i.imgur.com/TlMwR5i.png' | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 2 spaces but found 4.
|
||
| } | ||
Check failureCode scanning / ESLint Require or disallow trailing commas Error
Missing trailing comma.
|
||
|
|
||
| let presence; | ||
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
|
|
||
| try { | ||
| presence = new Presence({ | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 2 spaces but found 4.
|
||
| clientId: '1459594619972096248' | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
|
||
| }); | ||
Check failureCode scanning / ESLint Require or disallow trailing commas Error
Missing trailing comma.
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 2 spaces but found 4.
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
| } catch (error) { | ||
Check failureCode scanning / ESLint Enforce consistent brace style for blocks Error
Closing curly brace appears on the same line as the subsequent block.
Check failureCode scanning / ESLint Disallow unused variables Error
'error' is defined but never used.
|
||
| // Silent catch for production environments | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 2 spaces but found 4.
|
||
| } | ||
|
|
||
| if (presence) { | ||
| presence.on('UpdateData', async () => { | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 2 spaces but found 4.
|
||
|
|
||
Check failureCode scanning / ESLint Disallow trailing whitespace at the end of lines Error
Trailing spaces not allowed.
|
||
| // 1. DYNAMIC IMAGE LOGIC | ||
Check failureCode scanning / ESLint Require or disallow padding within blocks Error
Block must not be padded by blank lines.
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
|
||
| // Default to the static logo | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
|
||
| let currentLargeImage: string = ActivityAssets.Logo; | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
|
|
||
Check failureCode scanning / ESLint Disallow trailing whitespace at the end of lines Error
Trailing spaces not allowed.
|
||
| // standard mediaSession check for high-res artwork | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
|
||
| const artwork = navigator.mediaSession?.metadata?.artwork; | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
|
|
||
| if (artwork && artwork.length > 0) { | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
|
||
| // Select the last image in the array (typically the highest resolution) | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 6 spaces but found 12.
|
||
| const coverUrl = artwork[artwork.length - 1]?.src; | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 6 spaces but found 12.
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
| if (coverUrl) { | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 6 spaces but found 12.
|
||
| currentLargeImage = coverUrl; | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 8 spaces but found 16.
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
| } | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 6 spaces but found 12.
|
||
| } | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
|
||
|
|
||
| // 2. INITIALIZE ACTIVITY DATA | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
|
||
| // We create a fresh object every tick to avoid 'undefined' property issues | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
|
||
| const presenceData: any = { | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
|
||
| type: 2, // ActivityType.Listening | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 6 spaces but found 12.
|
||
| largeImageKey: currentLargeImage, | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 6 spaces but found 12.
|
||
| largeImageText: "Listening on Monochrome", | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 6 spaces but found 12.
Check failureCode scanning / ESLint Enforce the consistent use of either backticks, double, or single quotes Error
Strings must use singlequote.
|
||
| // Default small icon (overwritten below if paused) | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 6 spaces but found 12.
|
||
| smallImageKey: ActivityAssets.Play, | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 6 spaces but found 12.
|
||
| smallImageText: "Playing" | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 6 spaces but found 12.
Check failureCode scanning / ESLint Enforce the consistent use of either backticks, double, or single quotes Error
Strings must use singlequote.
|
||
| }; | ||
Check failureCode scanning / ESLint Require or disallow trailing commas Error
Missing trailing comma.
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
|
|
||
| // 3. TEXT STRATEGY (Browser Tab) | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
|
||
| // Parses "Song - Artist" or "Song • Artist" from the document title | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
|
||
| const tabTitle = document.title || ""; | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
Check failureCode scanning / ESLint Enforce the consistent use of either backticks, double, or single quotes Error
Strings must use singlequote.
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
| let separator = ""; | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
Check failureCode scanning / ESLint Enforce the consistent use of either backticks, double, or single quotes Error
Strings must use singlequote.
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
|
|
||
| if (tabTitle.includes(' - ')) separator = " - "; | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
Check failureCode scanning / ESLint Newline after if Error
Expect newline after if
Check failureCode scanning / ESLint Enforce the consistent use of either backticks, double, or single quotes Error
Strings must use singlequote.
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
| else if (tabTitle.includes(' • ')) separator = " • "; | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
Check failureCode scanning / ESLint Newline after if Error
Expect newline after if
Check failureCode scanning / ESLint Enforce the consistent use of either backticks, double, or single quotes Error
Strings must use singlequote.
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
|
|
||
| if (separator) { | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
|
||
| const parts = tabTitle.split(separator); | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 6 spaces but found 12.
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
| presenceData.details = parts[0]?.trim() || "Unknown Song"; | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 6 spaces but found 12.
Check failureCode scanning / ESLint Enforce the consistent use of either backticks, double, or single quotes Error
Strings must use singlequote.
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
| presenceData.state = parts.slice(1).join(separator).trim() || "Unknown Artist"; | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 6 spaces but found 12.
Check failureCode scanning / ESLint Enforce the consistent use of either backticks, double, or single quotes Error
Strings must use singlequote.
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
| } else { | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
Check failureCode scanning / ESLint Enforce consistent brace style for blocks Error
Closing curly brace appears on the same line as the subsequent block.
|
||
| // Fallback for non-standard titles | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 6 spaces but found 12.
|
||
| presenceData.details = "Monochrome"; | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 6 spaces but found 12.
Check failureCode scanning / ESLint Enforce the consistent use of either backticks, double, or single quotes Error
Strings must use singlequote.
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
| presenceData.state = "Listening..."; | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 6 spaces but found 12.
Check failureCode scanning / ESLint Enforce the consistent use of either backticks, double, or single quotes Error
Strings must use singlequote.
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
| } | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
|
||
|
|
||
| // 4. AUDIO STATUS & TIMESTAMPS | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
|
||
| const mediaElement = document.querySelector('audio'); | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
|
|
||
| if (mediaElement) { | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 4 spaces but found 8.
|
||
| if (!mediaElement.paused) { | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 6 spaces but found 12.
|
||
| // -- PLAYING STATE -- | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 8 spaces but found 16.
|
||
| presenceData.smallImageKey = ActivityAssets.Play; | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 8 spaces but found 16.
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
| presenceData.smallImageText = "Playing"; | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 8 spaces but found 16.
Check failureCode scanning / ESLint Enforce the consistent use of either backticks, double, or single quotes Error
Strings must use singlequote.
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
|
|
||
| // Calculate timestamps using native Date.now() for accuracy | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 8 spaces but found 16.
|
||
| const now = Date.now(); | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 8 spaces but found 16.
Check failureCode scanning / ESLint Require or disallow semicolons instead of ASI Error
Extra semicolon.
|
||
| presenceData.startTimestamp = now - (mediaElement.currentTime * 1000); | ||
Check failureCode scanning / ESLint Enforce consistent indentation Error
Expected indentation of 8 spaces but found 16.
|
||
|
|
||
| // Only set endTimestamp if duration is finite and positive | ||
| if (mediaElement.duration && Number.isFinite(mediaElement.duration) && mediaElement.duration > 0) { | ||
| presenceData.endTimestamp = now + ((mediaElement.duration - mediaElement.currentTime) * 1000); | ||
| } | ||
| } else { | ||
| // -- PAUSED STATE -- | ||
| presenceData.smallImageKey = ActivityAssets.Pause; | ||
| presenceData.smallImageText = "Paused"; | ||
| // Note: We do not set timestamps here, effectively hiding the time bar | ||
| } | ||
|
|
||
| presence.setActivity(presenceData); | ||
| } else { | ||
| // Clear activity if no audio player is found | ||
| presence.setActivity({}); | ||
| } | ||
| }); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.