迷失幻境
路径已断,迷雾笼罩,尝试返回现实吧。
// ==UserScript== // @name Via 浏览器 404 和网络连接失败页面美化 // @namespace https://viayoo.com/ // @version 1.11 // @description 为 Via 浏览器错误页面(404 Not Found 和网络连接失败)注入美化,404 页面采用幻境风格,网络连接失败页面采用生命美学与科幻风格,支持日夜模式自动切换 // @author 是小白呀 & Grok // @match *://*/* // @license MIT // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 提取错误页面中的 URL(用于网络连接失败页面) function extractErrorUrl() { const bodyText = document.body ? document.body.innerText : ''; const urlMatch = bodyText.match(/(https?:\/\/[^\s]+)/i); return urlMatch ? urlMatch[0] : '未知地址'; } // 提取错误代码和服务器信息(用于 404 页面) function extractErrorInfo() { const bodyText = document.body ? document.body.innerText : ''; const errorCodeMatch = bodyText.match(/net::ERR_[A-Z_]+/) || document.title.match(/404 Not Found/) || ['404 Not Found']; const serverMatch = bodyText.match(/nginx/i) ? 'nginx' : ''; return { errorCode: errorCodeMatch[0], server: serverMatch }; } // 检查是否为 404 错误页面(严格匹配“404 Not Found”和“nginx”) function checkFor404Page() { let has404 = false; let hasNginx = false; // 检查标题 if (/404 Not Found/i.test(document.title)) { has404 = true; } // 检查 body 内容 if (document.body) { const text = document.body.innerText || ''; if (/404 Not Found/i.test(text)) { has404 = true; } if (/nginx/i.test(text)) { hasNginx = true; } } // 必须同时满足“404 Not Found”和“nginx” return has404 && hasNginx; } // 检查是否为网络连接失败页面 function checkForConnectionErrorPage() { // 排除 404 页面 if (checkFor404Page()) { return false; } // 快速检查标题 if (/无法打开|Error/i.test(document.title)) { return true; } // 检查 body 内容 if (document.body) { const text = document.body.innerText || ''; if (/net::ERR_|网页无法打开|无法连接|ERR_NAME_NOT_RESOLVED/i.test(text)) { return true; } // 空页面 if (document.body.innerHTML.trim() === '') { return true; } } return false; } // 替换 404 错误页面(幻境风格) function replace404Page() { const { errorCode, server } = extractErrorInfo(); document.documentElement.innerHTML = `
路径已断,迷雾笼罩,尝试返回现实吧。
无法感知星辰脉动,请检查网络或稍后重试。