mirror of
https://github.com/FranP-code/heart-save.git
synced 2025-10-13 00:13:54 +00:00
Main logic implemented
This commit is contained in:
2
.tool-versions
Normal file
2
.tool-versions
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
nodejs 22.14.0
|
||||||
|
pnpm 8.15.4
|
||||||
123
injected.js
123
injected.js
@@ -1,56 +1,83 @@
|
|||||||
|
const EMOJI_TARGET = "❤"; // Acting like ❤️ on Whatsapp
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
console.log("WhatsApp Heart Favorites script - Candidate Test");
|
console.log("WhatsApp Heart Favorites script - Candidate Test");
|
||||||
|
|
||||||
// Initialize WhatsApp Store access
|
// Initialize WhatsApp Store access
|
||||||
function initializeWAStore() {
|
function initializeWAStore() {
|
||||||
// Wait for WhatsApp to initialize its modules
|
window.Store = null;
|
||||||
const storeCheckInterval = setInterval(() => {
|
|
||||||
if (window.Store) {
|
|
||||||
clearInterval(storeCheckInterval);
|
|
||||||
console.log("WhatsApp store already initialized");
|
|
||||||
setupReactionListener();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (typeof window.require === "function") {
|
// Wait for WhatsApp to initialize its modules
|
||||||
try {
|
const storeCheckInterval = setInterval(() => {
|
||||||
// Load the essential modules
|
if (window.Store) {
|
||||||
window.Store = Object.assign({}, window.require("WAWebCollections"));
|
clearInterval(storeCheckInterval);
|
||||||
window.Store.Cmd = window.require("WAWebCmd").Cmd;
|
console.log("WhatsApp store already initialized");
|
||||||
|
setupReactionListener();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
clearInterval(storeCheckInterval);
|
if (typeof window.require === "function") {
|
||||||
console.log("WhatsApp store initialized");
|
try {
|
||||||
setupReactionListener();
|
if (!window.require("WAWebCollections").Reactions._models?.length) {
|
||||||
} catch (error) {
|
console.log("Not injected. Still not defined");
|
||||||
console.error("Error initializing WhatsApp store:", error);
|
return;
|
||||||
}
|
}
|
||||||
}
|
// Load the essential modules
|
||||||
}, 1000);
|
window.Store = Object.assign({}, window.require("WAWebCollections"));
|
||||||
}
|
window.Store.Cmd = window.require("WAWebCmd").Cmd;
|
||||||
|
|
||||||
// Set up listeners for heart reactions
|
clearInterval(storeCheckInterval);
|
||||||
function setupReactionListener() {
|
console.log("WhatsApp store initialized");
|
||||||
// TODO: Implement the reaction listener here
|
setupReactionListener();
|
||||||
//
|
} catch (error) {
|
||||||
// CANDIDATE TASK: Write code that will star a message when you react to it with a heart emoji
|
console.error("Error initializing WhatsApp store:", error);
|
||||||
//
|
}
|
||||||
// Hints:
|
}
|
||||||
// 1. You'll need to listen for reaction events using Store.Reactions
|
}, 1000);
|
||||||
// 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");
|
// Set up listeners for heart reactions
|
||||||
}
|
function setupReactionListener() {
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
|
||||||
// Initialize
|
Store.Reactions._models.forEach((model) => {
|
||||||
initializeWAStore();
|
model.reactions._events.add = [
|
||||||
|
...model.reactions._events.add,
|
||||||
|
{
|
||||||
|
callback: async (...args) => {
|
||||||
|
if (args[0].__x_aggregateEmoji === EMOJI_TARGET) {
|
||||||
|
const msgKey = args[1].parent.__x_id._serialized;
|
||||||
|
const msg = Store.Msg.get(msgKey);
|
||||||
|
const chat = await Store.Chat.find(msg.id.remote);
|
||||||
|
const messageHasStar = msg.__x_star;
|
||||||
|
|
||||||
|
if (!messageHasStar) {
|
||||||
|
Store.Cmd.sendStarMsgs(chat, [msg], false);
|
||||||
|
} else {
|
||||||
|
Store.Cmd.sendUnstarMsgs(chat, [msg], false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize
|
||||||
|
initializeWAStore();
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user