Last active
July 24, 2022 00:23
-
-
Save wildeyes/987fbb65c5135812cdeb91a1efea3653 to your computer and use it in GitHub Desktop.
Userscript to select all contacts in search / group add in whatsapp
This file contains hidden or 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
// https://gist.github.com/wildeyes/987fbb65c5135812cdeb91a1efea3653 | |
// So, imagine you have to add 200 people to a group chat for work. | |
// how do you do it? | |
// 1. add them all via google contacts, add to their names some identifier, like GROUP | |
// 2. open whatsapp web, wait for contacts to sync (this could take some time) | |
// 3. click menu -> new group | |
// 4. open devtools (f12), go to console tab | |
// 5. copy the following script to the console and change what's inside the quotes on the following line to the identifier you chose (like GROUP) and press enter | |
whatsappSelectAllContacts('YOUR STRING HERE') | |
function whatsappSelectAllContacts(value) { | |
let interval = setInterval(() => { | |
function setNativeValue(element, value) { | |
const valueSetter = Object.getOwnPropertyDescriptor(element, 'value').set | |
const prototype = Object.getPrototypeOf(element) | |
const prototypeValueSetter = Object.getOwnPropertyDescriptor(prototype, 'value').set | |
if (valueSetter && valueSetter !== prototypeValueSetter) { | |
prototypeValueSetter.call(element, value) | |
} else { | |
valueSetter.call(element, value) | |
} | |
} | |
input = document.querySelector('[data-testid=inputarea]') | |
function type(value) { | |
setNativeValue(input, value) | |
input.dispatchEvent(new Event('input', { bubbles: true })) | |
} | |
type(value) | |
const contactsListElement = document.querySelector('[data-testid=contact-list-key]') | |
if (contactsListElement) { | |
contactsListElement.children[0].children[0].querySelector('span').click() | |
} else { | |
clearTimeout(interval) | |
} | |
}, 100) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment