移除 hcf2023.top WebGL 支持

完全移除 hcf2023.top 上的 WebGL 支持

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         移除 hcf2023.top WebGL 支持
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  完全移除 hcf2023.top 上的 WebGL 支持
// @author       You
// @match        *://hcf2023.top/*
// @match        *://*.hcf2023.top/*
// @grant        none
// @run-at       document-start
// @license MIT
// ==/UserScript==

(function() {
    'use strict';
    
    // 使用 Proxy 拦截 getContext 方法
    const originalGetContext = HTMLCanvasElement.prototype.getContext;
    
    HTMLCanvasElement.prototype.getContext = new Proxy(originalGetContext, {
        apply: function(target, thisArg, argumentsList) {
            const contextType = argumentsList[0];
            
            // 拦截所有 WebGL 相关的上下文请求
            if (contextType && typeof contextType === 'string' && 
                (contextType.includes('webgl') || contextType === 'experimental-webgl')) {
                console.log('WebGL 请求被拦截:', contextType);
                return null;
            }
            
            // 对于其他类型的上下文,正常执行
            return Reflect.apply(target, thisArg, argumentsList);
        }
    });
    
    // 彻底禁用 WebGL 相关构造函数
    const blockWebGL = () => {
        if (window.WebGLRenderingContext) {
            window.WebGLRenderingContext = null;
            delete window.WebGLRenderingContext;
        }
        
        if (window.WebGL2RenderingContext) {
            window.WebGL2RenderingContext = null;
            delete window.WebGL2RenderingContext;
        }
        
        if (window.WebGLProgram) {
            window.WebGLProgram = null;
            delete window.WebGLProgram;
        }
        
        if (window.WebGLShader) {
            window.WebGLShader = null;
            delete window.WebGLShader;
        }
        
        if (window.WebGLBuffer) {
            window.WebGLBuffer = null;
            delete window.WebGLBuffer;
        }
        
        if (window.WebGLTexture) {
            window.WebGLTexture = null;
            delete window.WebGLTexture;
        }
    };
    
    // 立即执行并监听后续的全局变量定义尝试
    blockWebGL();
    
    // 拦截可能的后续 WebGL 相关对象创建
    Object.defineProperty(window, 'WebGLRenderingContext', {
        get: () => undefined,
        set: () => {},
        configurable: false
    });
    
    Object.defineProperty(window, 'WebGL2RenderingContext', {
        get: () => undefined,
        set: () => {},
        configurable: false
    });
    
    console.log('hcf2023.top WebGL 支持已被完全移除');

    // 顺便干掉alert
    Object.defineProperty(window, 'alert', { value: function alert (data) {}});
})();