Skip to content

Commit

Permalink
feat(Google Meet): add settings and use a cache (#8613)
Browse files Browse the repository at this point in the history
* feat(Google Meet): add settings, use a cache & make dark tired

* chore(Google Meet): remove console log & make dark even more tired

* Update websites/G/Google Meet/presence.ts

Co-authored-by: Bas van Zanten <[email protected]>
Signed-off-by: Dark_Ville <[email protected]>

* fix(Google Meet): make it work for non english & give dark headache

---------

Signed-off-by: Dark_Ville <[email protected]>
Co-authored-by: Bas van Zanten <[email protected]>
  • Loading branch information
Dark_Ville and Bas950 committed Jul 29, 2024
1 parent ca8e780 commit c348e41
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 15 deletions.
40 changes: 39 additions & 1 deletion websites/G/Google Meet/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"url": "meet.google.com",
"regExp": "meet[.]google([.][a-z]+)+[/]",
"version": "1.2.21",
"version": "1.3.0",
"logo": "https://cdn.rcd.gg/PreMiD/websites/G/Google%20Meet/assets/logo.png",
"thumbnail": "https://cdn.rcd.gg/PreMiD/websites/G/Google%20Meet/assets/thumbnail.png",
"color": "#308574",
Expand All @@ -22,5 +22,43 @@
"google",
"meet",
"video"
],
"settings": [
{
"id": "usePresenceName",
"title": "Show Title as Presence",
"icon": "fad fa-user-edit",
"value": false
},
{
"id": "hideInviteCode",
"title": "Hide invite code from showing",
"icon": "fas fa-user-secret",
"value": true
},
{
"id": "meetTitle",
"if": {
"usePresenceName": true
},
"title": "Meeting Title row 0",
"icon": "fas fa-comment-alt-edit",
"value": "%meettime% %meettitle%",
"placeholder": "Use %meettime%, %meettitle%, %meetpeople%"
},
{
"id": "meetDetail",
"title": "Meeting Details row 1",
"icon": "fas fa-comment-alt-edit",
"value": "%meettime% %meettitle%",
"placeholder": "Use %meettime%, %meettitle%, %meetpeople%"
},
{
"id": "meetState",
"title": "Meeting State row 2",
"icon": "fas fa-comment-alt-edit",
"value": "%meetpeople%",
"placeholder": "Use %meettime%, %meettitle%, %meetpeople%"
}
]
}
152 changes: 138 additions & 14 deletions websites/G/Google Meet/presence.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,149 @@
const presence = new Presence({
clientId: "701914032541794386",
}),
time = Math.floor(Date.now() / 1000);
browsingTimestamp = Math.floor(Date.now() / 1000);

presence.on("UpdateData", () => {
const presenceData: PresenceData = {
largeImageKey:
"https://cdn.rcd.gg/PreMiD/websites/G/Google%20Meet/assets/logo.png",
startTimestamp: time,
function capitalizeFirstLetter(string: string) {
if (string) {
return (
string.trim().charAt(0).toUpperCase() +
string.trim().slice(1).toLowerCase()
);
}
}
let oldURL: string,
pdCache = {
name: "",
details: "",
state: "",
meetTitle: "",
meetDetails: "",
meetState: "",
};

if (document.location.pathname.toLowerCase() === "/") {
function replacePlaceholders(
original: string,
mTime: string,
mTitle: string,
mPeople: string
) {
if (!original) return "";

let tempString = original;

if (mTime) tempString = tempString.replace("%meettime%", `| time: ${mTime}`);
else tempString = tempString.replace("%meettime%", "");

if (mTitle)
tempString = tempString.replace("%meettitle%", `| title: ${mTitle}`);
else tempString = tempString.replace("%meettitle%", "");

if (mPeople) {
tempString = tempString.replace(
"%meetpeople%",
`| amount of attendants: ${mPeople}`
);
} else tempString = tempString.replace("%meetpeople%", "");

if (!tempString) return "";
else if (tempString?.toLowerCase()?.includes("ready to join?")) return "";
else if (tempString.at(0) === "|")
tempString = capitalizeFirstLetter(tempString.slice(2));
else if (tempString.at(1) === "|")
tempString = capitalizeFirstLetter(tempString.slice(3));
else tempString = capitalizeFirstLetter(tempString);

return tempString;
}

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey:
"https://cdn.rcd.gg/PreMiD/websites/G/Google%20Meet/assets/logo.png",
startTimestamp: browsingTimestamp,
},
[
usePresenceName,
hideInviteCode,
presenceName,
presenceDetail,
presenceState,
] = await Promise.all([
presence.getSetting<boolean>("usePresenceName"),
presence.getSetting<boolean>("hideInviteCode"),
presence.getSetting<string>("meetTitle"),
presence.getSetting<string>("meetDetail"),
presence.getSetting<string>("meetState"),
]),
{ href, pathname } = document.location;

if (pathname.toLowerCase() === "/") {
presenceData.details = "Initial page";
presenceData.state = "Just waiting";
} else {
presenceData.smallImageKey = Assets.VideoCall;
presenceData.details = "In a meeting";
presenceData.state = `${
(document.querySelector(".wnPUne") ?? document.querySelector(".uGOf1d"))
.textContent
} users in the room`;
return presence.setActivity(presenceData);
}

let meetTitle = document.querySelector(".lefKC")?.textContent;

const meetTime = document.querySelector('[jsname="W5i7Bf"]')?.textContent,
meetPeople = document.querySelector(".uGOf1d")?.textContent;

if ((!meetTitle || !meetTitle?.includes(":") || !meetPeople) && !meetTime) {
presenceData.details = "Waiting for the meeting to start.";
presence.setActivity(presenceData);
return;
}
if (
href !== oldURL || // If no href
!pdCache?.details || // If no cached details
pdCache?.meetDetails !== presenceDetail || // If cached presence setting details !== current presence setting details
pdCache?.meetState !== presenceState || // If cached presence setting state !== current presence setting state
(usePresenceName && pdCache.meetTitle !== presenceName) // If use presenceName && cached presence setting name !== current presence setting name
) {
meetTitle = meetTitle?.replace(/([0-9]{2}:[0-9]{2})( )?((am)|(pm))?/gm, "");
if (
meetTitle?.toLowerCase()?.match(/[a-z]{3}-[a-z]{4}-[a-z]{3}/gm)?.[0] &&
hideInviteCode
)
// If the invitecode is in the title & the don't show invite code setting is enabled
meetTitle = "Secret";

presenceData.details = replacePlaceholders(
presenceDetail,
meetTime,
meetTitle,
meetPeople
);

presenceData.state = replacePlaceholders(
presenceState,
meetTime,
meetTitle,
meetPeople
);

oldURL = href;

if (usePresenceName) {
presenceData.name = replacePlaceholders(
presenceName,
meetTime,
meetTitle,
meetPeople
);
}
pdCache = {
name: presenceData?.name ?? "",
details: presenceData?.details,
state: presenceData?.state,
meetTitle: presenceName ?? "",
meetDetails: presenceDetail ?? "",
meetState: presenceState ?? "",
};
} else if (pdCache?.details) {
if (usePresenceName) presenceData.name = pdCache.name;
presenceData.details = pdCache.details;
presenceData.state = pdCache.state;
}

presence.setActivity(presenceData);
Expand Down

0 comments on commit c348e41

Please sign in to comment.