移除 hcf2023.top WebGL 支持

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

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

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 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) {}});
})();