Skip to content

Instantly share code, notes, and snippets.

@yarliganfatih
Last active June 23, 2024 12:13
Show Gist options
  • Save yarliganfatih/0b45a5b48824120adcd6aa6842d5e8d8 to your computer and use it in GitHub Desktop.
Save yarliganfatih/0b45a5b48824120adcd6aa6842d5e8d8 to your computer and use it in GitHub Desktop.
Resend the last deleted message
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
@yarliganfatih
Copy link
Author

@yarliganfatih
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment