API WhatsApp To WEB WhatsApp Redirect with Debug

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

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        API WhatsApp To WEB WhatsApp Redirect with Debug
// @icon        https://i.imgur.com/r2qkepk.png
// @namespace   Whatsapp API
// @include     *://api.whatsapp.com/*
// @version     1.2
// @author      SleepTheGod
// @namespace   SleepTheGod
// @grant       GM_addStyle
// @require     https://code.jquery.com/jquery-3.6.0.min.js
// @license     GPL version 2 or any later version; http://www.gnu.org/licenses/gpl-2.0.txt
// @run-at      document-start
// @description Redirects API WhatsApp links to Web WhatsApp and logs page information for debugging.
// ==/UserScript==

(function() {
    'use strict';

    // Debugging the entire page
    console.debug("Page URL: ", location.href);
    console.debug("Page Hostname: ", location.hostname);
    console.debug("Document Title: ", document.title);
    console.debug("Document Cookies: ", document.cookie);
    console.debug("User Agent: ", navigator.userAgent);
    console.debug("Full HTML of the page: ", document.documentElement.outerHTML);

    // Check if the URL contains 'api.whatsapp'
    if (location.hostname === 'api.whatsapp.com') {
        // Debug the redirection action
        console.debug("Redirecting from API to Web WhatsApp...");

        // Redirect to 'web.whatsapp.com' with the same path and query parameters
        const newUrl = location.href.replace('api.whatsapp.com', 'web.whatsapp.com');
        console.debug("New URL: ", newUrl);
        location.replace(newUrl);
    }
})();