add sprint mode, bundle-extension scripts, fix context bloat in DOM extraction
This commit is contained in:
parent
cd6a432e3f
commit
6d867260a6
5 changed files with 99 additions and 9 deletions
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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"),
|
||||
}),
|
||||
);
|
||||
},
|
||||
|
|
|
|||
68
scripts/hljs-bundle.mjs
Normal file
68
scripts/hljs-bundle.mjs
Normal file
|
|
@ -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;
|
||||
Loading…
Add table
Add a link
Reference in a new issue