diff --git a/CLAUDE.md b/CLAUDE.md index 8c8512a..6d3c2d9 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -222,6 +222,12 @@ dialog#my-modal .my-button { - Translation keys include: UI buttons, modal content, system prompts, error messages, placeholders, input placeholders - Each language file follows format: `export const [code] = { key: "translation", ... };` +## Sprint Mode +- ALWAYS commit and push as soon as work is complete +- Do not wait for user confirmation to commit or push +- Commit frequently: small, focused commits over large batches +- Push immediately after each commit + ## Commit Message Guidelines - Use single line commit messages only - Never include Claude Code attribution or "Generated with Claude Code" diff --git a/public/src/content.js b/public/src/content.js index 18997b7..c6e9ae7 100644 --- a/public/src/content.js +++ b/public/src/content.js @@ -105,12 +105,24 @@ function extractDOMContent() { content += `**Meta Keywords**: ${metaKeywords.content}\n\n`; } + // Tags that never contain translatable/readable content + const SKIP_TAGS = new Set([ + "script", "style", "noscript", "template", "svg", + "iframe", "object", "embed", "canvas", "video", "audio", + ]); + // Recursively extract text and links from the body content function getTextWithLinks(element) { if (element.nodeType === Node.TEXT_NODE) { content += `${element.textContent} `; } else if (element.nodeType === Node.ELEMENT_NODE) { - if (element.tagName.toLowerCase() === "a") { + const tag = element.tagName.toLowerCase(); + + // Skip non-content elements + if (SKIP_TAGS.has(tag)) return; + if (element.hidden || element.getAttribute("aria-hidden") === "true") return; + + if (tag === "a") { // If it's a link, append the text and the href content += `[${element.textContent}](${element.href}) `; } else { diff --git a/public/src/translation.js b/public/src/translation.js index a731374..49e81ed 100644 --- a/public/src/translation.js +++ b/public/src/translation.js @@ -522,13 +522,17 @@ export function extractPageContent() { // Clone the document to avoid modifying the original const documentClone = document.cloneNode(true); - // Remove any open modals/dialogs that shouldn't be in the translation - const modalsToRemove = documentClone.querySelectorAll( - 'dialog[open], #uncloseai-embedded-modal, [id*="modal"], [class*="modal"]', - ); - modalsToRemove.forEach((modal) => modal.remove()); + // Remove non-translatable elements that waste context tokens + const junkSelectors = [ + 'dialog[open]', '#uncloseai-embedded-modal', + '[id*="modal"]', '[class*="modal"]', + 'script', 'style', 'noscript', 'template', + 'svg', 'iframe', 'canvas', + ]; + documentClone.querySelectorAll(junkSelectors.join(", ")) + .forEach((el) => el.remove()); - // Return the entire HTML of the document to preserve head, styles, and scripts + // Return cleaned HTML preserving structure for rendering return documentClone.documentElement.outerHTML; } diff --git a/scripts/bundle-extension.mjs b/scripts/bundle-extension.mjs index 3176dab..c5e74ca 100644 --- a/scripts/bundle-extension.mjs +++ b/scripts/bundle-extension.mjs @@ -23,11 +23,11 @@ const cdnResolverPlugin = { }), ); - // highlight.js: https://cdnjs.cloudflare.com/ajax/libs/highlight.js/ + // highlight.js: use core + common languages shim (not full 192-language build) build.onResolve( { filter: /^https:\/\/cdnjs\.cloudflare\.com\/ajax\/libs\/highlight\.js/ }, () => ({ - path: require.resolve("highlight.js"), + path: path.join(__dirname, "hljs-bundle.mjs"), }), ); }, diff --git a/scripts/hljs-bundle.mjs b/scripts/hljs-bundle.mjs new file mode 100644 index 0000000..df5856f --- /dev/null +++ b/scripts/hljs-bundle.mjs @@ -0,0 +1,68 @@ +// highlight.js core + common languages for the extension bundle. +// Full highlight.js (all 192 languages) adds ~1.2MB. This shim +// registers only the languages users are most likely to encounter +// in code blocks, keeping the bundle under 500KB. + +import hljs from "highlight.js/lib/core"; + +import bash from "highlight.js/lib/languages/bash"; +import c from "highlight.js/lib/languages/c"; +import cpp from "highlight.js/lib/languages/cpp"; +import csharp from "highlight.js/lib/languages/csharp"; +import css from "highlight.js/lib/languages/css"; +import diff from "highlight.js/lib/languages/diff"; +import dockerfile from "highlight.js/lib/languages/dockerfile"; +import go from "highlight.js/lib/languages/go"; +import ini from "highlight.js/lib/languages/ini"; +import java from "highlight.js/lib/languages/java"; +import javascript from "highlight.js/lib/languages/javascript"; +import json from "highlight.js/lib/languages/json"; +import kotlin from "highlight.js/lib/languages/kotlin"; +import lua from "highlight.js/lib/languages/lua"; +import makefile from "highlight.js/lib/languages/makefile"; +import markdown from "highlight.js/lib/languages/markdown"; +import perl from "highlight.js/lib/languages/perl"; +import php from "highlight.js/lib/languages/php"; +import plaintext from "highlight.js/lib/languages/plaintext"; +import python from "highlight.js/lib/languages/python"; +import ruby from "highlight.js/lib/languages/ruby"; +import rust from "highlight.js/lib/languages/rust"; +import scss from "highlight.js/lib/languages/scss"; +import shell from "highlight.js/lib/languages/shell"; +import sql from "highlight.js/lib/languages/sql"; +import swift from "highlight.js/lib/languages/swift"; +import typescript from "highlight.js/lib/languages/typescript"; +import xml from "highlight.js/lib/languages/xml"; +import yaml from "highlight.js/lib/languages/yaml"; + +hljs.registerLanguage("bash", bash); +hljs.registerLanguage("c", c); +hljs.registerLanguage("cpp", cpp); +hljs.registerLanguage("csharp", csharp); +hljs.registerLanguage("css", css); +hljs.registerLanguage("diff", diff); +hljs.registerLanguage("dockerfile", dockerfile); +hljs.registerLanguage("go", go); +hljs.registerLanguage("ini", ini); +hljs.registerLanguage("java", java); +hljs.registerLanguage("javascript", javascript); +hljs.registerLanguage("json", json); +hljs.registerLanguage("kotlin", kotlin); +hljs.registerLanguage("lua", lua); +hljs.registerLanguage("makefile", makefile); +hljs.registerLanguage("markdown", markdown); +hljs.registerLanguage("perl", perl); +hljs.registerLanguage("php", php); +hljs.registerLanguage("plaintext", plaintext); +hljs.registerLanguage("python", python); +hljs.registerLanguage("ruby", ruby); +hljs.registerLanguage("rust", rust); +hljs.registerLanguage("scss", scss); +hljs.registerLanguage("shell", shell); +hljs.registerLanguage("sql", sql); +hljs.registerLanguage("swift", swift); +hljs.registerLanguage("typescript", typescript); +hljs.registerLanguage("xml", xml); +hljs.registerLanguage("yaml", yaml); + +export default hljs;