diff --git a/tdx-enhanced.js b/tdx-enhanced.js index 48a6aca..c9a88e7 100644 --- a/tdx-enhanced.js +++ b/tdx-enhanced.js @@ -67,6 +67,8 @@ 'zsite' : {'bg' : '#98A4AE', 'txt' : 'white'}, }; + var tdxtoolsUrl = "https://engineering.purdue.edu" + //regex for matching inline highlights var colorsByStatus = { '!!': {style: {background: 'var(--col-highlight-1)'}, type: 'highlight', re: new RegExp("\!! (.*) \!!","g")}, @@ -97,6 +99,7 @@ heading.style.color = q.txt parent.style.backgroundColor = q.bg } + handleHighlight("report",headingTxt,heading.parentElement) } @@ -470,9 +473,10 @@ let hours = duration.asHours() let alpha = hours / ageThreshold + alpha = alpha > 1 ? 1 : alpha let cell = modDate.cell - cell.style.background = `rgba(255,0,0,${alpha}` + handleHighlight("dateModified",alpha,cell) cell.classList.add(alpha > 0.5 ? "light" : "dark") } } @@ -485,34 +489,29 @@ //reply from user if (fromUser.txt == lastModified.txt && fromUser.txt != assignedTo.txt && assignedTo.txt != "Unassigned") { - item.row.style.backgroundColor = "var(--col-reply)"; + //item.row.style.backgroundColor = "var(--col-reply)"; + handleHighlight("reply",null,item.row) } //modified by internal if (lastModified.txt != fromUser.txt && lastModified.txt != assignedTo.txt) { let cell = item.LastModifiedByFullName.cell - cell.style.backgroundColor = "var(--col-modified)" + //cell.style.backgroundColor = "var(--col-modified)" + handleHighlight("userModified",null,cell) } } + //find internal users and highlight them + if ('ResponsibleFullName' in item) { + handleHighlight("person",item.ResponsibleFullName.txt,item.ResponsibleFullName.cell) + } else if ('Responsibility' in item) { + handleHighlight("person",item.Responsibility.txt,item.Responsibility.cell) + } + //find inline highlights for tasks if ('Title' in item) { let title = item.Title - for (const [key,color] of Object.entries(colorsByStatus)) { - let re = color.re.exec(title.txt) - if (re) { - let newTitle = re[1] - - let link = title.cell.querySelector("a") - if (link) { - title.cell.style.backgroundColor = color.style.background - link.innerText = newTitle - } - - //reset regex - color.re.lastIndex = 0 - } - } + handleHighlight("title",title.txt,title.cell) } //find links & open in new tab, if configured @@ -602,6 +601,92 @@ } + 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 + } + } + + const customHighlights = settings('get','customHighlights') || [] + for (const customHighlight of customHighlights) { + let customType = customHighlight.type + 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 (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=="userModified" && customType=="userModified") { + style = customHighlight.style + } + + if (type=="report" && customType=="report") { + if (customHighlight.value==txt) { + style = customHighlight.style + } + } + + if (type=="person" && customType=="person") { + if (customHighlight.value==txt) { + element = createHighlightBubble(element) + style = customHighlight.style + } + } + } + + if (style) { + //console.log("Apply custom highlight:",txt) + + let link = element.querySelector("a") + if (re && link) { + let newTitle = re[1] + link.innerText = newTitle + //reset regex + re.lastIndex = 0 + } + + for (const [attr,val] of Object.entries(style)) { + element.style[attr] = val + } + //element.style.backgroundColor = style.background + + } else { + //apply defaults + if (type=="reply") { + element.style.backgroundColor = "var(--col-reply)"; + } + if (type=="userModified") { + element.style.backgroundColor = "var(--col-modified)"; + } + if (type=="dateModified") { + element.style.backgroundColor = `rgba(255,0,0,${txt}`; + } + } + } + function generatePopup(href,w,h,l,t,source) { } @@ -865,6 +950,13 @@ +