INNER CODE UNIT · JavaScript

match

EdgeTypE/better-deepseek · src/background/index.js:445

  const match = contentType.match(/charset\s*=\s*([^\s;]+)/i);
  return match ? match[1].trim().replace(/^["']|["']$/g, "") : null;
}

function detectCharsetFromHtml(buffer) {
  const scanView = new TextDecoder("latin1").decode(buffer.slice(0, 10240));

  let match = scanView.match(/<meta[\s>][^>]*charset\s*=\s*["']?\s*([a-zA-Z0-9_-]+)\s*["']?[^>]*\/?>/i);
  if (match) return match[1];

  match = scanView.match(/<meta\s+http-equiv\s*=\s*["']?\s*Content-Type\s*["']?\s*content\s*=\s*["'][^"']*charset\s*=\s*([a-zA-Z0-9_-]+)/i);
  if (match) return match[1];

  return null;
}

async function fetchPageContent(url, options = {}) {
  if (!url) throw new Error("No URL provided.");

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…