Skip to content

Instantly share code, notes, and snippets.

@qgustavor
Last active October 1, 2019 03:11
Show Gist options
  • Select an option

  • Save qgustavor/25b1896467e2d6a3d85e to your computer and use it in GitHub Desktop.

Select an option

Save qgustavor/25b1896467e2d6a3d85e to your computer and use it in GitHub Desktop.
Batch Messages on WhatsApp Web
// ==UserScript==
// @name Batch Messages on WhatsApp Web
// @namespace [email protected]
// @include https://web.whatsapp.com/
// @version 1
// @grant unsafeWindow
// ==/UserScript==
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //
// Disclaimer: WhatsApp is banning people who use this //
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //
checkButton();
function checkButton(){
var menuButton = document.querySelector('button.icon-menu[data-reactid*="$conversation-header"]');
if (menuButton) {
menuButton.onclick = addAction;
} else {
setTimeout(checkButton, 1000);
}
}
function addAction (){
var headerMenuList = document.querySelector('ul[data-reactid*="$conversation-header"]');
if (!headerMenuList) { return setTimeout(addAction, 150); }
var newListElement = document.createElement('li');
newListElement.className = 'menu-item menu-shortcut';
newListElement.style.opacity = 1;
var newListAnchor = document.createElement('a');
newListAnchor.onclick = createSendScript;
newListAnchor.textContent = 'Send last message to all contacts';
newListElement.appendChild(newListAnchor);
headerMenuList.appendChild(newListElement);
(function check(){
if (newListElement.parentNode) {
setTimeout(check, 1000);
} else {
checkButton();
}
}());
}
function createSendScript() {
unsafeWindow.eval('('+sendMessages+'());');
}
function sendMessages() {
var b = Store.Chat.models.filter(function(a) {
return a.active;
})[0].msgs.last().attributes.body;
if(confirm('You\'re sure that you want to send this message\n"' + b + '"\nto everyone?')) {
Store.Chat.models.filter(function(a) {
return !a.active;
}).forEach(function(a) {
a.sendMessage(b);
});
}
}
@qgustavor
Copy link
Author

"What, WhatsApp supports it natively? It's named Broadcast Lists? Whoa..."

@kintaro1981
Copy link

"Broadcast List" don't deliver messages if the sender contact is not in the recipient contact list.

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