Source Viewer

View the HTML source code of any online web page. (use the Tampermonkey Command Menu)

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name            Source Viewer
// @name:de         Seitenquelltext anzeigen
// @name:fr         Visualiseur de Code Source
// @name:es         Visor de Código Fuente
// @name:it         Visualizzatore del Codice Sorgente
// @name:pt         Visualizador de Código-Fonte
// @name:ru         Просмотр исходного кода
// @name:zh         网页源代码查看器
// @name:ja         ページソースの表示
// @description     View the HTML source code of any online web page. (use the Tampermonkey Command Menu)
// @description:de  Schauen Sie sich den Seitenquelltext von jeder beliebigen Website an. (nutzen Sie das Tampermonkey-Menü)
// @description:fr  Affichez le code source HTML de n'importe quelle page Web en ligne. (utilisez le menu de commandes Tampermonkey)
// @description:es  Ver el código fuente HTML de cualquier página web en línea. (utilice el menú de comandos de Tampermonkey)
// @description:it  Visualizza il codice sorgente HTML di qualsiasi pagina web online. (usa il menu dei comandi di Tampermonkey)
// @description:pt  Visualize o código-fonte HTML de qualquer página da web online. (use o menu de comandos do Tampermonkey)
// @description:ru  Просматривайте HTML-исходный код любой веб-страницы онлайн. (используйте командное меню Tampermonkey)
// @description:zh  查看任何在线网页的 HTML 源代码。(使用 Tampermonkey 命令菜单)
// @description:ja  オンラインのあらゆるウェブページの HTML ソースコードを表示します。(Tampermonkey コマンドメニューを使用)
// @version         6.9.0
// @author          Wack.3gp (https://greasyfork.org/users/4792)
// @copyright       2013+, Wack.3gp
// @namespace       https://greasyfork.org/users/4792
// @license         CC BY-NC-ND 4.0; http://creativecommons.org/licenses/by-nc-nd/4.0/
//
// @match           *://*/*
// @noframes
//
// @grant           GM_registerMenuCommand
// @grant           GM_notification
//
// @compatible      Chrome tested with Tampermonkey
// @supportURL      https://greasyfork.org/scripts/4611/feedback
// @contributionURL https://www.paypal.com/donate/?hosted_button_id=BYW9D395KJWZ2
// @contributionAmount €1.00
// ==/UserScript==

/* jshint esversion: 9 */

(function() {
    'use strict';

    const _vault = "4792";
    const _isOriginal = GM_info.script.namespace.includes(_vault);
    const _originalURL = GM_info.script.supportURL.replace("feedback", "");

    const checkProtection = () => {
        if (!_isOriginal) {
            alert("Please install the Original Version");
            window.location.href = _originalURL;
            return false;
        }
        return true;
    };

    GM_registerMenuCommand("🔍 View Source: " + window.location.hostname, function () {
        
        if (!checkProtection()) return;

        const doctype = new XMLSerializer().serializeToString(document.doctype) || "";
        let source = doctype + "\n" + document.documentElement.outerHTML;

        source = source.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");

        const sourceWindow = window.open("");
        sourceWindow.document.write(`
            <html>
            <head>
                <title>Source: ${window.location.href}</title>
                <style>
                    body { margin: 0; background: #1e1e1e; color: #d4d4d4; font-family: 'Consolas', 'Monaco', monospace; }
                    pre { padding: 20px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; }
                </style>
            </head>
            <body>
                <pre><code>${source}</code></pre>
            </body>
            </html>
        `);
        sourceWindow.document.close();
    });

        GM_registerMenuCommand("☕ Buy Me a Coffee :)", function () {
alert("Hello, I'm " + GM_info.script.author + "\nand I wrote this script as a hobby.\nIf you find it useful, buy me a coffee :)");
    window.open(GM_info.script.header.match(/@contributionURL\s+(.+)/)[1], "_blank");
        });
        
    if (_isOriginal) {
        console.log(`%c ${GM_info.script.name} v${GM_info.script.version} %c (Verified Original)`, 
                    "background: #f44336; color: white; font-weight: bold; padding: 2px 5px;", "color: #f44336;");
    }

})();