From fececa9f1422a57715355d7ad6222b92ff3a11c6 Mon Sep 17 00:00:00 2001 From: selvuen Date: Tue, 12 Mar 2024 20:45:38 +0300 Subject: [PATCH] feat(KQM): add presence (#8162) * kqm * edit logo Signed-off-by: selvuen * oops Signed-off-by: selvuen * add new field * Update websites/K/KQM/presence.ts Co-authored-by: Daniel Lau <32113157+theusaf@users.noreply.github.com> Signed-off-by: selvuen * remove iframematches Signed-off-by: selvuen * largeimagekey Signed-off-by: selvuen * m Signed-off-by: selvuen * Update presence.ts Signed-off-by: selvuen * me when the Signed-off-by: selvuen --------- Signed-off-by: selvuen Co-authored-by: Daniel Lau <32113157+theusaf@users.noreply.github.com> --- websites/K/KQM/metadata.json | 22 ++++++ websites/K/KQM/presence.ts | 134 +++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 websites/K/KQM/metadata.json create mode 100644 websites/K/KQM/presence.ts diff --git a/websites/K/KQM/metadata.json b/websites/K/KQM/metadata.json new file mode 100644 index 000000000000..b6d9fbb1323c --- /dev/null +++ b/websites/K/KQM/metadata.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://schemas.premid.app/metadata/1.10", + "author": { + "id": "290820916051705868", + "name": "clevernt" + }, + "service": "KQM", + "description": { + "en": "KQM is home to the best Genshin Impact guides and the most reputable theorycrafting community. Learn about your favorite Genshin Impact characters’ builds, artifacts, weapons, teams, and more!" + }, + "url": "keqingmains.com", + "matches": ["*://*.keqingmains.com/*"], + "version": "1.0.0", + "logo": "https://i.imgur.com/zPaoj5v.png", + "thumbnail": "https://keqingmains.com/wp-content/uploads/2023/12/KQM_Banner-1536x254.webp", + "color": "#dab2f9", + "category": "games", + "tags": [ + "genshin-impact", + "game" + ] +} diff --git a/websites/K/KQM/presence.ts b/websites/K/KQM/presence.ts new file mode 100644 index 000000000000..93603a0a1856 --- /dev/null +++ b/websites/K/KQM/presence.ts @@ -0,0 +1,134 @@ +const presence = new Presence({ + clientId: "1215004822676312174", +}); + +function cleanAndCapitalize(string: string): string { + return string + .replace(/[_-]/g, " ") + .split(" ") + .map(word => word.charAt(0).toUpperCase() + word.substring(1)) + .join(" "); +} + +const browsingTimestamp = Math.floor(Date.now() / 1000), + characterList = [ + "amber", + "barbara", + "beidou", + "bennett", + "chongyun", + "diluc", + "diona", + "eula", + "fischl", + "ganyu", + "hu_tao", + "jean", + "kaeya", + "kaedehara_kazuha", + "keqing", + "klee", + "lisa", + "mona", + "ningguang", + "noelle", + "qiqi", + "razor", + "rosaria", + "sucrose", + "tartaglia", + "anemo-traveler", + "geo-traveler", + "venti", + "xiangling", + "xiao", + "xingqiu", + "xinyan", + "yanfei", + "zhongli", + "albedo", + "kujou_sara", + "raiden_shogun", + "kamisato_ayaka", + "yoimiya", + "electro-traveler", + "sangonomiya_kokomi", + "sayu", + "aloy", + "thoma", + "itto", + "gorou", + "yunjin", + "shenhe", + "yae", + "ayato", + "shinobu", + "dendro-traveler", + "heizou", + "tighnari", + "collei", + "dori", + "candace", + "cyno", + "nilou", + "nahida", + "layla", + "faruzan", + "wanderer", + "alhaitham", + "yaoyao", + "dehya", + "mika", + "baizhu", + "kaveh", + "kirara", + "hydro-traveler", + "lyney", + "lynette", + "freminet", + "neuvillette", + "wriothesley", + "furina", + "charlotte", + "navia", + "chevreuse", + "xianyun", + "gaming", + ]; + +presence.on("UpdateData", async () => { + const presenceData: PresenceData = { + largeImageKey: "https://i.nuuls.com/Z1rY4.png", + startTimestamp: browsingTimestamp, + }, + { pathname, host } = document.location; + + if (pathname === "/") presenceData.details = "Browsing KQM"; + + const matchedCharacter = characterList.find(character => { + return new RegExp( + `^/(${character}|q/${character.toLowerCase()}[^/]*-quickguide)/$` + ).test(pathname); + }); + + if (matchedCharacter) { + presenceData.details = `Reading a ${ + pathname.includes("-quickguide") ? "Quick Guide" : "Guide" + }`; + presenceData.state = document.title + .replace(" - KQM", "") + .replace(" Quick Guide", ""); + } else if (pathname.includes("/misc")) { + presenceData.details = "Reading a Miscellaneous Guide"; + presenceData.state = document.title.replace(" - KQM", ""); + } else if (host === "library.keqingmains.com") { + presenceData.details = "Browsing TCL"; + presenceData.state = + cleanAndCapitalize(document.title.replace(" | KQM TCL", "")) || null; + } else if (host === "compendium.keqingmains.com") { + presenceData.details = "Browsing The Compendium"; + presenceData.state = cleanAndCapitalize(pathname.substring(1)) || null; + } + + presence.setActivity(presenceData); +});