From 78495710aa665742cbf94cbfd1722eeb9df93068 Mon Sep 17 00:00:00 2001 From: dzlandis <49926644+dzlandis@users.noreply.github.com> Date: Sat, 31 Jul 2021 05:04:37 -0700 Subject: [PATCH] Created Ko-Fi presence (#4142) * 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 * Fixed last URLSplit problem. Co-authored-by: codefactor-io Co-authored-by: Bas950 --- websites/K/Ko-Fi/dist/metadata.json | 23 ++++ websites/K/Ko-Fi/presence.ts | 172 ++++++++++++++++++++++++++++ websites/K/Ko-Fi/tsconfig.json | 6 + 3 files changed, 201 insertions(+) create mode 100644 websites/K/Ko-Fi/dist/metadata.json create mode 100644 websites/K/Ko-Fi/presence.ts create mode 100644 websites/K/Ko-Fi/tsconfig.json diff --git a/websites/K/Ko-Fi/dist/metadata.json b/websites/K/Ko-Fi/dist/metadata.json new file mode 100644 index 000000000000..59c5170793f1 --- /dev/null +++ b/websites/K/Ko-Fi/dist/metadata.json @@ -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!" + } + } \ No newline at end of file diff --git a/websites/K/Ko-Fi/presence.ts b/websites/K/Ko-Fi/presence.ts new file mode 100644 index 000000000000..e1831b559da3 --- /dev/null +++ b/websites/K/Ko-Fi/presence.ts @@ -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); +}); diff --git a/websites/K/Ko-Fi/tsconfig.json b/websites/K/Ko-Fi/tsconfig.json new file mode 100644 index 000000000000..d8a2968f1388 --- /dev/null +++ b/websites/K/Ko-Fi/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../../../tsconfig.json", + "compilerOptions": { + "outDir": "./dist/" + } + } \ No newline at end of file