Great Fork - Xem nguồn trang web

Hiển thị mã nguồn của trang web hiện tại và cho phép đóng cửa sổ mã nguồn

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Great Fork - Xem nguồn trang web
// @version      0.3
// @description  Hiển thị mã nguồn của trang web hiện tại và cho phép đóng cửa sổ mã nguồn
// @author       TieuThanhNhi
// @match        *://*/*
// @grant        none
// @namespace https://greasyfork.org/users/1177795
// ==/UserScript==

(function() {
    'use strict';

    // Tạo một button để mở mã nguồn của trang web
    var btn = document.createElement("button");
    btn.textContent = "Xem mã nguồn";
    btn.style.position = "fixed";
    btn.style.top = "10px";
    btn.style.left = "10px";
    btn.style.zIndex = "9999";
    btn.addEventListener("click", function() {
        // Mở một cửa sổ mới hiển thị mã nguồn
        var sourceWindow = window.open("about:blank", "_blank", "noopener,noreferrer");
        sourceWindow.document.write("<pre>" + escapeHTML(document.documentElement.outerHTML) + "</pre>");
        
        // Thêm nút thoát để đóng cửa sổ
        var exitButton = sourceWindow.document.createElement("button");
        exitButton.textContent = "Thoát";
        exitButton.style.position = "fixed";
        exitButton.style.top = "10px";
        exitButton.style.left = "10px";
        exitButton.style.zIndex = "9999";
        exitButton.addEventListener("click", function() {
            sourceWindow.close();
        });
        sourceWindow.document.body.appendChild(exitButton);
    });
    
    document.body.appendChild(btn);

    // Hàm để chuyển đổi các ký tự đặc biệt sang HTML entities
    function escapeHTML(text) {
        var map = {
            '&': '&amp;',
            '<': '&lt;',
            '>': '&gt;',
            '"': '&quot;',
            "'": '&#039;'
        };
        return text.replace(/[&<>"']/g, function(m) { return map[m]; });
    }
})();