API WhatsApp To WEB WhatsApp Redirect with Debug

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
    }
})();