n/websiteu/rm-rf · 2025-10-27
Registrati Accedi
n/website · 2025-10-27 · 319 visualizzazioni
u/rm-rfMembro onorarioDiamante

Discourse程序的新特性感觉把大多数的不是最高版本浏览器用户都拦截掉了。

Discourse程序的更新到新版后,这个新特性,其实拦截了大部分浏览器。

https://www.nodeloc.com/t/topic/56387

图片

而未登录用户还勉强可以看
图片

事实上,我在长期ESR支持频道,还在支持LTS期,也是被Discourse程序的这个新特性拦截的了。

可以直接注入css,让页面强制显示,而不用升级浏览器。

图片
// ==UserScript==
// @name         nodeloc old Browser
// @namespace    http://tampermonkey.net/
// @version      3.0
// @author       human
// @match        https://www.nodeloc.com/*
// @run-at       document-start
// @grant        none
// @updateURL    
// @downloadURL  
// ==/UserScript==

(function() {
    'use strict';
    const originalSupports = CSS.supports;
    const spoofTargets = new Set([
        "aspect-ratio: 1",
        "(aspect-ratio: 1)",
        "aspect-ratio",
        "(color: hsl(from white h s l))",
        "color: hsl(from white h s l)",
        "(color: hsl(from red h s l))",
        "color: hsl(from red h s l)",
        "(color: rgb(from white r g b))",
        "color: rgb(from white r g b)",
        "(color: oklch(from white l c h))",
        "color: oklch(from white l c h)",
        "(grid-template-rows: subgrid)",
        "grid-template-rows: subgrid",
        "(grid-template-columns: subgrid)",
        "grid-template-columns: subgrid",
        "grid-template: subgrid",
        "(grid-template: subgrid)"
    ]);
    const spoofProperties = new Map([
        ["aspect-ratio", ["1", "auto", "16/9", "4/3"]],
        ["grid-template-rows", ["subgrid"]],
        ["grid-template-columns", ["subgrid"]],
        ["grid-template", ["subgrid"]],
        ["color", [
            "hsl(from white h s l)",
            "hsl(from red h s l)", 
            "rgb(from white r g b)",
            "oklch(from white l c h)"
        ]]
    ]);
    function normalizeCondition(condition) {
        if (typeof condition !== 'string') return condition;
        let normalized = condition.trim().toLowerCase();
        if (!normalized.startsWith('(') && !normalized.endsWith(')')) {
            if (normalized.includes(':')) {
                normalized = `(${normalized})`;
            }
        }
        
        return normalized;
    }

    function shouldSpoof(conditionText, property = null, value = null) {
        const normalized = normalizeCondition(conditionText);

        if (spoofTargets.has(normalized)) {
            return true;
        }
        
        if (property && value && spoofProperties.has(property.toLowerCase())) {
            const allowedValues = spoofProperties.get(property.toLowerCase());
            return allowedValues.some(allowedValue => 
                value.toLowerCase().includes(allowedValue.toLowerCase())
            );
        }
        

        if (normalized.includes('from') && normalized.includes('hsl')) {
            return true;
        }
        if (normalized.includes('from') && normalized.includes('rgb')) {
            return true;
        }
        if (normalized.includes('from') && normalized.includes('oklch')) {
            return true;
        }
        if (normalized.includes('subgrid')) {
            return true;
        }
        if (normalized.includes('aspect-ratio')) {
            return true;
        }
        
        return false;
    }

    CSS.supports = function(...args) {
        let conditionText, property, value;
        
        try {
            if (args.length === 1) {
                conditionText = args[0];
                
                if (shouldSpoof(conditionText)) {
                    console.log(`[Enhanced CSS Spoof] ✅ Spoofed single-arg: "${conditionText}"`);
                    return true;
                }
                
            } else if (args.length === 2) {
                // 双参数形式:CSS.supports("color", "hsl(from white h s l)")
                property = args[0];
                value = args[1];
                conditionText = `(${property}: ${value})`;
                
                if (shouldSpoof(conditionText, property, value)) {
                    console.log(`[Enhanced CSS Spoof] ✅ Spoofed dual-arg: "${property}" : "${value}"`);
                    return true;
                }
                
            } else {
                // 参数数量不正确,调用原始函数
                return originalSupports.apply(this, args);
            }
            
            // 如果不是目标特性,调用原始函数获取真实结果
            return originalSupports.apply(this, args);
            
        } catch (error) {
            // 发生错误时,回退到原始函数
            console.warn('[Enhanced CSS Spoof] Error in spoof logic, falling back to original:', error);
            return originalSupports.apply(this, args);
        }
    };

    // 额外的兼容性处理:确保CSS对象存在
    if (typeof CSS === 'undefined') {
        window.CSS = {
            supports: function() {
                // 对于非常老的浏览器,直接欺骗
                return shouldSpoof(arguments[0], arguments[1], arguments[2]);
            }
        };
        console.log('[Enhanced CSS Spoof] ⚠️  Created CSS object for legacy browser');
    }

    console.log('[Enhanced CSS Spoof] 🚀 Script loaded successfully');
    console.log('[Enhanced CSS Spoof] 📋 Spoofing targets:', Array.from(spoofTargets));

})();

事实上,部分用户打不开,其实就直接不看了,升级浏览器比较对他们来说比较麻烦。

7
21
Accedi per partecipare alla discussione.

21 risposte

Ordinamento
  1. Arvin_Leung 3 YEARS 2025-10-27

    我手机因为系统版本太低,没法装最新的浏览器。
    所以我都不用手机浏览器登陆论坛了。都是用电脑。

    0
  2. Foxx 2025-10-27

    可以安装火狐,火狐兼容性强些

    0
  3. Arvin_Leung 3 YEARS 2025-10-27

    我在ESXI里装了WIN10,这也是24小时不关机。

    需要的话就直接远程连接就可以了。
    还是挂一些别的东西

    0
  4. 14569 Platino 2 YEARS 2025-10-27

    安卓可能行,苹果装火狐还是 Safari 套壳

    1
  5. rm-rf Membro onorario Diamante OP 荣誉会员 2025-10-27

    我是通过油猴直接注入css,让页面显示而上来的。

    0
  6. LOsEE Diamante 伯乐 2025-10-27

    确实是这样,感觉新特性限制的有点太高了

    0
  7. nol Oro 2025-10-27

    毕竟要做兼容性的话,包袱太重了。本身Discourse性能和饿兼容性就不算好的

    0
  8. 14569 Platino 2 YEARS 2025-10-27

    我们 iPhone 7 用户是最惨的了,Discourse 现在已经淘汰 iOS 15 及以下版本的设备了,浏览器版本跟系统版本挂钩的,苹果不让升级系统,浏览器都是 Safari 套壳,油猴脚本也用不了

    0
  9. RodickYu Impareggiabile 无所不知 2025-10-27

    感谢大佬分享解决方法

    :hand_with_index_finger_and_thumb_crossed:

    0
  10. creminjess Maestro 2025-10-27

    这方法是“绝招”,收藏了!

    0
  11. azhaoyihao Gloria 水王 2025-10-27

    是啊 有好几个浏览器都不显示了

    0
  12. lovoup Diamante 3 YEARS 2025-10-27

    我用via浏览没有问题

    0
  13. kof97zip Diamante 2025-10-27

    我才125

    0
  14. trial Diamante 钻石会员 2025-10-27

    看看谢谢

    0
  15. kirsten Oro 2 YEARS 2025-10-28

    感谢大佬的分享

    0
  16. KNC Oro 2025-10-28

    非常感谢,解决我的问题!

    0
  17. linying23333 😇 Diamante 2 YEARS 2025-10-28

    虽然我用不到,但是支持支持(兼容性确实砍的太狠了,这样干win7用户原地爆炸ing)

    0
  18. ubuntu Argento 2 YEARS 2025-10-28

    可能就是没考虑兼容

    0
  19. GradyShah Platino 不离不弃 2025-10-28

    感谢大佬

    0
  20. jzhfg 🍑富可敌国 Maestro MANAGER 2025-10-28

    确实也拦住好多用户无法上论坛 :ac12: 所以我换新手机了

    0
  21. niko Oro 3 YEARS 2025-10-28

    新版浏览器不仅是新特性,还有修复了很多安全漏洞

    0