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 @@ +
Custom Highlights
+
+
+ + +
+

Link Behavior

@@ -906,6 +998,19 @@ form.addEventListener("change", (event)=>{ settings("update",form) }); + form.addEventListener("submit", (event)=>{ + event.preventDefault() + }); + + //send/recieve data from popup + let customColorButton = settingsPage.querySelector("#colorPopup") + customColorButton.addEventListener("click", (event)=>{ + let url = `${tdxtoolsUrl}/ecnuds/tdx/userscript/coloreditor` + let colorWindow = window.open(url,"TDX Color Editor","popup=true") + colorWindow.onload = function() { + colorWindow.postMessage({msg:"here's the data"},"*") + } + }); //links let parent = iconBar.parentElement @@ -972,15 +1077,22 @@ var menu try { data = JSON.parse(localStorage.getItem("userSettings")) + if (!data) { throw "Data is null" + } else { + //resolve stringified objects + if ('customHighlights' in data) { + data.customHighlights = JSON.parse(data.customHighlights) + } } } catch(e) { - console.error("Couldn't grab settings!",e) + //console.error("Couldn't grab settings!",e) //set defaults data = { colorMode: getColorMode(), - linkBehavior: "tabs" + linkBehavior: "tabs", + customHighlights: [], } } @@ -989,6 +1101,11 @@ for (const setting in data) { let form = document.forms.settingsForm let value = data[setting] + + if (typeof value == "object") { + value = JSON.stringify(value) + } + console.log("Apply setting:",setting,value) if (form) { let elements = form.elements @@ -1008,6 +1125,10 @@ setColors('theme',data.theme) } } + + if ('customHighlights' in data) { + //parseCustomHighlights(data.highlightData) + } break } @@ -1030,7 +1151,7 @@ } case 'update': { - let form = value + let form = document.querySelector("#settingsForm") let formData = new FormData(form) data = Object.fromEntries([...formData]) console.log("Settings update!",data) @@ -1040,6 +1161,10 @@ } } + function parseCustomHighlights(data) { + console.log("Custom highlights:",data) + } + /* TDX TOOLS */ function checkPath() { let path = document.location.pathname @@ -1048,12 +1173,30 @@ if (pre) { console.log("Got key!",pre.innerText) let key = pre.innerText - window.opener.postMessage({tdxkey:key},"https://engineering.purdue.edu") + window.opener.postMessage({tdxkey:key},tdxtoolsUrl) window.close() } } } + window.addEventListener("message",(event) => { + let data = event.data + let origin = event.origin + let trgt = event.currentTarget + console.log("Message from:",origin,data,event) + + if (data.colorsReady) { + let colors = settings('get','customHighlights') + event.source.postMessage({ customColors: colors }, "*") + } + if (data.colorData) { + let element = document.getElementById("customHighlights") + let strData = JSON.stringify(data.colorData) + element.value = strData + settings('update') + } + },false); + changeTitle() //checkColorMode() settings("apply") @@ -1280,6 +1423,12 @@ display: flex; gap: 24px; } + +#settingsForm .textBox { + display: flex; + flex-direction: column; + gap: 8px; +} .calBox { display: flex; justify-content: space-around;