diff --git a/websites/W/WhatsApp/metadata.json b/websites/W/WhatsApp/metadata.json index e14b78c2b8ab..b010d79377f1 100644 --- a/websites/W/WhatsApp/metadata.json +++ b/websites/W/WhatsApp/metadata.json @@ -20,7 +20,7 @@ "ga_IE": "Seol agus faigh teachtaireachtaí WhatsApp go tapa ó do ríomhaire." }, "url": "web.whatsapp.com", - "version": "2.2.6", + "version": "2.3.0", "logo": "https://cdn.rcd.gg/PreMiD/websites/W/WhatsApp/assets/logo.png", "thumbnail": "https://cdn.rcd.gg/PreMiD/websites/W/WhatsApp/assets/thumbnail.jpg", "color": "#0dc143", diff --git a/websites/W/WhatsApp/presence.ts b/websites/W/WhatsApp/presence.ts index f26c126fc5a6..d0b9f10edf3e 100644 --- a/websites/W/WhatsApp/presence.ts +++ b/websites/W/WhatsApp/presence.ts @@ -1,56 +1,75 @@ const presence = new Presence({ clientId: "628019683718856714", }), - getSettings = async (): Promise<{ - showRecipient: boolean; - showNumbers: boolean; - }> => ({ - showRecipient: await presence.getSetting("showRecipient"), - showNumbers: await presence.getSetting("showNumbers"), - }); + browsingTimestamp = Math.floor(Date.now() / 1000); presence.on("UpdateData", async () => { - const settings = await getSettings(), + const presenceData: PresenceData = { + largeImageKey: + "https://cdn.rcd.gg/PreMiD/websites/W/WhatsApp/assets/logo.png", + startTimestamp: browsingTimestamp, + }, typing = document.querySelector( 'span[class="selectable-text copyable-text"]' - ); + ), + [showRecipient, showNumbers] = await Promise.all([ + presence.getSetting("showRecipient"), + presence.getSetting("showNumbers"), + ]); - let name = - settings.showRecipient && - document.querySelector('[data-testid="conversation-info-header"]') - .firstChild.firstChild?.textContent; + let name = document + .querySelector(".AmmtE") + ?.querySelector('[class*="lhj4utae"]')?.textContent; if ( - settings.showNumbers === false && - typeof name === "string" && - !isNaN(Number(name.replace(/[^a-zA-Z0-9 ]/g, "").replaceAll(" ", ""))) + name?.match( + /^[+]?[(]?[0-9]{3}[)]?[-\s.]?[0-9]{3}[-\s.]?[0-9]{4,6}$/gm + )?.[0] && + !showNumbers ) - name = null; + name = ""; if (!name && !typing) { - if (!document.querySelector('[data-testid="conversation-info-header"]')) { - presence.setActivity({ - largeImageKey: - "https://cdn.rcd.gg/PreMiD/websites/W/WhatsApp/assets/logo.png", - details: "Browsing...", - startTimestamp: Math.floor(Date.now() / 1000), - }); - } else { - presence.setActivity({ - largeImageKey: - "https://cdn.rcd.gg/PreMiD/websites/W/WhatsApp/assets/logo.png", - details: "Texting with someone", - state: "Just reading...", - startTimestamp: Math.floor(Date.now() / 1000), - }); + switch (true) { + case !!document.querySelector(".ppled2lx"): { + // Community tab + presenceData.details = "Viewing communities"; + break; + } + case !!document.querySelector(".mrcito7c.r96muop5"): { + // Status + presenceData.details = "Browsing all status updates"; + break; + } + case !document.querySelector( + '[data-testid="conversation-info-header"]' + ): { + presenceData.details = "Browsing..."; + break; + } + default: { + presenceData.details = "Texting with someone"; + presenceData.state = "Just reading..."; + break; + } } + } else if (document.querySelector('[role="tablist"]')) { + // if contact windows with media/documents/etc is open + presenceData.details = `Viewing ${document + .querySelector('button[aria-selected="true"]') + ?.textContent?.toLowerCase()} in the chat with ${ + !showRecipient ? "someone" : name + }`; + } else if (document.querySelector("._2Ts6i._1xFRo > span > div")) { + // If contact windows is open + presenceData.details = `Viewing contact info of ${ + !showRecipient ? "someone" : name + }`; } else { - presence.setActivity({ - largeImageKey: - "https://cdn.rcd.gg/PreMiD/websites/W/WhatsApp/assets/logo.png", - details: `Texting with ${name || "someone"}`, - state: (typing?.textContent && "Typing...") || "Just reading...", - startTimestamp: Math.floor(Date.now() / 1000), - }); + presenceData.details = `Texting with ${!showRecipient ? "someone" : name}`; + presenceData.state = + (typing?.textContent && "Typing...") || "Just reading..."; } + + presence.setActivity(presenceData); });