Skip to content

Commit

Permalink
its wraps dude
Browse files Browse the repository at this point in the history
  • Loading branch information
zheng980 committed Nov 5, 2025
1 parent 121a21c commit 1942a85
Show file tree
Hide file tree
Showing 10 changed files with 287 additions and 152 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,3 +228,4 @@ Both are included as minified files in the `lib/` directory.
4. Test thoroughly on TDX pages
5. Submit a pull request


22 changes: 16 additions & 6 deletions content/content.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,30 @@

// Listen for messages from popup windows (color editor)
window.addEventListener("message", (event) => {
// Only accept messages from trusted origin
if (event.origin !== tdxtoolsUrl) {
return
}

let data = event.data
let origin = event.origin
console.log("Message from:", origin, data, event)
if (!data) {
return
}

if (data.colorsReady) {
let colors = settings('get', 'customHighlights')
event.source.postMessage({ customColors: colors }, "*")
event.source.postMessage({ customColors: colors }, tdxtoolsUrl)
}
if (data.colorData) {
let element = document.getElementById("customHighlights")
if (element) {
let strData = JSON.stringify(data.colorData)
element.value = strData
settings('update')
try {
let strData = JSON.stringify(data.colorData)
element.value = strData
settings('update')
} catch (e) {
console.warn("Failed to process color data:", e)
}
}
}
}, false);
Expand Down
1 change: 0 additions & 1 deletion content/modules/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,6 @@ function getFilterForColor(rgbColor) {
}
}

console.log("Total iterations: ", iterationCount); // Log the total iterations
return bestResult;
}

Expand Down
76 changes: 45 additions & 31 deletions content/modules/highlighting.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,60 +19,74 @@ function handleHighlight(type, txt, element) {
var re
var style = null

for (const [key, color] of Object.entries(colorsByStatus)) {
re = color.re.exec(txt)
if (re) {
style = color.style
break
if (typeof txt === "string") {
for (const [key, color] of Object.entries(colorsByStatus)) {
// Reset regex lastIndex to avoid state issues
color.re.lastIndex = 0
re = color.re.exec(txt)
if (re) {
style = color.style
break
}
}
}

const customHighlights = settings('get', 'customHighlights') || []
for (const customHighlight of customHighlights) {
let customType = customHighlight.type
if (customType == "highlight") {
if (customType === "highlight") {
let char = customHighlight.value
let reg = new RegExp(`\\${char} (.*) \\${char}`, "g")
re = reg.exec(txt)
if (re) {
style = customHighlight.style
break
if (char && typeof txt === "string") {
try {
let reg = new RegExp(`\\${char} (.*) \\${char}`, "g")
re = reg.exec(txt)
if (re) {
style = customHighlight.style
break
}
} catch (e) {
console.warn("Invalid highlight pattern:", char, e)
}
}
}

if (type == "reply" && customType == "reply") {
if (type === "reply" && customType === "reply") {
style = customHighlight.style
}

if (type == "dateModified" && customType == "dateModified") {
style = customHighlight.style
if (style.background) {
let a = Math.floor(txt * 255).toString(16);
style.background = style.background + a
if (type === "dateModified" && customType === "dateModified") {
style = Object.assign({}, customHighlight.style) // Create copy to avoid modifying original
if (style.background && typeof txt === "number") {
let alpha = Math.floor(txt * 255).toString(16).padStart(2, '0')
style.background = style.background + alpha
}
}

if (type == "userModified" && customType == "userModified") {
if (type === "userModified" && customType === "userModified") {
style = customHighlight.style
}

if (type == "report" && customType == "report") {
if (customHighlight.value == txt) {
if (type === "report" && customType === "report") {
if (customHighlight.value === txt) {
element.classList.add("reportTitle")
style = customHighlight.style
}
}

if (type == "report" && customType == "report-regex") {
if ((new RegExp(customHighlight.value).exec(txt))) {
element.classList.add("reportTitle")
style = customHighlight.style
if (type === "report" && customType === "report-regex") {
try {
if ((new RegExp(customHighlight.value).test(txt))) {
element.classList.add("reportTitle")
style = customHighlight.style
}
} catch (e) {
console.warn("Invalid regex pattern for report highlight:", customHighlight.value, e)
}
}

if (type == "person" && customType == "person") {
if (customHighlight.value == txt) {
element = createHighlightBubble(element)
if (type === "person" && customType === "person") {
if (customHighlight.value === txt) {
element = createHighlightBubble(element, style?.background || "var(--col-highlight-1)", style?.color || "inherit")
style = customHighlight.style
}
}
Expand Down Expand Up @@ -105,14 +119,14 @@ function handleHighlight(type, txt, element) {

} else {
//apply defaults
if (type == "reply") {
if (type === "reply") {
element.style.backgroundColor = "var(--col-reply)";
}
if (type == "userModified") {
if (type === "userModified") {
element.style.backgroundColor = "var(--col-modified)";
}
if (type == "dateModified") {
element.style.backgroundColor = `rgba(255,0,0,${txt}`;
if (type === "dateModified") {
element.style.backgroundColor = `rgba(255,0,0,${txt})`;
}
}
}
14 changes: 12 additions & 2 deletions content/modules/observer.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,22 @@ let observer = new MutationObserver((mutations) => {
});
});

if (true) {
console.log("Observing...")
// Start observing DOM changes
if (document.body) {
observer.observe(document.body, {
characterDataOldValue: true,
subtree: true,
childList: true,
characterData: true
});
} else {
// Wait for body to be available
document.addEventListener('DOMContentLoaded', () => {
observer.observe(document.body, {
characterDataOldValue: true,
subtree: true,
childList: true,
characterData: true
});
});
}
Loading

0 comments on commit 1942a85

Please sign in to comment.