Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 293x 293x 26x 26x 26x 26x 293x 5x 5x 5x 1x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 219x 219x 26x 26x 16x 16x 26x 26x 219x 5x 5x 5x 1x 31x 31x 31x 31x 31x 31x 2x 31x 11x 11x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 3x 3x 31x 2x 2x 28x 3x 3x 26x 1x 1x 23x 4x 4x 4x 31x 31x 31x 1x 1x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 31x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 13x 10x 10x 13x 2x 2x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 8x 13x 15x 15x 9x 9x 9x 15x 7x 13x 1x 1x 1x 1x 1x 2x 2x 1x 1x 1x 2x 1x 1x 1x 1x 1x 1x 7x 13x 5x 5x 2x 13x 1x 1x 13x 1x 1x 11x 10x 10x 15x 12x 3x 3x 3x 3x 3x 9x 9x 3x 10x 10x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x 3x 3x 3x 3x | import { md5 } from './hash';
export interface BrowserInfo {
name: string;
version: string;
major: string;
}
export interface OSInfo {
name: string;
version: string;
}
export interface DeviceInfo {
type: 'desktop' | 'mobile' | 'tablet';
vendor: string;
model: string;
}
export interface EnvInfo {
browser: BrowserInfo;
os: OSInfo;
device: DeviceInfo;
url: string;
referrer: string;
title: string;
language: string;
user_agent: string;
screen_width: number;
screen_height: number;
viewport_width: number;
viewport_height: number;
}
function detectBrowser(ua: string): BrowserInfo {
const browsers: { name: string; pattern: RegExp; versionIndex?: number }[] = [
{ name: 'WeChat', pattern: /MicroMessenger\/([\d.]+)/i },
{ name: 'QQ Browser', pattern: /QIBrowser\/([\d.]+)/i },
{ name: 'UC Browser', pattern: /UCBrowser\/([\d.]+)/i },
{ name: 'Edge', pattern: /Edg\/([\d.]+)/i },
{ name: 'Edge', pattern: /Edge\/([\d.]+)/i },
{ name: 'Opera', pattern: /OPR\/([\d.]+)/i },
{ name: 'Opera', pattern: /Opera\/([\d.]+)/i },
{ name: 'Firefox', pattern: /Firefox\/([\d.]+)/i },
{ name: 'Safari', pattern: /Version\/([\d.]+).*Safari/i },
{ name: 'Chrome', pattern: /Chrome\/([\d.]+)/i },
{ name: 'IE', pattern: /MSIE ([\d.]+)/i },
{ name: 'IE', pattern: /Trident.*rv:([\d.]+)/i },
];
for (const b of browsers) {
const match = ua.match(b.pattern);
if (match) {
const version = match[1] || '';
const major = version.split('.')[0] || '';
return { name: b.name, version, major };
}
}
return { name: 'Unknown', version: '', major: '' };
}
function detectOS(ua: string): OSInfo {
const oss: { name: string; pattern: RegExp; versionIndex?: number }[] = [
{ name: 'Windows 11', pattern: /Windows NT 10\.0.*Win64.*x64/i },
{ name: 'Windows 10', pattern: /Windows NT 10\.0/i },
{ name: 'Windows 8.1', pattern: /Windows NT 6\.3/i },
{ name: 'Windows 8', pattern: /Windows NT 6\.2/i },
{ name: 'Windows 7', pattern: /Windows NT 6\.1/i },
{ name: 'Windows Vista', pattern: /Windows NT 6\.0/i },
{ name: 'Windows XP', pattern: /Windows NT 5\.1/i },
{ name: 'macOS', pattern: /Mac OS X ([\d_.]+)/i },
{ name: 'iOS', pattern: /OS ([\d_.]+) like Mac OS X/i },
{ name: 'Android', pattern: /Android ([\d.]+)/i },
{ name: 'Android', pattern: /Android/i },
{ name: 'Linux', pattern: /Linux/i },
];
for (const o of oss) {
const match = ua.match(o.pattern);
if (match) {
let version = match[1] || '';
if (version) {
version = version.replace(/_/g, '.');
}
return { name: o.name, version };
}
}
return { name: 'Unknown', version: '' };
}
function detectDevice(ua: string): DeviceInfo {
const isMobile = /Mobile|Android|iPhone|iPod|BlackBerry|Windows Phone|Opera Mini/i.test(ua);
const isTablet = /Tablet|iPad|PlayBook|Kindle|Silk/i.test(ua);
let type: 'desktop' | 'mobile' | 'tablet' = 'desktop';
if (isTablet) {
type = 'tablet';
} else if (isMobile) {
type = 'mobile';
}
let vendor = '';
let model = '';
const iphoneMatch = ua.match(/iPhone/i);
const ipadMatch = ua.match(/iPad/i);
const samsungMatch = ua.match(/SM-([A-Z0-9]+)/i);
const pixelMatch = ua.match(/Pixel ([0-9A-Z]+)/i);
const huaweiMatch = ua.match(/HUAWEI ([A-Z0-9]+)/i);
if (iphoneMatch) {
vendor = 'Apple';
model = 'iPhone';
} else if (ipadMatch) {
vendor = 'Apple';
model = 'iPad';
} else if (samsungMatch) {
vendor = 'Samsung';
model = samsungMatch[1];
} else if (pixelMatch) {
vendor = 'Google';
model = `Pixel ${pixelMatch[1]}`;
} else if (huaweiMatch) {
vendor = 'Huawei';
model = huaweiMatch[1];
}
return { type, vendor, model };
}
export function getEnvInfo(): EnvInfo {
const ua = typeof navigator !== 'undefined' ? navigator.userAgent : '';
const browser = detectBrowser(ua);
const os = detectOS(ua);
const device = detectDevice(ua);
return {
browser,
os,
device,
url: typeof location !== 'undefined' ? location.href : '',
referrer: typeof document !== 'undefined' ? document.referrer : '',
title: typeof document !== 'undefined' ? document.title : '',
language: typeof navigator !== 'undefined' ? navigator.language : '',
user_agent: ua,
screen_width: typeof screen !== 'undefined' ? screen.width : 0,
screen_height: typeof screen !== 'undefined' ? screen.height : 0,
viewport_width: typeof window !== 'undefined' ? window.innerWidth : 0,
viewport_height: typeof window !== 'undefined' ? window.innerHeight : 0,
};
}
export function getPageUrl(): string {
return typeof location !== 'undefined' ? location.href : '';
}
export function getReferrer(): string {
return typeof document !== 'undefined' ? document.referrer : '';
}
export function sanitizeUrl(url: string): string {
if (!url) return url;
// 过滤 javascript: 伪协议防止 XSS
if (/^\s*javascript:/i.test(url)) {
return 'javascript:[filtered]';
}
try {
const urlObj = new URL(url);
const sensitiveParams = [
'password', 'passwd', 'pwd',
'token', 'access_token', 'refresh_token',
'api_key', 'apikey', 'key',
'secret', 'private_key',
'code', 'auth',
'id_token', 'idToken',
'session', 'session_id',
];
const params = urlObj.searchParams;
let modified = false;
for (const key of Array.from(params.keys())) {
const lowerKey = key.toLowerCase().replace(/[-_]/g, '_');
if (sensitiveParams.some(s => lowerKey.includes(s))) {
params.set(key, '[Filtered]');
modified = true;
}
}
if (urlObj.hash && urlObj.hash.length > 1) {
const hashContent = urlObj.hash.substring(1);
if (hashContent.includes('=')) {
const hashParams = new URLSearchParams(hashContent);
let hashModified = false;
for (const key of Array.from(hashParams.keys())) {
const lowerKey = key.toLowerCase().replace(/[-_]/g, '_');
if (sensitiveParams.some(s => lowerKey.includes(s))) {
hashParams.set(key, '[Filtered]');
hashModified = true;
}
}
if (hashModified) {
urlObj.hash = '#' + hashParams.toString();
modified = true;
}
}
}
if (modified) {
return urlObj.toString();
}
return url;
} catch {
return url;
}
}
export function shouldIgnoreUrl(url: string, ignoreUrls: (string | RegExp)[] = []): boolean {
if (!ignoreUrls || ignoreUrls.length === 0) return false;
return ignoreUrls.some(pattern => {
if (typeof pattern === 'string') {
if (pattern.includes('*')) {
// 移除开头的 ^ 和结尾的 $,允许匹配 URL 的任意部分
const escaped = pattern.replace(/[.+?^${}()|[\]\\]/g, '\\$&').replace(/\*/g, '.*');
const regex = new RegExp(escaped);
return regex.test(url);
}
return url.includes(pattern);
}
return pattern.test(url);
});
}
const BROWSER_CODE_MAP: Record<string, string> = {
'Chrome': 'c',
'Safari': 's',
'Firefox': 'f',
'Edge': 'e',
'Opera': 'o',
'IE': 'i',
'WeChat': 'w',
'QQ Browser': 'q',
'UC Browser': 'u',
'Mobile Chrome': 'cm',
'Mobile Safari': 'sm',
};
const OS_CODE_MAP: Record<string, string> = {
'Windows 11': 'w11',
'Windows 10': 'w10',
'Windows 8.1': 'w81',
'Windows 8': 'w8',
'Windows 7': 'w7',
'Windows Vista': 'wv',
'Windows XP': 'wxp',
'macOS': 'm',
'iOS': 'i',
'Android': 'a',
'Linux': 'l',
};
export function getContexts() {
const env = getEnvInfo();
const browserCode = BROWSER_CODE_MAP[env.browser.name] || env.browser.name.toLowerCase();
const osCode = OS_CODE_MAP[env.os.name] || env.os.name.toLowerCase();
return {
browser: {
name: browserCode,
version: env.browser.major,
},
os: {
name: osCode,
version: env.os.version.split('.')[0],
},
device: {
type: env.device.type,
brand: env.device.vendor || undefined,
model: env.device.model || undefined,
},
};
}
export function getContextId(): string {
const env = getEnvInfo();
const key = `${env.browser.name}|${env.browser.major}|${env.os.name}|${env.os.version.split('.')[0]}|${env.device.type}|${env.device.vendor}|${env.device.model}|${env.language}`;
return md5(key).substring(0, 16);
}
|