Skip to content

Commit

Permalink
feat(LessWrong): add button for posts and profiles, display currently…
Browse files Browse the repository at this point in the history
… 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>
  • Loading branch information
tonybolivar and theusaf authored Dec 21, 2024
1 parent 9f7dd86 commit 4ce1e37
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion websites/L/LessWrong/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@
"forum",
"philosophy"
]
}
}
42 changes: 31 additions & 11 deletions websites/L/LessWrong/presence.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -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);
Expand Down

0 comments on commit 4ce1e37

Please sign in to comment.