-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(The StoryGraph): add activity (#9352)
- Loading branch information
Showing
3 changed files
with
378 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 @@ | ||
{ | ||
"thestorygraph.buttonViewBook": { | ||
"description": "Used as the title for the button in Discord.", | ||
"message": "View Book" | ||
}, | ||
"thestorygraph.viewBook": { | ||
"description": "Used to display the details of a selected book.", | ||
"message": "Viewing book:" | ||
}, | ||
"thestorygraph.viewSimilarBook": { | ||
"description": "Used to show books that are similar to the selected book.", | ||
"message": "Viewing similar books of:" | ||
}, | ||
"thestorygraph.viewEdition": { | ||
"description": "Used to view different editions of the selected book.", | ||
"message": "Viewing editions of:" | ||
}, | ||
"thestorygraph.viewContentWarnings": { | ||
"description": "Used to display content warnings related to the selected book.", | ||
"message": "Viewing content warnings of:" | ||
}, | ||
"thestorygraph.readBookClubQuestions": { | ||
"description": "Used to access questions for book club discussions.", | ||
"message": "Reading Book Club Questions of:" | ||
}, | ||
"thestorygraph.readReviews": { | ||
"description": "Used to read reviews written about the selected book.", | ||
"message": "Reading reviews of:" | ||
}, | ||
"thestorygraph.readReview": { | ||
"description": "Used to read a specific review of the selected book.", | ||
"message": "Reading review of:" | ||
}, | ||
"thestorygraph.buttonReadReview": { | ||
"description": "Used as the title for the button in Discord.", | ||
"message": "Read Review" | ||
}, | ||
"thestorygraph.readalongs": { | ||
"description": "Used to view readalongs available for the selected book.", | ||
"message": "Viewing readalongs" | ||
}, | ||
"thestorygraph.buddyReads": { | ||
"description": "Used to show buddy reads in progress.", | ||
"message": "Viewing Buddy Reads" | ||
}, | ||
"thestorygraph.bookTickets": { | ||
"description": "Used to report a book issue or concern.", | ||
"message": "Reporting a Book" | ||
}, | ||
"thestorygraph.viewStats": { | ||
"description": "Used to view reading statistics.", | ||
"message": "Viewing Stats" | ||
}, | ||
"thestorygraph.viewReadingChallenges": { | ||
"description": "Used to view challenges related to reading.", | ||
"message": "Viewing Reading Challenges" | ||
}, | ||
"thestorygraph.viewCommunity": { | ||
"description": "Used to view community interactions and discussions.", | ||
"message": "Viewing Community" | ||
}, | ||
"thestorygraph.viewBookClubs": { | ||
"description": "Used to view available book clubs.", | ||
"message": "Viewing Book Clubs" | ||
}, | ||
"thestorygraph.viewSimilarUsers": { | ||
"description": "Used to view users with similar reading interests.", | ||
"message": "Viewing Similar Users" | ||
}, | ||
"thestorygraph.viewGiveaways": { | ||
"description": "Used to view available book giveaways.", | ||
"message": "Viewing Giveaways" | ||
}, | ||
"thestorygraph.viewGiveaway": { | ||
"description": "Used to view a specific book giveaway.", | ||
"message": "Viewing Giveaway:" | ||
}, | ||
"thestorygraph.buttonViewGiveaway": { | ||
"description": "Used as the title for the button in Discord.", | ||
"message": "View Giveaway" | ||
}, | ||
"thestorygraph.viewEnteredGiveaways": { | ||
"description": "Used to view giveaways that the user has entered.", | ||
"message": "Viewing Entered Giveaways" | ||
}, | ||
"thestorygraph.viewNotifications": { | ||
"description": "Used to view notifications related to user activities.", | ||
"message": "Viewing notifications" | ||
}, | ||
"thestorygraph.viewPreferences": { | ||
"description": "Used to view user preferences.", | ||
"message": "Viewing Preferences" | ||
}, | ||
"thestorygraph.viewProfile": { | ||
"description": "Used to view the profile of a specific user.", | ||
"message": "Viewing Profile of:" | ||
}, | ||
"thestorygraph.buttonViewProfile": { | ||
"description": "Used as the title for the button in Discord.", | ||
"message": "View Profile" | ||
}, | ||
"thestorygraph.editProfile": { | ||
"description": "Used to edit the user's profile information.", | ||
"message": "Editing Profile" | ||
}, | ||
"thestorygraph.viewReadingJournal": { | ||
"description": "Used to view the user's reading journal.", | ||
"message": "Viewing Reading Journal" | ||
} | ||
} |
This file contains 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,23 @@ | ||
{ | ||
"$schema": "https://schemas.premid.app/metadata/1.13", | ||
"apiVersion": 1, | ||
"author": { | ||
"id": "354233941550694400", | ||
"name": "kuriel." | ||
}, | ||
"service": "The StoryGraph", | ||
"description": { | ||
"en": "A site for you to track your reading and choose your next book", | ||
"pt": "Um sítio web para rastrear a sua leitura e escolher o seu próximo livro", | ||
"pt-br": "Um site para você rastrear sua leitura e escolher seu próximo livro" | ||
}, | ||
"url": "app.thestorygraph.com", | ||
"version": "1.0.0", | ||
"logo": "https://i.imgur.com/jgyqQZq.png", | ||
"thumbnail": "https://i.imgur.com/NyNVraQ.png", | ||
"color": "#2ab5c0", | ||
"category": "socials", | ||
"tags": [ | ||
"books" | ||
] | ||
} |
This file contains 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,245 @@ | ||
const presence = new Presence({ | ||
clientId: '1345071934563418153', | ||
}) | ||
const browsingTimestamp = Math.floor(Date.now() / 1000) | ||
|
||
enum ActivityAssets { | ||
Logo = 'https://i.imgur.com/jgyqQZq.png', | ||
} | ||
|
||
async function getStrings() { | ||
return presence.getStrings({ | ||
browsing: 'general.browsing', | ||
viewHome: 'general.viewHome', | ||
searchFor: 'general.searchFor', | ||
viewPage: 'general.viewPage', | ||
terms: 'general.terms', | ||
privacy: 'general.privacy', | ||
buttonViewBook: 'thestorygraph.buttonViewBook', | ||
viewBook: 'thestorygraph.viewBook', | ||
viewSimilarBook: 'thestorygraph.viewSimilarBook', | ||
viewEdition: 'thestorygraph.viewEdition', | ||
viewContentWarnings: 'thestorygraph.viewContentWarnings', | ||
readBookClubQuestions: 'thestorygraph.readBookClubQuestions', | ||
readReviews: 'thestorygraph.readReviews', | ||
readReview: 'thestorygraph.readReview', | ||
bookTickets: 'thestorygraph.bookTickets', | ||
buddyReads: 'thestorygraph.buddyReads', | ||
readalongs: 'thestorygraph.readalongs', | ||
viewStats: 'thestorygraph.viewStats', | ||
viewReadingChallenges: 'thestorygraph.viewReadingChallenges', | ||
viewCommunity: 'thestorygraph.viewCommunity', | ||
viewBookClubs: 'thestorygraph.viewBookClubs', | ||
viewSimilarUsers: 'thestorygraph.viewSimilarUsers', | ||
viewEnteredGiveaways: 'thestorygraph.viewEnteredGiveaways', | ||
viewGiveaway: 'thestorygraph.viewGiveaway', | ||
viewGiveaways: 'thestorygraph.viewGiveaways', | ||
buttonViewGiveaway: 'thestorygraph.buttonViewGiveaway', | ||
viewNotifications: 'thestorygraph.viewNotifications', | ||
viewPreferences: 'thestorygraph.viewPreferences', | ||
buttonReadReview: 'thestorygraph.buttonReadReview', | ||
viewProfile: 'thestorygraph.viewProfile', | ||
buttonViewProfile: 'thestoryGraph.buttonViewProfile', | ||
editProfile: 'thestorygraph.editProfile', | ||
viewReadingJournal: 'thestorygraph.viewReadingJournal', | ||
}) | ||
} | ||
|
||
presence.on('UpdateData', async () => { | ||
const presenceData: PresenceData = { | ||
largeImageKey: ActivityAssets.Logo, | ||
startTimestamp: browsingTimestamp, | ||
} | ||
const { pathname, href, search } = document.location | ||
const strings = await getStrings() | ||
|
||
switch (pathname.split('/')[1]) { | ||
case 'books': { | ||
if (pathname.split('/')[3] === 'similar') { | ||
presenceData.details = strings.viewSimilarBook | ||
presenceData.state = document.querySelector('.standard-link')?.textContent | ||
} | ||
if (pathname.split('/')[3] === 'editions') { | ||
presenceData.details = strings.viewEdition | ||
presenceData.state = document.querySelector('h3:nth-child(1) > a:nth-child(2)')?.textContent | ||
} | ||
if (pathname.split('/')[3] === 'content_warnings') { | ||
presenceData.details = strings.viewContentWarnings | ||
presenceData.state = document.querySelector('.standard-link')?.textContent | ||
} | ||
else { | ||
presenceData.details = strings.viewBook | ||
presenceData.state = document.title.slice(0, document.title.length - '| The StoryGraph'.length).trim() | ||
presenceData.buttons = [ | ||
{ | ||
label: strings.buttonViewBook, | ||
url: href, | ||
}, | ||
] | ||
presenceData.largeImageKey = document.querySelector<HTMLImageElement>('.book-cover >img')?.src ?? ActivityAssets.Logo | ||
} | ||
break | ||
} | ||
case 'users': { | ||
switch (pathname.split('/')[2]) { | ||
case 'sign_in': | ||
case 'password': | ||
case 'sign_up': { | ||
presenceData.details = strings.viewPage | ||
presenceData.state = 'Login' | ||
break | ||
} | ||
} | ||
break | ||
} | ||
case 'plus': { | ||
presenceData.details = strings.viewPage | ||
presenceData.state = 'The StoryGraph Plus' | ||
break | ||
} | ||
case 'app': { | ||
presenceData.details = strings.viewPage | ||
presenceData.state = 'App' | ||
break | ||
} | ||
case 'terms-of-service': { | ||
presenceData.details = strings.viewPage | ||
presenceData.state = strings.terms | ||
break | ||
} | ||
case 'privacy': { | ||
presenceData.details = strings.viewPage | ||
presenceData.state = strings.privacy | ||
break | ||
} | ||
case 'browse': { | ||
presenceData.details = strings.browsing | ||
if (search.includes('search_term')) { | ||
presenceData.details = strings.searchFor | ||
presenceData.state = decodeURIComponent( | ||
search?.split('=')[1] ?? '', | ||
) | ||
} | ||
break | ||
} | ||
case 'book_club_questions': { | ||
presenceData.details = strings.readBookClubQuestions | ||
presenceData.state = document.querySelector('.text-lg')?.textContent | ||
break | ||
} | ||
case 'book_reviews': { | ||
presenceData.details = strings.readReviews | ||
presenceData.state = document.querySelector('.standard-link')?.textContent | ||
break | ||
} | ||
case 'reviews': { | ||
presenceData.details = strings.readReview | ||
presenceData.state = document.querySelector('h4 > .standard-link')?.textContent | ||
presenceData.buttons = [ | ||
{ | ||
label: strings.buttonReadReview, | ||
url: href, | ||
}, | ||
] | ||
break | ||
} | ||
case 'book_tickets': { | ||
presenceData.details = strings.bookTickets | ||
break | ||
} | ||
case 'readalongs': { | ||
presenceData.details = strings.readalongs | ||
break | ||
} | ||
case 'buddy-reads': { | ||
presenceData.details = strings.buddyReads | ||
break | ||
} | ||
case 'community': { | ||
presenceData.details = strings.viewCommunity | ||
break | ||
} | ||
case 'book_clubs': { | ||
presenceData.details = strings.viewBookClubs | ||
break | ||
} | ||
case 'similar-users': { | ||
presenceData.details = strings.viewSimilarUsers | ||
break | ||
} | ||
case 'giveaway_entries': { | ||
presenceData.details = strings.viewEnteredGiveaways | ||
break | ||
} | ||
case 'stats': { | ||
presenceData.details = strings.viewStats | ||
break | ||
} | ||
case 'reading_challenges': { | ||
presenceData.details = strings.viewReadingChallenges | ||
break | ||
} | ||
case 'giveaways': { | ||
presenceData.details = strings.viewGiveaways | ||
if (pathname.split('/')[2]) { | ||
presenceData.details = strings.viewGiveaway | ||
presenceData.state = document.querySelector('h2.text-base')?.textContent | ||
presenceData.buttons = [ | ||
{ | ||
label: strings.buttonViewGiveaway, | ||
url: href, | ||
}, | ||
] | ||
presenceData.largeImageKey = document.querySelector<HTMLImageElement>('img.rounded-sm')?.src ?? ActivityAssets.Logo | ||
} | ||
break | ||
} | ||
case 'profile': { | ||
presenceData.details = strings.viewProfile | ||
presenceData.buttons = [ | ||
{ | ||
label: strings.buttonViewProfile, | ||
url: href, | ||
}, | ||
] | ||
presenceData.state = document.querySelector('div.w-max')?.textContent?.replace('Edit your profile', '') | ||
presenceData.largeImageKey = document.querySelector<HTMLImageElement>('img.object-cover')?.src ?? ActivityAssets.Logo | ||
if (pathname.split('/')[2] === 'edit') { | ||
presenceData.details = strings.editProfile | ||
} | ||
break | ||
} | ||
case 'currently-reading': | ||
case 'books-read': | ||
case 'to-read': | ||
case 'five_star_reads': { | ||
presenceData.details = strings.viewPage | ||
// eslint-disable-next-line unicorn/prefer-dom-node-text-content | ||
presenceData.state = document.querySelector<HTMLHeadingElement>('.page-heading')?.innerText?.trim() ?? null | ||
break | ||
} | ||
case 'journal': { | ||
presenceData.details = strings.viewReadingJournal | ||
break | ||
} | ||
case 'notifications': { | ||
presenceData.details = strings.viewNotifications | ||
break | ||
} | ||
case 'preferences': { | ||
presenceData.details = strings.viewPreferences | ||
break | ||
} | ||
default: { | ||
if (pathname.split('/')[1]) { | ||
presenceData.details = strings.browsing | ||
} | ||
else { | ||
presenceData.details = strings.viewHome | ||
} | ||
break | ||
} | ||
} | ||
|
||
presence.setActivity(presenceData) | ||
}) |