Skip to content

Commit

Permalink
feat(NameMC): privacy mode (#8668)
Browse files Browse the repository at this point in the history
* feat(NameMC): add privacy mode

* fix(NameMC): details missing on some pages

* fix(NameMC): better code consistency
  • Loading branch information
Kathund authored Aug 22, 2024
1 parent 8f99267 commit dbf3a47
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
8 changes: 7 additions & 1 deletion websites/N/NameMC/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"url": "namemc.com",
"regExp": "([a-z0-9-]+[.])*namemc[.]com[/]",
"version": "2.0.20",
"version": "2.0.21",
"logo": "https://cdn.rcd.gg/PreMiD/websites/N/NameMC/assets/logo.png",
"thumbnail": "https://cdn.rcd.gg/PreMiD/websites/N/NameMC/assets/thumbnail.png",
"color": "#000000",
Expand All @@ -26,6 +26,12 @@
"id": "lang",
"multiLanguage": true
},
{
"id": "privacy",
"title": "Privacy Mode",
"icon": "fad fa-user-secret",
"value": false
},
{
"id": "buttons",
"title": "Show Buttons",
Expand Down
55 changes: 28 additions & 27 deletions websites/N/NameMC/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ let strings: Awaited<ReturnType<typeof getStrings>>,
oldLang: string = null;

presence.on("UpdateData", async () => {
const newLang = await presence.getSetting<string>("lang").catch(() => "en"),
buttons = await presence.getSetting<boolean>("buttons");
const [newLang, privacy, buttons] = await Promise.all([
presence.getSetting<string>("lang").catch(() => "en"),
presence.getSetting<boolean>("privacy"),
presence.getSetting<boolean>("buttons"),
]);

if (oldLang !== newLang || !strings) {
oldLang = newLang;
Expand Down Expand Up @@ -95,19 +98,16 @@ presence.on("UpdateData", async () => {
"/cape/": {
details: strings.viewCape,
state: `${
document
.querySelector(".default-skin main.container h1")
?.textContent.split("\n")[1]
} Cape`,
document.querySelector("main > h1")?.textContent.split("\n")[1]
}`,
},
"/minecraft-servers/": {
details: strings.servers,
},
"/server/": {
details: strings.viewServer,
state: document.querySelector(
"body > main > div.row.no-gutters.align-items-center > div.col > h1"
)?.textContent,
state: document.querySelector("body > main > div > div > h1")
?.textContent,
buttons: [
{
label: strings.buttonViewServer,
Expand All @@ -133,7 +133,8 @@ presence.on("UpdateData", async () => {
},
"/profile/": {
details: strings.viewProfile,
state: document.querySelector("body > main > h1")?.textContent,
state: document.querySelector("body > main > div > div > h1")
?.textContent,
buttons: [
{
label: strings.buttonViewProfile,
Expand All @@ -145,33 +146,33 @@ presence.on("UpdateData", async () => {
details: strings.viewing,
state: strings.privacy,
},
"/search/": {
"/search": {
details: strings.search,
state: document.querySelector(
"#status-bar > div > div > div.col-lg-7 > h1 > samp"
)?.textContent,
state: document.location.href.split("/search?q=")[1],
smallImageKey: Assets.Search,
},
"/skin/": {
details: strings.viewSkin,
},
};

for (const [k, v] of Object.entries(statics)) {
if (
location.href
.replace(/\/?$/, "/")
.replace(`https://${location.hostname}`, "")
.replace("?", "/")
.match(k)
) {
presenceData.smallImageKey = Assets.Reading;
presenceData.smallImageText = strings.browse;
presenceData = { ...presenceData, ...v };
if (privacy) presenceData.details = strings.browse;
else {
for (const [k, v] of Object.entries(statics)) {
if (
document.location.href
.replace(/\/?$/, "/")
.replace(`https://${document.location.hostname}`, "")
.replace("?", "/")
.match(k)
) {
presenceData.smallImageKey = Assets.Reading;
presenceData.smallImageText = strings.browse;
presenceData = { ...presenceData, ...v };
}
}
if (!buttons) delete presenceData.buttons;
}

if (!buttons) delete presenceData.buttons;

presence.setActivity(presenceData);
});

0 comments on commit dbf3a47

Please sign in to comment.