Compare commits

..

No commits in common. "230c20f6499203d2db0a2ee78d73d0e91aa9ba16" and "638a753a13ccb39ef9e9d10f601cfcb918e3e5a1" have entirely different histories.

2 changed files with 22 additions and 61 deletions

View File

@ -9,8 +9,7 @@
"rules": { "rules": {
"quotes": ["warn", "double"], "quotes": ["warn", "double"],
"semi": ["warn", "never"], "semi": ["warn", "never"],
"indent": ["warn", 2], "indent": ["warn", 4],
"prettier/prettier": 0, "prettier/prettier": 0
"no-unused-vars": ["warn", { "argsIgnorePAttern": "^_" }]
} }
} }

View File

@ -22,71 +22,33 @@ const highlightCodes = {
} }
const findSportsItems = () => { const findSportsItems = () => {
let sportsItems = [] let rawItems = []
channelTags.forEach((tag) => { channelTags.forEach((tag) => {
const query = `${tag} .op` const query = `${tag} .op`
const channelItems = document.querySelectorAll(query) const channelItems = document.querySelectorAll(query)
rawItems.push(...channelItems)
channelItems.forEach((item) => {
const afterStyle = window.getComputedStyle(item, "::after")
if (afterStyle.content !== "none" && afterStyle.content !== '""') {
sportsItems.push(item)
}
})
}) })
return sportsItems
}
const applyHighlight = () => { let sportsItems = []
const sportsItems = findSportsItems()
sportsItems.forEach((item) => { rawItems.forEach((item) => {
if (item.parentElement.style.backgroundColor !== highlightCodes["sport"]) { const afterStyle = window.getComputedStyle(item, "::after")
item.parentElement.style.backgroundColor = highlightCodes["sport"]
if (afterStyle.content !== "none" && afterStyle.content !== '""') {
sportsItems.push(item)
} }
}) })
return sportsItems
}
window.addEventListener("load", () => {
const sportsItems = findSportsItems()
sportsItems.forEach((item) => {
item.parentElement.style.backgroundColor = highlightCodes["sport"]
})
console.log("ip-highlight.js: All sports events highlighted successfully!") console.log("ip-highlight.js: All sports events highlighted successfully!")
} })
const createUpdateObserver = () => {
let debounceTimer
const callback = (mutationsList, _observer) => {
clearTimeout(debounceTimer)
debounceTimer = setTimeout(() => {
for (let mutation of mutationsList) {
if (mutation.type === "childList") {
console.log(
"ip-highlight.js: Re-applying highlighting due to changes in the catalog"
)
applyHighlight()
break
}
}
}, 100) // Debounce for 100ms
}
return new MutationObserver(callback)
}
const initializeHighlighter = () => {
const targetNode = document.getElementById("programtable")
if (targetNode) {
applyHighlight()
const observer = createUpdateObserver()
observer.observe(targetNode, { childList: true, subtree: true })
} else {
console.log("ip-highlight.js: Program table not found, retrying in 100ms")
setTimeout(initializeHighlighter, 100)
}
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", initializeHighlighter)
} else {
initializeHighlighter()
}