-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(Typersguild): add activity #10359
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
heydathan
wants to merge
7
commits into
PreMiD:main
Choose a base branch
from
heydathan: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 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f7cc686
Typersguild
akashdathan 39667cb
feat(Typersguild): created
akashdathan 0b32c24
Merge remote-tracking branch 'origin/main'
akashdathan 118e303
refactor(Typersguild): updated name and state
heydathan b6ec077
Merge branch 'main' into main
heydathan 7d7baf6
Merge branch 'main' into main
heydathan 43642f2
Merge branch 'main' into main
heydathan 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,29 @@ | ||
| { | ||
| "$schema": "https://schemas.premid.app/metadata/1.16", | ||
| "apiVersion": 1, | ||
| "author": { | ||
| "id": "620949166604156955", | ||
| "name": "heydathan" | ||
| }, | ||
| "service": "Typersguild", | ||
| "description": { | ||
| "en": "Practice typing by retyping entire books. Improve your speed with 100+ classics and real-time WPM tracking" | ||
| }, | ||
| "url": "typersguild.com", | ||
| "regExp": "^https?[:][/][/]([a-z0-9-]+[.])*typersguild[.]com[/]", | ||
| "version": "1.0.0", | ||
| "logo": "https://typersguild.com/android-chrome-512x512.png", | ||
| "thumbnail": "https://typersguild.com/books.webp", | ||
| "color": "#6366f1", | ||
| "category": "other", | ||
| "tags": [ | ||
| "typing", | ||
| "books", | ||
| "learning", | ||
| "productivity", | ||
| "practice", | ||
| "speed", | ||
| "reading", | ||
| "education" | ||
| ] | ||
| } |
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,110 @@ | ||
| import { ActivityType, StatusDisplayType } from 'premid' | ||
|
|
||
| const presence = new Presence({ | ||
| clientId: '1459578800223420416', | ||
| }) | ||
|
|
||
| const browsingTimestamp = Math.floor(Date.now() / 1000) | ||
|
|
||
| enum ActivityAssets { | ||
| Logo = 'https://typersguild.com/android-chrome-512x512.png', | ||
| } | ||
|
|
||
| enum ContentType { | ||
| Book = 'book', | ||
| Wiki = 'wiki', | ||
| Browsing = 'browsing', | ||
| } | ||
|
|
||
| function getBookName(): string { | ||
| const presenceName = document | ||
| .querySelector('[data-presence-book-name]') | ||
| ?.getAttribute('data-presence-book-name') | ||
| ?.trim() | ||
|
|
||
| return presenceName || 'a book' | ||
| } | ||
|
|
||
| function getBookAuthor(): string { | ||
| const authorName = document | ||
| .querySelector('[data-presence-book-author]') | ||
| ?.getAttribute('data-presence-book-author') | ||
| ?.trim() | ||
|
|
||
| return authorName || 'Unknown Author' | ||
| } | ||
|
|
||
| function getBookCover(): string | null { | ||
| const coverUrl = document | ||
| .querySelector('[data-presence-book-cover]') | ||
| ?.getAttribute('data-presence-book-cover') | ||
| ?.trim() | ||
|
|
||
| return coverUrl || null | ||
| } | ||
|
|
||
| function getContentType(path: string): ContentType { | ||
| if (/^\/books\/[^/]+\/chapter\/\d+/.test(path)) { | ||
| return ContentType.Book | ||
| } | ||
|
|
||
| if (/^\/my-books\/[^/]+\/chapter\/\d+/.test(path)) { | ||
| return ContentType.Book | ||
| } | ||
|
|
||
| if (/^\/wiki\/[^/]+\/[^/]+/.test(path)) { | ||
| return ContentType.Wiki | ||
| } | ||
|
|
||
| return ContentType.Browsing | ||
| } | ||
|
|
||
| presence.on('UpdateData', async () => { | ||
| const { pathname } = document.location | ||
| const contentType = getContentType(pathname) | ||
|
|
||
| const presenceData: PresenceData = { | ||
| type: ActivityType.Playing, | ||
| name: 'Typing on Typersguild', | ||
| statusDisplayType: StatusDisplayType.Details, | ||
| largeImageKey: ActivityAssets.Logo, | ||
| largeImageUrl: 'https://typersguild.com/books', | ||
| detailsUrl: 'https://typersguild.com/books', | ||
| startTimestamp: browsingTimestamp, | ||
| } | ||
|
|
||
| switch (contentType) { | ||
| case ContentType.Book: | ||
| { const bookCover = getBookCover() | ||
| const bookName = getBookName() | ||
| if (bookCover) { | ||
| presenceData.largeImageKey = bookCover | ||
| } | ||
|
|
||
| presenceData.details = bookName | ||
| presenceData.state = `by ${getBookAuthor()}` | ||
|
|
||
| break | ||
| } | ||
|
|
||
| case ContentType.Wiki: | ||
| presenceData.details = getBookName() | ||
| presenceData.state = 'Typing Wikipedia' | ||
|
|
||
|
||
| break | ||
|
|
||
| case ContentType.Browsing: | ||
| presenceData.name = 'Browsing Typersguild' | ||
| presenceData.details = 'Typersguild' | ||
| presenceData.state = 'Books, Wikis, and more' | ||
|
|
||
| break | ||
| } | ||
|
|
||
| if (presenceData.state) { | ||
| 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
namefield should just be the name of the activity. Actions like "typing on..." should be in thedetailsfield.You can use the
statusDisplayTypefield to change which string appears as the main one in Discord if you likeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the "typing on" action to the state. And updated the screenshots