Skip to content

Commit

Permalink
feat(FiveM): add privacy, buttons & covers (PreMiD#6789)
Browse files Browse the repository at this point in the history
* feat(FiveM): add privacy, buttons & covers

* chore(FiveM): fix issues & add contributor
  • Loading branch information
Dark_Ville authored Sep 16, 2022
1 parent 9bf491f commit 06ede1b
Show file tree
Hide file tree
Showing 2 changed files with 207 additions and 26 deletions.
35 changes: 34 additions & 1 deletion websites/F/FiveM/dist/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
"name": "Marino",
"id": "598953747963707409"
},
"contributors": [
{
"name": "Dark_Ville",
"id": "638080361179512853"
}
],
"service": "FiveM",
"description": {
"en": "FiveM is a multiplayer modification framework for GTA V, allowing you to play on customized dedicated servers.",
Expand All @@ -12,9 +18,10 @@
"url": [
"fivem.net",
"docs.fivem.net",
"forum.cfx.re",
"servers.fivem.net"
],
"version": "1.0.10",
"version": "1.1.0",
"logo": "https://i.imgur.com/BvGqA4s.png",
"thumbnail": "https://i.imgur.com/b6Kd7z8.png",
"color": "#FF7300",
Expand All @@ -25,5 +32,31 @@
"fivem",
"online",
"five"
],
"settings": [
{
"id": "privacy",
"title": "Privacy Mode",
"icon": "fas fa-user-secret",
"value": false
},
{
"id": "buttons",
"title": "Show Buttons",
"icon": "fas fa-compress-arrows-alt",
"value": true,
"if": {
"privacy": false
}
},
{
"id": "covers",
"title": "Show Cover",
"icon": "fad fa-images",
"value": true,
"if": {
"privacy": false
}
}
]
}
198 changes: 173 additions & 25 deletions websites/F/FiveM/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,196 @@ const presence = new Presence({
}),
browsingTimestamp = Math.floor(Date.now() / 1000);

presence.on("UpdateData", () => {
enum Assets {
Logo = "https://i.imgur.com/BvGqA4s.png",
SearchImage = "https://i.imgur.com/oGQtnIY.png",
ReadingImage = "https://i.imgur.com/nese1O7.png",
}

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey: "fivem",
largeImageKey: Assets.Logo,
startTimestamp: browsingTimestamp,
},
{ pathname } = document.location,
{ hostname } = document.location;
{ href, hostname, pathname } = document.location,
[privacy, buttons, covers] = await Promise.all([
presence.getSetting<boolean>("privacy"),
presence.getSetting<boolean>("buttons"),
presence.getSetting<boolean>("covers"),
]);

switch (hostname) {
case "fivem.net":
case "www.fivem.net": {
presenceData.details = "Viewing:";
if (pathname === "/") presenceData.state = "Home Page";
let search: HTMLInputElement;

if (privacy) {
presenceData.details = "Browsing";
presence.setActivity(presenceData);
return;
}
switch (hostname.replace("www.", "")) {
case "fivem.net": {
if (pathname === "/") presenceData.details = "Viewing home Page";
else if (pathname.includes("terms")) {
presenceData.details = "Reading terms";
presenceData.smallImageKey = Assets.ReadingImage;
}
break;
}
case "docs.fivem.net":
case "www.docs.fivem.net": {
presenceData.details = "Viewing documentation:";
if (pathname.startsWith("/docs/")) {
case "docs.fivem.net": {
search = document.querySelector('[name="search"]');
if (search?.value) {
presenceData.details = "Searchin for";
presenceData.state = search.value;
presenceData.smallImageKey = Assets.SearchImage;
} else if (pathname.startsWith("/docs/")) {
presenceData.details = "Reading documentation about";
presenceData.state = document.querySelector(
"body > div > div > div > main > div > h1:nth-child(1)"
).textContent;
'[class="docContent"]'
)?.firstChild?.textContent;
presenceData.smallImageKey = Assets.ReadingImage;
presenceData.buttons = [
{
label: "Read Docs",
url: href,
},
];
}

break;
}
case "servers.fivem.net":
case "www.servers.fivem.net": {
presenceData.details = "Viewing server:";
if (pathname.startsWith("/servers/detail/")) {
presenceData.state = document.querySelector(
"body > app-root > div > div.app-root > servers > app-servers-detail > div.info.one-info > h1"
).textContent;
} else if (pathname === "/servers")
presenceData.details = "Seaching for a server";
case "forum.cfx.re": {
search = document.querySelector('[id="search-term"]');
if (search?.value) {
presenceData.details = "Searchin for";
presenceData.state = search.value;
presenceData.smallImageKey = Assets.SearchImage;
presence.setActivity(presenceData);
return;
}
switch (pathname.split("/")[1]) {
case "": {
presenceData.details = "Viewing the forum home Page";
break;
}
case "categories":
case "c": {
// categories
presenceData.details = "Viewing forum category";
presenceData.state = document.querySelector(
'[class="category-name"]'
)?.textContent;
presenceData.buttons = [
{
label: "View Forum Category",
url: href,
},
];
break;
}
case "tag": {
presenceData.details = "Viewing posts with tag";
presenceData.state =
document.querySelector('[class="name"]')?.textContent;
presenceData.buttons = [
{
label: "View Posts",
url: href,
},
];
break;
}
case "t": {
// post
presenceData.details = "Reading post";
presenceData.state = document.querySelector(
'[class="fancy-title"]'
)?.textContent;
presenceData.smallImageKey = Assets.ReadingImage;
presenceData.buttons = [
{
label: "Reading Post",
url: href,
},
];
break;
}
case "u": {
// user
presenceData.details = "Viewing user";
presenceData.largeImageKey = `https://${hostname}/${document
.querySelector('[class="user-profile-avatar"]')
?.firstElementChild.getAttribute("src")}`;
presenceData.state = document
.querySelector('[class="username"]')
.textContent.split("\n")[1]
.trim();
presenceData.buttons = [
{
label: "View Profile",
url: href,
},
];
break;
}
case "latest": {
presenceData.details = "Exploring the latest posts";
break;
}
case "top": {
presenceData.details = "Exploring the top posts";
break;
}
case "badges": {
presenceData.details = "Exploring all badges";
break;
}
case "g": {
presenceData.details = "Exploring all groups";
break;
}
}
break;
}
case "servers.fivem.net": {
search = document.querySelector('[id="searchBox"]');
if (search?.value) {
presenceData.details = "Searchin for";
presenceData.state = search.value;
presenceData.smallImageKey = Assets.SearchImage;
} else if (pathname.startsWith("/servers/detail/")) {
presenceData.largeImageKey = document
.querySelector('[class="icon"]')
.firstElementChild.getAttribute("src");
presenceData.details = "Viewing server";
presenceData.state =
document.querySelector('[class="title"]').textContent;
presenceData.buttons = [
{
label: "View Server",
url: href,
},
];
} else {
presenceData.details = `Exploring ${
document.querySelector('[class="nav-item subnav-item active"]')
?.textContent ?? "all servers"
}`;
presenceData.state = `Sorted by ${
document.querySelector('[class="sort-by active"]')?.textContent
}`;
presenceData.buttons = [
{
label: "View All Server",
url: href,
},
];
}

break;
}
// No default
}

if (!covers) presenceData.largeImageKey = Assets.Logo;
if (!buttons) delete presenceData.buttons;
if (presenceData.details) presence.setActivity(presenceData);
else presence.setActivity();
});

0 comments on commit 06ede1b

Please sign in to comment.