Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Heroku): add presence #6744

Merged
merged 13 commits into from
Sep 8, 2022
Prev Previous commit
Next Next commit
style: sort case statements
  • Loading branch information
theusaf committed Sep 2, 2022
commit 9f24b7b8189ddc487a6ad8574d4f0c5f7296b090
3 changes: 2 additions & 1 deletion websites/H/Heroku/dist/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"id": "showNames",
"value": false,
"multiLanguage": false,
"title": "Show Application Names"
"title": "Show Application Names",
"icon": "fas fa-text"
}
],
"tags": ["hosting", "application", "web"]
Expand Down
156 changes: 78 additions & 78 deletions websites/H/Heroku/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,84 +19,6 @@ presence.on("UpdateData", async () => {
}
break;
}
case "help.heroku.com": {
presenceData.details = "Browsing Heroku Support";
if (/^\/\d+$/.test(pathname)) {
presenceData.details = "Viewing Support Ticket";
presenceData.state = document.querySelector("h2").textContent;
} else if (
pathname === "/tickets/new" ||
(pathname === "/" && new URLSearchParams(search).get("t") === "true")
)
presenceData.state = "Creating a new ticket";
else if (pathname === "/tickets") presenceData.state = "Viewing tickets";
else {
presenceData.state =
document.querySelector("h2")?.textContent ||
document.querySelector("h1")?.textContent ||
document.title;
}
break;
}
case "brand.heroku.com": {
presenceData.details = "Browsing";
presenceData.state = "Brand";
break;
}
case "elements.heroku.com": {
presenceData.details = "Browsing Elements";
presenceData.state = document.title.match(
/(.*?)(?=(?: - Heroku Elements|$))/
)[1];
break;
}
case "data.heroku.com": {
presenceData.details = "Browsing Data";
if (pathname === "/") presenceData.state = "Looking at datastores";
else if (pathname === "/dataclips")
presenceData.state = "Looking at dataclips";
else if (pathname.startsWith("/datastores/")) {
if (await presence.getSetting<boolean>("showNames")) {
presenceData.state = `Viewing datastore '${document.title.match(
/(.*?)(?=(?: \| Heroku Data|$))/
)}'`;
} else presenceData.state = "Viewing a datastore";
} else if (pathname.startsWith("/dataclips/")) {
if (await presence.getSetting<boolean>("showNames")) {
presenceData.state = `Viewing dataclip '${document.title.match(
/(.*?)(?=(?: \| Heroku Data|$))/
)}'`;
} else presenceData.state = "Viewing a dataclip";
}
break;
}
case "devcenter.heroku.com": {
presenceData.details = "Browsing Dev Center";
if (pathname === "/") presenceData.state = "Home page";
else {
presenceData.state = document.title.match(
/(.*?)(?=(?: \| Heroku Dev Center|$))/
)[1];
}
break;
}
case "status.heroku.com": {
presenceData.details = "Viewing Heroku Status";
if (pathname === "/incidents") presenceData.state = "Past incidents";
else if (pathname.startsWith("/incidents/")) {
presenceData.state = document.title.match(
/(.*?)(?=(?: \| Heroku Status|$))/
)[1];
} else {
const [appStatus, dataStatus, toolsStatus] = document.querySelectorAll(
".container.body-container > div a > .status-summary__description"
);
presenceData.state = `Apps: ${appStatus.textContent.replace(/\s/g, "")}
Data: ${dataStatus.textContent.replace(/\s/g, "")}
Tools: ${toolsStatus.textContent.replace(/\s/g, "")}`;
}
break;
}
case "blog.heroku.com": {
presenceData.details = "Browsing blog posts";
if (pathname !== "/") {
Expand All @@ -106,6 +28,11 @@ Tools: ${toolsStatus.textContent.replace(/\s/g, "")}`;
}
break;
}
case "brand.heroku.com": {
presenceData.details = "Browsing";
presenceData.state = "Brand";
break;
}
case "dashboard.heroku.com": {
presenceData.details = "Viewing Dashboard";
if (pathname === "/apps") presenceData.state = "Apps";
Expand Down Expand Up @@ -163,6 +90,79 @@ Tools: ${toolsStatus.textContent.replace(/\s/g, "")}`;
}
break;
}
case "data.heroku.com": {
presenceData.details = "Browsing Data";
if (pathname === "/") presenceData.state = "Looking at datastores";
else if (pathname === "/dataclips")
presenceData.state = "Looking at dataclips";
else if (pathname.startsWith("/datastores/")) {
if (await presence.getSetting<boolean>("showNames")) {
theusaf marked this conversation as resolved.
Show resolved Hide resolved
presenceData.state = `Viewing datastore '${document.title.match(
/(.*?)(?=(?: \| Heroku Data|$))/
)}'`;
} else presenceData.state = "Viewing a datastore";
} else if (pathname.startsWith("/dataclips/")) {
if (await presence.getSetting<boolean>("showNames")) {
presenceData.state = `Viewing dataclip '${document.title.match(
/(.*?)(?=(?: \| Heroku Data|$))/
)}'`;
} else presenceData.state = "Viewing a dataclip";
}
break;
}
case "devcenter.heroku.com": {
presenceData.details = "Browsing Dev Center";
if (pathname === "/") presenceData.state = "Home page";
else {
presenceData.state = document.title.match(
/(.*?)(?=(?: \| Heroku Dev Center|$))/
)[1];
}
break;
}
case "elements.heroku.com": {
presenceData.details = "Browsing Elements";
presenceData.state = document.title.match(
/(.*?)(?=(?: - Heroku Elements|$))/
)[1];
break;
}
case "help.heroku.com": {
presenceData.details = "Browsing Heroku Support";
if (/^\/\d+$/.test(pathname)) {
presenceData.details = "Viewing Support Ticket";
presenceData.state = document.querySelector("h2").textContent;
} else if (
pathname === "/tickets/new" ||
(pathname === "/" && new URLSearchParams(search).get("t") === "true")
)
presenceData.state = "Creating a new ticket";
else if (pathname === "/tickets") presenceData.state = "Viewing tickets";
else {
presenceData.state =
document.querySelector("h2")?.textContent ||
document.querySelector("h1")?.textContent ||
document.title;
}
break;
}
case "status.heroku.com": {
presenceData.details = "Viewing Heroku Status";
if (pathname === "/incidents") presenceData.state = "Past incidents";
else if (pathname.startsWith("/incidents/")) {
presenceData.state = document.title.match(
/(.*?)(?=(?: \| Heroku Status|$))/
)[1];
} else {
const [appStatus, dataStatus, toolsStatus] = document.querySelectorAll(
".container.body-container > div a > .status-summary__description"
);
presenceData.state = `Apps: ${appStatus.textContent.replace(/\s/g, "")}
Data: ${dataStatus.textContent.replace(/\s/g, "")}
Tools: ${toolsStatus.textContent.replace(/\s/g, "")}`;
}
break;
}
}

if (presenceData.details) presence.setActivity(presenceData);
EncryptedDev marked this conversation as resolved.
Show resolved Hide resolved
Expand Down