Skip to content

Commit

Permalink
feat(Stack Overflow): add buttons with setting (PreMiD#6754)
Browse files Browse the repository at this point in the history
  • Loading branch information
RisingSunLight42 authored Sep 5, 2022
1 parent 58d9bb0 commit 7c2a4a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
10 changes: 9 additions & 1 deletion websites/S/Stack Overflow/dist/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@
"nl": "Stack Overflow is een open community voor iedereen die codeert. Het helpt je om antwoorden op je moeilijkste codeervragen te krijgen, kennis met je collega's privé te delen en je volgende droombaan te vinden."
},
"url": "stackoverflow.com",
"version": "2.3.14",
"version": "2.4.0",
"logo": "https://i.imgur.com/iTWct8S.png",
"thumbnail": "https://i.imgur.com/Z4LQn2d.png",
"color": "#f48023",
"category": "other",
"tags": [
"coding",
"help"
],
"settings": [
{
"id": "buttons",
"title": "Show Buttons",
"icon": "fas fa-compress-arrows-alt",
"value": true
}
]
}
34 changes: 10 additions & 24 deletions websites/S/Stack Overflow/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const presence = new Presence({
clientId: "610123745033584651",
}),
browsingTimestamp = Math.floor(Date.now() / 1000);

let title: HTMLAnchorElement,
pageNumber: HTMLElement,
jobPageNumber: HTMLAnchorElement,
Expand All @@ -13,9 +14,11 @@ let title: HTMLAnchorElement,

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
details: "Unknown page",
largeImageKey: "lg",
};
details: "Unknown page",
largeImageKey: "lg",
startTimestamp: browsingTimestamp,
},
showButtons = await presence.getSetting<boolean>("buttons");

title = document.querySelector("div#question-header h1 a");

Expand Down Expand Up @@ -47,15 +50,12 @@ presence.on("UpdateData", async () => {

if (title && document.location.pathname.includes("/questions/")) {
presenceData.details = "Reading a question.";

presenceData.state = title.textContent;

presenceData.startTimestamp = browsingTimestamp;
presenceData.buttons = [
{ label: "View Question", url: document.location.href },
];
} else if (document.location.pathname === "/") {
presenceData.state = "Main Page | Home";

presenceData.startTimestamp = browsingTimestamp;

delete presenceData.details;
} else if (
document.location.pathname === "/questions" &&
Expand All @@ -66,15 +66,11 @@ presence.on("UpdateData", async () => {

if (lastquestionsPageNumber > lastPageNumber) {
presence.info(`${lastPageNumber} --- ${lastquestionsPageNumber}`);

lastPage = pageNumber.textContent;
}

presenceData.details = "Browsing all the questions.";

presenceData.state = `Current page: ${pageNumber.textContent}/${lastPage}`;

presenceData.startTimestamp = browsingTimestamp;
} else {
switch (document.location.pathname) {
case "/jobs": {
Expand All @@ -90,9 +86,6 @@ presence.on("UpdateData", async () => {
presenceData.details = "Browsing jobs.";

presenceData.state = `Current page: ${jobPageNumber.textContent}/${lastPage}`;

presenceData.startTimestamp = browsingTimestamp;

break;
}
case "/users": {
Expand All @@ -109,9 +102,6 @@ presence.on("UpdateData", async () => {
presenceData.details = "Browsing users.";

presenceData.state = `Current page: ${usersortagsPageNumber.textContent}/${lastPage}`;

presenceData.startTimestamp = browsingTimestamp;

break;
}
case "/tags": {
Expand All @@ -126,16 +116,12 @@ presence.on("UpdateData", async () => {
}

presenceData.details = "Browsing tags.";

presenceData.state = `Current page: ${usersortagsPageNumber.textContent}/${lastPage}`;

presenceData.startTimestamp = browsingTimestamp;

break;
}
// No default
}
}

if (!showButtons) delete presenceData.buttons;
presence.setActivity(presenceData);
});

0 comments on commit 7c2a4a0

Please sign in to comment.