salman0ansari / WhatsApp Web Calling Enabler

// ==UserScript==
// @name         WhatsApp Web Calling Enabler
// @namespace    https://hisalman.in
// @version      1.0
// @description  Enable calling features in WhatsApp Web by overriding AB test configurations.
// @author       salman0ansari
// @license      MIT
// @match        https://web.whatsapp.com/*
// @run-at       document-start
// @grant        none
// ==/UserScript==

// ==OpenUserJS==
// @author       salman0ansari
// ==/OpenUserJS==

(function () {
  function wrap(func) {
    return function (...args) {
      const key = args[0];

      switch (key) {
        case 'enable_web_calling':
        case 'enable_web_group_calling':
        case 'web_voip_call_tab_new_call':
          return true;
        case 'calling_lid_version':
          return 1;
        case 'heartbeat_interval_s':
          return 5;
        default:
          return func(...args);
      }
    };
  }

  const timer = setInterval(() => {
    try {
      const mod = window.require && window.require("WAWebABProps");
      if (!mod || !mod.getABPropConfigValue) return;

      // already hooked on THIS copy?
      if (mod.getABPropConfigValue.__wa_hooked__) return;

      const original = mod.getABPropConfigValue;
      const hooked = wrap(original);

      hooked.__wa_hooked__ = true;
      hooked.__wa_original__ = original;

      mod.getABPropConfigValue = hooked;

      console.log("[WA Calling Enabler] AB props patched");
    }
    catch {}
  }, 500);
})();