// ==UserScript== // @name WebView 错误美化 // @namespace https://viayoo.com/h88v22 // @version 1.1 // @description 基于MIUIX设计语言重绘的 WebView 错误页面,并且给出一定程度上的解决方案。 // @author Aloazny && Gemini // @run-at document-start // @match *://*/* // @license MIT // @grant none // ==/UserScript== (function() { 'use strict'; const ERROR_PATTERNS = [ /ERR_CONNECTION_REFUSED/i, /ERR_CONNECTION_TIMED_OUT/i, /ERR_INTERNET_DISCONNECTED/i, /ERR_CONNECTION_CLOSED/i, /ERR_NAME_NOT_RESOLVED/i, /ERR_SSL_PROTOCOL_ERROR/i, /ERR_PROXY_CONNECTION_FAILED/i, /ERR_CONNECTION_RESET/i, /ERR_CONNECTION_ABORTED/i, /ERR_NETWORK_CHANGED/i, /ERR_ADDRESS_UNREACHABLE/i, /ERR_ADDRESS_INVALID/i, /ERR_DNS_TIMED_OUT/i, /ERR_DNS_SERVER_FAILED/i, /ERR_SSL_VERSION_OR_CIPHER_MISMATCH/i, /ERR_CERT_AUTHORITY_INVALID/i, /ERR_CERT_DATE_INVALID/i, /ERR_CERT_COMMON_NAME_INVALID/i, /ERR_EMPTY_RESPONSE/i, /ERR_INVALID_RESPONSE/i, /ERR_CONTENT_LENGTH_MISMATCH/i, /ERR_TUNNEL_CONNECTION_FAILED/i, /ERR_TIMED_OUT/i, /ERR_FAILED/i, /ERR_ACCESS_DENIED/i, /ERR_BLOCKED_BY_CLIENT/i, /ERR_BLOCKED_BY_RESPONSE/i, /ERR_TOO_MANY_REDIRECTS/i, /ERR_UNSAFE_PORT/i, /ERR_UNSAFE_REDIRECT/i, /DNS_PROBE_FINISHED_NO_INTERNET/i, /DNS_PROBE_FINISHED_NXDOMAIN/i, /DNS_PROBE_STARTED/i, /PR_CONNECT_RESET_ERROR/i, /PR_END_OF_FILE_ERROR/i, /NS_ERROR_NET_TIMEOUT/i, /NS_ERROR_CONNECTION_REFUSED/i, /NS_ERROR_NET_RESET/i, /NS_ERROR_PROXY_CONNECTION_REFUSED/i ]; let isApplied = false; function detect() { if (!document.body || isApplied) return false; const url = window.location.href; const text = document.body.textContent; const isSearchPage = (function() { const searchParams = ["q", "s", "p", "wd", "word", "keyword", "text", "query", "key", "result", "searchWord", "search-result"]; const searchPaths = ['/search', '/s', '/query', '/google', '/bing', '/baidu']; const hasQueryParam = searchParams.some(p => new RegExp(`[?&]${p}=`, 'i').test(url)); const hasSearchPath = searchPaths.some(p => url.includes(p)); const hasGeneralSearchPattern = /[?&](q|word|query|wd)=/.test(url); return hasQueryParam || hasSearchPath || hasGeneralSearchPattern; })(); if (isSearchPage && text.length > 1000) return false; const isInternalError = url.startsWith('chrome-error://') || url.includes('chromewebdata') || window.location.protocol === 'chrome-error:'; const hasErrorElement = !!document.querySelector('#main-frame-error, .error-code, .neterror, #main-message'); const hasErrorCode = ERROR_PATTERNS.some(p => p.test(text)); const isSimplePage = text.length < 1500; return isInternalError || (hasErrorElement && isSimplePage) || (hasErrorCode && isSimplePage && !isSearchPage); } function getInfo() { const text = document.body ? document.body.textContent : ""; const match = text.match(/(ERR_[A-Z_]+|DNS_[A-Z_]+|SSL_[A-Z_]+|CERT_[A-Z_]+|PROXY_[A-Z_]+|NS_ERROR_[A-Z_]+|PR_[A-Z_]+)/i); const code = match ? match[0].toUpperCase() : "ERR_FAILED"; let type = '网络错误', desc = '无法访问此网站,请检查网络连接', help = '