Last active
June 23, 2024 12:13
-
-
Save yarliganfatih/0b45a5b48824120adcd6aa6842d5e8d8 to your computer and use it in GitHub Desktop.
Resend the last deleted message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let reMessage = "You deleted that message but you cannot delete this message"; | |
let controlLastNMessage = 5; | |
let msgSelector = "#main > div._amm9 > div > div._ajyl > div.x3psx0u.xwib8y2.xkhd6sd.xrmvbpv"; | |
function isThereReMessageLast(num) { | |
if(num==0) return false; | |
if(document.querySelector(msgSelector + " > div:nth-last-child("+num+")").innerHTML.includes(reMessage)) { | |
return true; | |
} | |
return isThereReMessageLast(num-1); | |
} | |
function controlLoop(){ | |
try { | |
// If it is not in the last 5 messages | |
if(!isThereReMessageLast(controlLastNMessage)){ | |
sendMessage(reMessage); | |
console.log("resent message"); | |
} | |
}catch(err) { | |
console.log("error"); | |
} | |
} | |
function sendMessage(message){ | |
const mainEl = document.querySelector('#main') | |
const textareaEl = mainEl.querySelector('div[contenteditable="true"]') | |
if(!textareaEl) { | |
throw new Error('There is no opened conversation') | |
} | |
textareaEl.focus() | |
document.execCommand('insertText', false, message) | |
textareaEl.dispatchEvent(new Event('change', { bubbles: true })) | |
setTimeout(() => { | |
(mainEl.querySelector('[data-testid="send"]') || mainEl.querySelector('[data-icon="send"]')).click() | |
}, 100) | |
} | |
let timer = setInterval(controlLoop ,1000); | |
// clearInterval(timer); // for stop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sendMessage function ref : https://stackoverflow.com/a/53465009/14824683