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);