Whatsapp Web Spammer

A userscript that adds a Spam button to WhatsApp Web interface allowing you to send repeated messages with customizable count and timing.

  1. // ==UserScript==
  2. // @name Whatsapp Web Spammer
  3. // @namespace @ProdByGR
  4. // @match https://web.whatsapp.com/*
  5. // @grant none
  6. // @version 1.1
  7. // @author @ProdByGR
  8. // @description A userscript that adds a Spam button to WhatsApp Web interface allowing you to send repeated messages with customizable count and timing.
  9. // @require https://cdn.jsdelivr.net/npm/@violentmonkey/dom@2
  10. // @license MIT
  11. // ==/UserScript==
  12. const MESSAGE_PROMT = "Escriba el mensaje:";
  13. const COUNT_PROMT = "Cuántos mensajes quiere enviar:";
  14. const INTERVAL_PROMT = "Cuánto tiempo entre cada mensaje:";
  15. function start() {
  16. const message = prompt(MESSAGE_PROMT);
  17. if (message === null) return;
  18. const count = prompt(COUNT_PROMT);
  19. if (count === null) return;
  20. const interval = prompt(INTERVAL_PROMT, "450");
  21. if (interval === null) return;
  22. const countNum = parseInt(count);
  23. const intervalNum = parseInt(interval);
  24. if (isNaN(countNum) || isNaN(intervalNum)) {
  25. alert("Por favor, ingrese números válidos");
  26. return;
  27. }
  28. for (let i = 0; i < countNum; i++) {
  29. setTimeout(() => {
  30. sendMessage(message);
  31. }, i * intervalNum);
  32. }
  33. }
  34. async function sendMessage(message) {
  35. const main = document.querySelector("#main");
  36. main.querySelector(`div._ak1r`).focus();
  37. await document.execCommand("insertText", false, message);
  38. setTimeout(() => {
  39. const iconSend =
  40. main.querySelector('[data-testid="send"]') ||
  41. main.querySelector('[data-icon="send"]');
  42. iconSend.click();
  43. }, 100);
  44. }
  45. function addButtonIfNotExists(inputDiv) {
  46. const existingButton = inputDiv.querySelector("#spam-btn");
  47. if (existingButton) return;
  48. inputDiv.style.alignItems = "center";
  49. const button = document.createElement("button");
  50. button.id = "spam-btn";
  51. button.type = "button";
  52. button.textContent = "Spam";
  53. button.style.zIndex = "1000";
  54. button.style.fontWeight = "bold";
  55. button.style.padding = "5px 10px";
  56. button.style.backgroundColor = "#2a3942";
  57. button.style.color = "#8696a0";
  58. button.style.border = "none";
  59. button.style.borderRadius = "5px";
  60. button.style.cursor = "pointer";
  61. button.addEventListener("click", start);
  62. inputDiv.appendChild(button);
  63. }
  64. function setupObserver() {
  65. const observer = new MutationObserver((mutationsList) => {
  66. for (const mutation of mutationsList) {
  67. if (mutation.type === "childList") {
  68. const inputDiv = document.querySelector("div._ak1r");
  69. if (inputDiv) {
  70. addButtonIfNotExists(inputDiv);
  71. observer.disconnect();
  72. }
  73. }
  74. }
  75. });
  76. const mainContainer = document.querySelector("#main");
  77. if (mainContainer) {
  78. observer.observe(mainContainer, {
  79. childList: true,
  80. subtree: true,
  81. });
  82. }
  83. }
  84. window.addEventListener("load", () => {
  85. setupObserver();
  86. });
  87. VM.observe(document.body, () => {
  88. const inputDiv = document.querySelector("div._ak1r");
  89. if (inputDiv) {
  90. setupObserver();
  91. }
  92. return false;
  93. });