diff --git a/websites/K/Kotobade Asobou/metadata.json b/websites/K/Kotobade Asobou/metadata.json new file mode 100644 index 000000000000..c3c15f233cfb --- /dev/null +++ b/websites/K/Kotobade Asobou/metadata.json @@ -0,0 +1,45 @@ +{ + "$schema": "https://schemas.premid.app/metadata/1.10", + "author": { + "id": "193714715631812608", + "name": "nihongojouzu" + }, + "service": "Kotobade Asobou", + "altnames": [ + "言葉で遊ぼう" + ], + "description": { + "en": "Japanese Wordle - daily word puzzle game.", + "ja_JP": "日本語版 Wordle - 日替わり単語パズルゲーム。" + }, + "url": "taximanli.github.io", + "matches": [ + "*://taximanli.github.io/*" + ], + "version": "1.0.0", + "logo": "https://taximanli.github.io/kotobade-asobou/kotobade-asobou_logo_512x512.png", + "thumbnail": "https://taximanli.github.io/kotobade-asobou/kotobade-asobou_card_600x314.png", + "color": "#22c55e", + "category": "games", + "tags": [ + "wordle", + "kotoba", + "japanese", + "game", + "puzzle", + "language", + "word" + ], + "settings": [ + { + "id": "displayLanguage", + "icon": "fas fa-language", + "value": 0, + "values": [ + "English", + "にほんご" + ], + "title": "Display Language" + } + ] +} \ No newline at end of file diff --git a/websites/K/Kotobade Asobou/presence.ts b/websites/K/Kotobade Asobou/presence.ts new file mode 100644 index 000000000000..c6e4d2f38d97 --- /dev/null +++ b/websites/K/Kotobade Asobou/presence.ts @@ -0,0 +1,73 @@ +import languageStrings from "./strings"; + +const presence = new Presence({ + clientId: "1233147201559990292", + }), + browsingTimestamp = Math.floor(Date.now() / 1000); + +const enum PresenceAssets { + Logo = "https://taximanli.github.io/kotobade-asobou/kotobade-asobou_logo_512x512.png", +} + +presence.on("UpdateData", async () => { + const presenceData: PresenceData = { + largeImageKey: PresenceAssets.Logo, + startTimestamp: browsingTimestamp, + }, + language = await presence.getSetting("displayLanguage"), + strings = languageStrings[["en", "ja"][language] as "en" | "ja"], + rows = [...document.querySelectorAll(".grid > div")], + nextIndex = rows.findIndex(row => + [...row.children].every( + tile => + !tile.querySelector(".letter-container").textContent + ) + ), + lastRow: HTMLDivElement = rows[nextIndex - 1], + isComplete = !!( + (lastRow?.children.length && + [...lastRow.children].every(tile => + tile.classList.contains("correct") + )) || + nextIndex === -1 + ); + + if (isComplete) { + const finalScore = nextIndex === -1 ? 12 : nextIndex; + let outcome = ""; + for (let i = 0; i < finalScore; i++) { + outcome += getRowEmojis(rows[i]); + outcome += " | "; + } + presenceData.details = nextIndex === -1 ? strings.failure : strings.victory; + presenceData.state = `${finalScore}/12 - ${getRowEmojis( + rows[finalScore - 1] + )}`; + presenceData.smallImageKey = Assets.Question; + presenceData.smallImageText = outcome; + presenceData.buttons = [ + { url: document.location.href, label: strings.play }, + ]; + } else { + presenceData.details = strings.guessing; + presenceData.state = `${nextIndex}/12 - ${getRowEmojis(lastRow)}`; + } + + presence.setActivity(presenceData); +}); + +function getRowEmojis(row: HTMLDivElement): string { + const darkMode = document.documentElement.classList.contains("dark"); + if (!row) return darkMode ? "⬛".repeat(4) : "⬜".repeat(4); + let emojis = ""; + for (let i = 0; i < row.children.length; i++) { + const tile = row.children[i]; + if (tile.classList.contains("correct")) emojis += "🟩"; + else if (tile.classList.contains("present")) emojis += "🟨"; + else if (tile.classList.contains("vowel")) emojis += "↔️"; + else if (tile.classList.contains("consonant")) emojis += "↕️"; + else if (tile.classList.contains("close")) emojis += "🟢"; + else emojis += darkMode ? "⬛" : "⬜"; + } + return emojis; +} diff --git a/websites/K/Kotobade Asobou/strings.ts b/websites/K/Kotobade Asobou/strings.ts new file mode 100644 index 000000000000..f71c0f4bd164 --- /dev/null +++ b/websites/K/Kotobade Asobou/strings.ts @@ -0,0 +1,14 @@ +const en = { + victory: "Victory", + failure: "Failure", + guessing: "Guessing", + play: "Play Game", + }, + ja: Record = { + victory: "しょうり", + failure: "しっぱい", + guessing: "すいそく", + play: "あそぼう", + }; + +export default { en, ja };