Discourse程序的更新到新版后,这个新特性,其实拦截了大部分浏览器。
而未登录用户还勉强可以看
事实上,我在长期ESR支持频道,还在支持LTS期,也是被Discourse程序的这个新特性拦截的了。
可以直接注入css,让页面强制显示,而不用升级浏览器。
// ==UserScript==
// @name nodeloc old Browser
// @namespace http://tampermonkey.net/
// @version 3.0
// @author human
// @match https://6waed6lo6phn6.pages.dev/*
// @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));
})();
事实上,部分用户打不开,其实就直接不看了,升级浏览器比较对他们来说比较麻烦。


