API WhatsApp To WEB WhatsApp Redirect with Debug

Redirects API WhatsApp links to Web WhatsApp and logs page information for debugging.

  1. // ==UserScript==
  2. // @name API WhatsApp To WEB WhatsApp Redirect with Debug
  3. // @icon https://i.imgur.com/r2qkepk.png
  4. // @namespace Whatsapp API
  5. // @include *://api.whatsapp.com/*
  6. // @version 1.2
  7. // @author SleepTheGod
  8. // @namespace SleepTheGod
  9. // @grant GM_addStyle
  10. // @require https://code.jquery.com/jquery-3.6.0.min.js
  11. // @license GPL version 2 or any later version; http://www.gnu.org/licenses/gpl-2.0.txt
  12. // @run-at document-start
  13. // @description Redirects API WhatsApp links to Web WhatsApp and logs page information for debugging.
  14. // ==/UserScript==
  15.  
  16. (function() {
  17. 'use strict';
  18.  
  19. // Debugging the entire page
  20. console.debug("Page URL: ", location.href);
  21. console.debug("Page Hostname: ", location.hostname);
  22. console.debug("Document Title: ", document.title);
  23. console.debug("Document Cookies: ", document.cookie);
  24. console.debug("User Agent: ", navigator.userAgent);
  25. console.debug("Full HTML of the page: ", document.documentElement.outerHTML);
  26.  
  27. // Check if the URL contains 'api.whatsapp'
  28. if (location.hostname === 'api.whatsapp.com') {
  29. // Debug the redirection action
  30. console.debug("Redirecting from API to Web WhatsApp...");
  31.  
  32. // Redirect to 'web.whatsapp.com' with the same path and query parameters
  33. const newUrl = location.href.replace('api.whatsapp.com', 'web.whatsapp.com');
  34. console.debug("New URL: ", newUrl);
  35. location.replace(newUrl);
  36. }
  37. })();