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
|
||||||
33
injected.js
33
injected.js
@@ -1,8 +1,12 @@
|
|||||||
|
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() {
|
||||||
|
window.Store = null;
|
||||||
|
|
||||||
// Wait for WhatsApp to initialize its modules
|
// Wait for WhatsApp to initialize its modules
|
||||||
const storeCheckInterval = setInterval(() => {
|
const storeCheckInterval = setInterval(() => {
|
||||||
if (window.Store) {
|
if (window.Store) {
|
||||||
@@ -14,6 +18,10 @@
|
|||||||
|
|
||||||
if (typeof window.require === "function") {
|
if (typeof window.require === "function") {
|
||||||
try {
|
try {
|
||||||
|
if (!window.require("WAWebCollections").Reactions._models?.length) {
|
||||||
|
console.log("Not injected. Still not defined");
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Load the essential modules
|
// Load the essential modules
|
||||||
window.Store = Object.assign({}, window.require("WAWebCollections"));
|
window.Store = Object.assign({}, window.require("WAWebCollections"));
|
||||||
window.Store.Cmd = window.require("WAWebCmd").Cmd;
|
window.Store.Cmd = window.require("WAWebCmd").Cmd;
|
||||||
@@ -30,9 +38,8 @@
|
|||||||
|
|
||||||
// Set up listeners for heart reactions
|
// Set up listeners for heart reactions
|
||||||
function setupReactionListener() {
|
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
|
// CANDIDATE TASK: Write code that will star a message when you react to it with a heart emoji ✅
|
||||||
//
|
//
|
||||||
// Hints:
|
// Hints:
|
||||||
// 1. You'll need to listen for reaction events using Store.Reactions
|
// 1. You'll need to listen for reaction events using Store.Reactions
|
||||||
@@ -48,7 +55,27 @@
|
|||||||
// require("WAWebCmd") or any other module name. This will show you available methods,
|
// require("WAWebCmd") or any other module name. This will show you available methods,
|
||||||
// _events, and other properties that might be helpful for this task.
|
// _events, and other properties that might be helpful for this task.
|
||||||
|
|
||||||
console.log("Reaction listener needs to be implemented");
|
Store.Reactions._models.forEach((model) => {
|
||||||
|
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
|
// Initialize
|
||||||
|
|||||||
Reference in New Issue
Block a user