From 4ce1e37aa30f29ab52007573abf38b5ddf1de7a8 Mon Sep 17 00:00:00 2001 From: Anthony Bolivar <71916060+tonybolivar@users.noreply.github.com> Date: Sat, 21 Dec 2024 06:50:38 -0500 Subject: [PATCH] feat(LessWrong): add button for posts and profiles, display currently viewed profile (#8959) * Update presence.ts Signed-off-by: Anthony Bolivar <71916060+tonybolivar@users.noreply.github.com> * Update metadata.json Signed-off-by: Anthony Bolivar <71916060+tonybolivar@users.noreply.github.com> * Update presence.ts Signed-off-by: Anthony Bolivar <71916060+tonybolivar@users.noreply.github.com> * Update presence.ts Signed-off-by: Anthony Bolivar <71916060+tonybolivar@users.noreply.github.com> * Add files via upload Signed-off-by: Anthony Bolivar <71916060+tonybolivar@users.noreply.github.com> * Add files via upload Signed-off-by: Anthony Bolivar <71916060+tonybolivar@users.noreply.github.com> * Update websites/L/LessWrong/presence.ts Co-authored-by: Daniel Lau <32113157+theusaf@users.noreply.github.com> Signed-off-by: Anthony Bolivar <71916060+tonybolivar@users.noreply.github.com> * Update presence.ts Signed-off-by: Anthony Bolivar <71916060+tonybolivar@users.noreply.github.com> --------- Signed-off-by: Anthony Bolivar <71916060+tonybolivar@users.noreply.github.com> Co-authored-by: Daniel Lau <32113157+theusaf@users.noreply.github.com> --- websites/L/LessWrong/metadata.json | 2 +- websites/L/LessWrong/presence.ts | 42 ++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/websites/L/LessWrong/metadata.json b/websites/L/LessWrong/metadata.json index 863990cf83c6..fda90a023e0e 100644 --- a/websites/L/LessWrong/metadata.json +++ b/websites/L/LessWrong/metadata.json @@ -26,4 +26,4 @@ "forum", "philosophy" ] -} \ No newline at end of file +} diff --git a/websites/L/LessWrong/presence.ts b/websites/L/LessWrong/presence.ts index cb21e6badee0..3700c11e8207 100644 --- a/websites/L/LessWrong/presence.ts +++ b/websites/L/LessWrong/presence.ts @@ -1,12 +1,7 @@ const presence = new Presence({ - clientId: "1310452380915077170", -}); - -function capitalize(string: string): string { - return string.charAt(0).toUpperCase() + string.substring(1); -} - -const browsingTimestamp = Math.floor(Date.now() / 1000); + clientId: "1310452380915077170", + }), + browsingTimestamp = Math.floor(Date.now() / 1000); let data; presence.on("UpdateData", async () => { @@ -21,10 +16,35 @@ presence.on("UpdateData", async () => { presenceData.state = "at Homepage"; } else if (document.location.pathname.startsWith("/posts/")) { data = document.location.pathname.split("/"); + const postTitle = + document.querySelector(".PostsPageTitle-link")?.textContent || + document.querySelector(".PostsPage-secondSplashPageHeader") + ?.textContent || + "Unknown Post"; presenceData.details = `Reading ${data[1]}`; - presenceData.state = `${capitalize( - data[3].replace(/-\d+$/, "").split("-").join(" ") - )}`; + presenceData.state = postTitle; + + presenceData.buttons = [ + { + label: "View Post", + url: new URL(document.location.pathname, document.location.origin).href, + }, + ]; + } else if (document.location.pathname.startsWith("/users/")) { + data = document.location.pathname.split("/"); + + presenceData.details = "Viewing User"; + presenceData.state = `${ + document.querySelector(".UsersProfile-usernameTitle")?.textContent || + "Loading User" + }'s profile`; + + presenceData.buttons = [ + { + label: "View Profile", + url: new URL(document.location.pathname, document.location.origin).href, + }, + ]; } else presenceData.details = "Browsing LessWrong"; if (presenceData.details) presence.setActivity(presenceData);