Skip to content

Commit

Permalink
Created Ko-Fi presence (PreMiD#4142)
Browse files Browse the repository at this point in the history
* Created Ko-Fi presence

* [CodeFactor] Apply fixes to commit 671ffe2

* Fixed CodeFactor problems

* Fixed explore page duplication.

* Ran prettier on the file.

* Fixed the last CodeFactor problem.

* Fixed Codacy quoting problem.

* Fixed unneeded .textContent splits and fixed URLSplit.

* Fixed array destructuring?

* Fixed URLSplit problems?

* Fixed array destructuring?

* [CodeFactor] Apply fixes to commit 4670544

* Fixed array destructuring?

* [CodeFactor] Apply fixes

* Changed order to hopefully fix array destructuring

* Reverted back to working URLSplit.

* Fixed URLSplit

Co-authored-by: Bas950 <bas.van.zanten007@gmail.com>

* Fixed last URLSplit problem.

Co-authored-by: codefactor-io <support@codefactor.io>
Co-authored-by: Bas950 <bas.van.zanten007@gmail.com>
  • Loading branch information
3 people authored Jul 31, 2021
1 parent b2f920c commit 7849571
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 0 deletions.
23 changes: 23 additions & 0 deletions websites/K/Ko-Fi/dist/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://schemas.premid.app/metadata/1.3",
"service": "Ko-Fi",
"author": {
"name": "Dzlandis",
"id": "259708781166985217"
},
"category": "other",
"logo": "https://i.imgur.com/EzWg3eE.png",
"thumbnail": "https://i.imgur.com/fa1gCIG.png",
"version": "1.0.0",
"color": "#28AAE0",
"tags": [
"kofi",
"donation",
"support",
"coffee"
],
"url": "ko-fi.com",
"description": {
"en": "Ko-fi lets creators receive support from fans of their content for the price of a coffee!"
}
}
172 changes: 172 additions & 0 deletions websites/K/Ko-Fi/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
const presence = new Presence({
clientId: "855316349655711744"
}),
browsingStamp = Math.floor(Date.now() / 1000);

presence.on("UpdateData", () => {
const presenceData: PresenceData = {
largeImageKey: "logo",
startTimestamp: browsingStamp
};
if (document.location.pathname === "/")
presenceData.details = "Viewing the home page.";
else if (document.location.pathname.startsWith("/dashboard/")) {
const title = document
.querySelector(
"body > div.app > header > ul.navbar-nav.ml-auto.d-none.d-sm-inline-block > div > div"
)
.textContent
.trim();
presenceData.details = "Managing the settings of:";
presenceData.state = title;
} else if (
document.location.pathname.toLowerCase().startsWith("/account/register")
)
presenceData.details = "Registering...";
else if (
document.location.pathname.toLowerCase().startsWith("/account/login") ||
document.location.pathname
.toLowerCase()
.startsWith("/account/externallogincallback")
)
presenceData.details = "Logining in...";
else if (document.location.pathname.toLowerCase().startsWith("/account/"))
presenceData.details = "Setting up account...";
else if (document.location.pathname.startsWith("/gold"))
presenceData.details = "Viewing the Gold plan.";
else if (document.location.pathname.startsWith("/art"))
presenceData.details = "Viewing art creations.";
else if (document.location.pathname.startsWith("/cosplay"))
presenceData.details = "Viewing cosplay creations.";
else if (document.location.pathname.startsWith("/commissionsopen"))
presenceData.details = "Viewing open commissions.";
else if (
document.location.pathname.toLowerCase().startsWith("/home/featured")
)
presenceData.details = "Viewing featured creators.";
else if (document.location.pathname.toLowerCase() === "/explore")
presenceData.details = "Viewing the explore page.";
else if (document.location.pathname.toLowerCase().startsWith("/blog/"))
presenceData.details = "Creating a blog post...";
else if (document.location.pathname.toLowerCase().startsWith("/manage"))
presenceData.details = "Managing Ko-Fi";
else if (document.location.pathname.toLowerCase().startsWith("/settings"))
presenceData.details = "Adjusting user settings...";
else if (document.location.pathname.toLowerCase().startsWith("/newsfeed"))
presenceData.details = "Viewing the newsfeed...";
else if (
document.location.pathname.toLowerCase().startsWith("/my-supporters")
)
presenceData.details = "Viewing supporters...";
else if (document.location.pathname.toLowerCase().startsWith("/streamalerts"))
presenceData.details = "Viewing stream alerts.";
else if (document.location.pathname.toLowerCase().startsWith("/shop"))
presenceData.details = "Viewing shop.";
else if (document.location.pathname.toLowerCase() === "/about")
presenceData.details = "Viewing Ko-Fi's About Page";
else if (document.location.pathname.toLowerCase().startsWith("/s/")) {
try {
const shopItem = document
.querySelector(
"#shop-item-detail > div > div.kfds-lyt-between-algn-top-row-to-col.kfds-c-sticky > div.sidebar.kfds-c-sticky-wrapper.kfds-c-order-2.kfds-c-shop-detail-wrapper > div.kfds-lyt-width-100.kfds-c-lyt-pdg-16-24.kfds-c-shop-detail-column-control > span"
)
.textContent
.trim(),
shopOwner = document
.querySelector(
"#shop-item-detail > div > div.kfds-lyt-between-algn-top-row-to-col.kfds-c-sticky > div.sidebar.kfds-c-sticky-wrapper.kfds-c-order-2.kfds-c-shop-detail-wrapper > div.kfds-lyt-width-100.kfds-c-lyt-pdg-16-24.kfds-c-shop-detail-column-control > div > a > div > span:nth-child(1)"
)
.textContent
.trim(),
[, , URLSplit ] = document.location.pathname.split("/"),
URL = `https://ko-fi.com/s/${URLSplit}?ref=premid_discord_presence`;
presenceData.details = `Viewing ${shopItem}`;
presenceData.state = `By ${shopOwner}`;
presenceData.buttons = [{ label: "View Item", url: URL }];
} catch {
presenceData.details = "Viewing a shop item.";
}
} else if (document.location.pathname.toLowerCase().startsWith("/summary"))
presenceData.details = "Viewing payment summary.";
else if (
document.location.pathname.toLowerCase().startsWith("/home/coffeeshop")
)
presenceData.details = "Just bought someone coffee!";
else if (document.location.pathname.toLowerCase().startsWith("/home/about"))
presenceData.details = "Viewing Ko-Fi's About Page";
else if (document.location.pathname.toLowerCase().startsWith("/home"))
presenceData.details = "Viewing the home page.";
else if (document.location.pathname.toLowerCase().startsWith("/post")) {
presenceData.details = "Viewing a post.";
try {
const postName = document
.querySelector(
"#body-content > div > div.wrapper.wrapper-content.article > div > div > div > div > div:nth-child(4) > div > h1"
)
.textContent
.trim(),
[, , URLSplit ] = document.location.pathname.split("/"),
URL = `https://ko-fi.com/post/${URLSplit}?ref=premid_discord_presence`;
presenceData.details = "Viewing a post:";
presenceData.state = postName;
presenceData.buttons = [{ label: "View Post", url: URL }];
} catch {
presenceData.details = "Viewing a post.";
}
} else if (document.location.pathname.toLowerCase().startsWith("/album")) {
try {
const user = document
.querySelector(
"#body-content > div > div > div:nth-child(2) > div > a > name"
)
.textContent
.trim();
presenceData.details = "Viewing an album.";
if (user !== "undefined") {
presenceData.details = "Viewing a users album:";
presenceData.state = user;
}
} catch {
presenceData.details = "Viewing an album.";
}
} else if (document.location.pathname.toLowerCase() === "/404.html")
presenceData.details = "Oh No! Page Not Found.";
else {
try {
const user = document
.querySelector(
"#profile-header-v2 > div > div.kfds-lyt-column.kfds-lyt-width-100.kfds-c-header-showmobile-at-736 > div.kfds-lyt-row-start.kfds-lyt-width-100 > div > div.kfds-font-size-22.kfds-font-bold > span"
)
.textContent
.trim(),
userSplit = document.location.pathname.split("/");
// userFixed = user.toLowerCase().split(" ").join("");
// console.log(userFixed)

if (user !== "undefined") {
const userURL = `https://ko-fi.com/${userSplit[1]}?ref=premid_discord_presence`;

presenceData.details = "Viewing this users page:";
presenceData.state = user;
presenceData.buttons = [{ label: "View Page", url: userURL }];
}

if (document.location.pathname.startsWith(`/${userSplit[1]}/gallery`))
presenceData.details = "Viewing this users gallery:";
else if (document.location.pathname.startsWith(`/${userSplit[1]}/posts`))
presenceData.details = "Viewing this users posts:";
else if (document.location.pathname.startsWith(`/${userSplit[1]}/shop`))
presenceData.details = "Viewing this users shop:";
else if (
document.location.pathname.startsWith(`/${userSplit[1]}/commissions`)
)
presenceData.details = "Viewing this users commissions:";
else if (document.location.pathname.startsWith(`/${userSplit[1]}/tiers`))
presenceData.details = "Viewing this users tier options:";
} catch {
presenceData.details = "Viewing an unsupported page.";
}
}

presence.setActivity(presenceData);
});
6 changes: 6 additions & 0 deletions websites/K/Ko-Fi/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist/"
}
}

0 comments on commit 7849571

Please sign in to comment.