diff --git a/websites/C/CritiqueBrainz/dist/metadata.json b/websites/C/CritiqueBrainz/dist/metadata.json new file mode 100644 index 000000000000..78ed4bfecbd9 --- /dev/null +++ b/websites/C/CritiqueBrainz/dist/metadata.json @@ -0,0 +1,22 @@ +{ + "$schema": "https://schemas.premid.app/metadata/1.7", + "author": { + "name": "theusaf", + "id": "193714715631812608" + }, + "service": "CritiqueBrainz", + "description": { + "en": "CritiqueBrainz is a repository for Creative Commons licensed music reviews. Here you can read what other people have written about an album or event and write your own review!" + }, + "url": "critiquebrainz.org", + "version": "1.0.0", + "logo": "https://i.imgur.com/LG31f5s.png", + "thumbnail": "https://i.imgur.com/7ACWqDu.png", + "color": "#36b5b2", + "category": "music", + "tags": [ + "review", + "encyclopedia", + "community" + ] +} \ No newline at end of file diff --git a/websites/C/CritiqueBrainz/presence.ts b/websites/C/CritiqueBrainz/presence.ts new file mode 100644 index 000000000000..27eb1a091b2d --- /dev/null +++ b/websites/C/CritiqueBrainz/presence.ts @@ -0,0 +1,153 @@ +const presence = new Presence({ + clientId: "1017821399705985097", + }), + browsingTimestamp = Math.floor(Date.now() / 1000); + +presence.on("UpdateData", () => { + const presenceData: PresenceData = { + largeImageKey: "https://i.imgur.com/LG31f5s.png", + startTimestamp: browsingTimestamp, + }, + { pathname, href } = window.location, + pathSplit = pathname.split("/").slice(1); + switch (pathSplit[0]) { + case "": { + presenceData.details = "Browsing home page"; + break; + } + case "profile": { + if (pathSplit[1] === "applications") { + switch (pathSplit[2]) { + case "": { + presenceData.details = "Managing applications"; + break; + } + case "create": { + presenceData.details = "Creating a new application"; + break; + } + default: { + if (/\/edit\/?$/.test(pathname)) { + presenceData.details = "Editing an application"; + presenceData.state = document.querySelector( + "form fieldset input" + ).value; + } + } + } + } else if (pathSplit[1] === "edit") + presenceData.details = "Editing profile"; + + break; + } + case "user": { + if (pathSplit[1] === "edit") { + presenceData.details = "Editing profile"; + presenceData.state = document + .querySelector(".nav a") + .textContent.replace(/^\s+|\s+$/g, ""); + } else { + presenceData.details = "Viewing a profile"; + const username = document.querySelector("h2").textContent; + switch (pathSplit[2] || "") { + case "": { + presenceData.state = username; + break; + } + case "info": { + presenceData.state = `Statistics for '${username}'`; + break; + } + } + } + break; + } + case "statistics": { + presenceData.details = "Viewing the top 10 contributors"; + break; + } + case "review": { + presenceData.details = "Browsing reviews"; + switch (pathSplit[1]) { + case "": { + presenceData.state = "Home page"; + break; + } + case "write": { + presenceData.details = "Writing a review"; + presenceData.state = + document.querySelector("dd a").textContent; + break; + } + default: { + if (/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/.test(pathSplit[1])) { + presenceData.largeImageKey = + document.querySelector(".cover-art")?.src ?? + presenceData.largeImageKey; + switch (pathSplit[2] || "") { + case "": { + presenceData.details = "Reading a review"; + presenceData.state = `${ + document.querySelector("h3 > a") + .textContent + }'s review of ${ + document.querySelector("h2 > a") + .textContent + }`; + if (!document.querySelector(".alert-warning")) { + presenceData.buttons = [ + { + label: "Read Review", + url: href, + }, + ]; + } + break; + } + case "edit": { + presenceData.details = "Editing review"; + presenceData.state = + document.querySelector("dd a").textContent; + break; + } + case "revisions": { + if (!pathSplit[3]) + presenceData.details = "Viewing review revision history"; + else { + presenceData.details = "Viewing review revision"; + presenceData.state = + document.querySelector( + "h2 a" + ).textContent; + } + break; + } + case "delete": { + presenceData.details = "Deleting review"; + presenceData.state = document + .querySelector(".lead") + .textContent.match(/"(.*?)"/)[1]; + break; + } + } + } + } + } + break; + } + case "search": { + presenceData.details = "Searching"; + presenceData.state = + document.querySelector("#input-query").value; + break; + } + default: { + presenceData.details = "Browsing..."; + presenceData.state = document.title.match( + /(.*?)( - CritiqueBrainz$|$)/ + )[1]; + } + } + if (presenceData.details) presence.setActivity(presenceData); + else presence.setActivity(); +}); diff --git a/websites/C/CritiqueBrainz/tsconfig.json b/websites/C/CritiqueBrainz/tsconfig.json new file mode 100644 index 000000000000..3bf4ca1f9f55 --- /dev/null +++ b/websites/C/CritiqueBrainz/tsconfig.json @@ -0,0 +1,6 @@ +{ + "extends": "../../../tsconfig.json", + "compilerOptions": { + "outDir": "./dist/" + } +}