Skip to content

Commit

Permalink
Merge pull request PreMiD#3057 from Hibanka/master
Browse files Browse the repository at this point in the history
Added R6Stats presence
  • Loading branch information
mergify[bot] authored Feb 22, 2021
2 parents 510edc0 + 3dbd9b2 commit b0ebad6
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
21 changes: 21 additions & 0 deletions websites/R/R6Stats/dist/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://schemas.premid.app/metadata/1.0",
"author": {
"name": "Hibanka",
"id": "467658348158779393"
},
"url": "r6stats.com",
"description": {
"en": "View and compare your Rainbow Six: Siege statistics with millions of other players around the world!",
"ru": "Посматривайте и сравнивайте свою статистику в Rainbow Six: Siege с миллионами других игроков со всего мира!"
},
"service": "R6Stats",
"version": "1.0.0",
"logo": "https://i.imgur.com/DCvK0Bz.png",
"thumbnail": "https://i.imgur.com/nOrZDpv.png",
"color": "#ffda0c",
"tags": [
"rainbow6"
],
"category": "games"
}
68 changes: 68 additions & 0 deletions websites/R/R6Stats/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const presence = new Presence({
clientId: "812646634663837706"
}),
browsingStamp = Math.floor(Date.now() / 1000);

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey: "logo",
startTimestamp: browsingStamp
};

if (window.location.pathname.includes('/leaderboards')) {
presenceData.details = "Viewing Leaderboard:";

const selects = document.querySelectorAll("select"),
labels = [];

if (selects[0].selectedIndex == 0) {
labels.push("General");
labels.push(selects[2].options[selects[2].selectedIndex].label); // Stat Type
labels.push(selects[1].options[selects[1].selectedIndex].label); // Platform
} else {
labels.push("Seasonal");
labels.push(selects[4].options[selects[4].selectedIndex].label); // Stat Type
labels.push(selects[2].options[selects[2].selectedIndex].label); // Platform
}

presenceData.state = labels.join(" | ");
presenceData.buttons = [
{
label: "View Leaderboard",
url: document.location.href
}
];
} else if (window.location.pathname.includes('/search')) {
presenceData.details = "Searching Player:";
presenceData.state = document.querySelector(
"#__layout > div > div.layout-default__content > div.container__wrapper--content > div > main > div > div.page-search__wrapper > div > div > div.page-search__results__header--left > span.page-search__results__header--light"
).textContent.trim().slice(1, -1);
} else if (window.location.pathname.includes('/stats')) {
presenceData.details = "Viewing Player:";
presenceData.state = document.querySelector(
"#__layout > div > div.layout-default__content > div.container__wrapper--content > div > main > div > div.player-header > div.player-header__about > div.player-header__about__meta > div.player-header__about__meta--player > div > span.player-info__player__username"
).textContent.trim();
presenceData.buttons = [
{
label: "View Stats",
url: document.URL
.replace("/operators", "")
.replace("/seasons", "")
.replace("/weapons", "")
}
];
} else if (window.location.pathname.includes('/compare')) {
presenceData.details = "Viewing Page:";
presenceData.state = "Compare Players";
} else if (window.location.pathname.includes('/account')) {
presenceData.details = "Viewing Page:";
presenceData.state = "Personal Account";
} else if (window.location.pathname.includes('/privacy-policy')) {
presenceData.details = "Viewing Page:";
presenceData.state = "Privacy Policy";
} else {
presenceData.details = "Browsing...";
}

presence.setActivity(presenceData);
});
6 changes: 6 additions & 0 deletions websites/R/R6Stats/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist/"
}
}

0 comments on commit b0ebad6

Please sign in to comment.