From 2edb9a45d3e5a3f16f448e187e58c124e822767a Mon Sep 17 00:00:00 2001 From: Matias Carpintini Date: Thu, 20 Mar 2025 16:16:04 -0300 Subject: [PATCH] initial script --- .DS_Store | Bin 0 -> 6148 bytes README.md | 59 ++++++++++++++++++++++++++++++++++++++++++++++ content-script.js | 20 ++++++++++++++++ injected.js | 56 +++++++++++++++++++++++++++++++++++++++++++ manifest.json | 21 +++++++++++++++++ 5 files changed, 156 insertions(+) create mode 100644 .DS_Store create mode 100644 README.md create mode 100644 content-script.js create mode 100644 injected.js create mode 100644 manifest.json diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ed6d89e5de89d65c43c9026f156fc2217bb6c7b2 GIT binary patch literal 6148 zcmeHK%Sr=55Ukc50zrs3FT(tQ0smkP@!;7X&^&}l%!(WD`$vAFRzD(c+>-|p>4xd* z%yiAn7G!1`fJ|SPm%tdnkWEoE=rQf?9Xg8SW1`p`D{QgD1sW`RCi;tAy7yD=wzi#r z-Tw>Lc;?qk@QCJSQ!nP5dd_T>>WyvkZpH{0F?Y+n6=&MfFMC;62doo3;hwxT9>{6- zYw2FP>&f{6Q`byO1yX@jAQeajex?BLY_;LYF?}kK3Zw#`3h4Pz*c7Y4*3pg*Ix7K) z19qD+)(5h3N?;Y(I&y?2P9-{3qQnrVv%f@M71%mD9TLTd#LD~PMQnA>Uo0I`Ii^nq zQh}}lTKm$*djDVZFVkD(TS~fAAQkwp3dmq~JDc+B;%@!+oqE?6wmUX8&1*HFG44D9 i_(RW;GaK~rqA~NTz}8V`(SD;7^C4h@q)P>UL4gn2TRKSq literal 0 HcmV?d00001 diff --git a/README.md b/README.md new file mode 100644 index 0000000..f25ff87 --- /dev/null +++ b/README.md @@ -0,0 +1,59 @@ +# WhatsApp Heart Favorites + +A Chrome extension that automatically stars messages when you react with a heart emoji on WhatsApp Web. + +## Description + +WhatsApp Heart Favorites enhances your WhatsApp Web experience by automatically starring messages that you react to with a heart emoji (❤️). This makes it easier to keep track of important messages without having to manually star them. + +## Features + +- Automatically stars messages when you add a heart reaction +- Works seamlessly with WhatsApp Web +- Lightweight and unobtrusive + +## Installation + +### From Chrome Web Store + +1. Visit the Chrome Web Store (link to be added) +2. Click "Add to Chrome" +3. Confirm the installation + +### Manual Installation + +1. Download or clone this repository +2. Open Chrome and navigate to `chrome://extensions/` +3. Enable "Developer mode" in the top-right corner +4. Click "Load unpacked" and select the downloaded folder +5. The extension should now be installed and active + +## Usage + +1. Open WhatsApp Web (https://web.whatsapp.com/) +2. React to any message with a heart emoji (❤️) +3. The message will be automatically starred + +## How It Works + +The extension injects a script into WhatsApp Web that: + +1. Accesses WhatsApp's internal JavaScript modules +2. Listens for reaction events +3. When a heart reaction is detected, it triggers the star message function + +## Permissions + +This extension requires the following permissions: + +- `activeTab`: To interact with the WhatsApp Web page +- `scripting`: To inject scripts into the page +- Access to `https://web.whatsapp.com/*`: To function on WhatsApp Web + +## Development + +The extension consists of: + +- `manifest.json`: Extension configuration +- `content-script.js`: Detects when WhatsApp Web is loaded and injects the main script +- `injected.js`: Contains the core functionality for detecting reactions and starring messages diff --git a/content-script.js b/content-script.js new file mode 100644 index 0000000..7953d8b --- /dev/null +++ b/content-script.js @@ -0,0 +1,20 @@ +// This script runs in the context of the web page +function injectScript(filePath) { + const script = document.createElement("script"); + script.setAttribute("type", "text/javascript"); + script.setAttribute("src", chrome.runtime.getURL(filePath)); + document.documentElement.appendChild(script); + script.remove(); +} + +// Check if WhatsApp Web is loaded +function checkWhatsAppLoaded() { + if (document.querySelector("h1")) { + clearInterval(checkInterval); + injectScript("injected.js"); + console.log("WhatsApp Heart Favorites extension loaded"); + } +} + +// Check periodically if WhatsApp is loaded +const checkInterval = setInterval(checkWhatsAppLoaded, 1000); diff --git a/injected.js b/injected.js new file mode 100644 index 0000000..868009f --- /dev/null +++ b/injected.js @@ -0,0 +1,56 @@ +(function () { + console.log("WhatsApp Heart Favorites script - Candidate Test"); + + // Initialize WhatsApp Store access + function initializeWAStore() { + // Wait for WhatsApp to initialize its modules + const storeCheckInterval = setInterval(() => { + if (window.Store) { + clearInterval(storeCheckInterval); + console.log("WhatsApp store already initialized"); + setupReactionListener(); + return; + } + + if (typeof window.require === "function") { + try { + // Load the essential modules + window.Store = Object.assign({}, window.require("WAWebCollections")); + window.Store.Cmd = window.require("WAWebCmd").Cmd; + + clearInterval(storeCheckInterval); + console.log("WhatsApp store initialized"); + setupReactionListener(); + } catch (error) { + console.error("Error initializing WhatsApp store:", error); + } + } + }, 1000); + } + + // Set up listeners for heart reactions + function setupReactionListener() { + // TODO: Implement the reaction listener here + // + // CANDIDATE TASK: Write code that will star a message when you react to it with a heart emoji + // + // Hints: + // 1. You'll need to listen for reaction events using Store.Reactions + // 2. Check if the reaction is a heart emoji (❤️) + // 3. Use Store.Msg to get the message object + // 4. Use Store.Chat to get the chat object + // 5. Use Store.Cmd.sendStarMsgs to star the message + // + // Your code should detect when the user adds a heart reaction and then + // automatically star that message in the chat + // + // TIP: You can inspect WhatsApp modules directly in your Chrome console by typing: + // require("WAWebCmd") or any other module name. This will show you available methods, + // _events, and other properties that might be helpful for this task. + + console.log("Reaction listener needs to be implemented"); + } + + // Initialize + initializeWAStore(); +})(); diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..d12bb98 --- /dev/null +++ b/manifest.json @@ -0,0 +1,21 @@ +{ + "name": "WhatsApp Heart Favorites", + "description": "Automatically star messages when you react with a heart emoji", + "version": "1.0.0", + "manifest_version": 3, + "permissions": ["activeTab", "scripting"], + "host_permissions": ["https://web.whatsapp.com/*"], + "content_scripts": [ + { + "matches": ["https://web.whatsapp.com/*"], + "run_at": "document_end", + "js": ["content-script.js"] + } + ], + "web_accessible_resources": [ + { + "resources": ["injected.js"], + "matches": ["https://web.whatsapp.com/*"] + } + ] +}