Click here to manage keyword/highlight sets
" + "' + e.target.textContent + '
' + ''; var rng = document.createRange(); rng.selectNodeContents(e.target.children[0]); var sel = window.getSelection(); sel.removeAllRanges(); sel.addRange(rng); if (hlobj[hlset].prevkeyw && hlobj[hlset].prevkeyw != '') { document.getElementById('thsrevert' + hlset).removeAttribute('disabled'); document.getElementById('thsrevert' + hlset).setAttribute('title','Revert to "' + hlobj[hlset].prevkeyw + '"'); } } } } function kwhienabledisable(hlsetnum,enable){ if (enable == false) { // Update object and persist to GM storage hlobj[hlsetnum].enabled = "false"; hljson = JSON.stringify(hlobj); GM_setValue("kwstyles",hljson); // Unhighlight unhighlight(hlsetnum); // Clear seek info from bar if this set is there var seekset = document.getElementById("thdtopfindbuttons").getAttribute("thdseek"); if (seekset){ if(seekset.indexOf("|") > -1) seekset = seekset.split("|")[0]; if (hlsetnum == seekset){ document.getElementById("thdtopfindbuttons").setAttribute("thdseek",""); document.getElementById("thdseekdesc").textContent = "Seek"; document.getElementById("thdtopkeywords").innerHTML = "Click here to manage keyword/highlight sets"; } } } else { // Update object and persist to GM storage hlobj[hlsetnum].enabled = "true"; hljson = JSON.stringify(hlobj); GM_setValue("kwstyles",hljson); // Highlight THmo_doHighlight(document.body,[hlsetnum]); } } function kwhinewset(e,kwtext){ // call up new set form // set set number attribute document.querySelector('#kwhiedit tr').setAttribute('kwhiset', 'new'); // clear class for keywords document.querySelector('#kwhiedit td:nth-of-type(1) p:nth-of-type(1)').className = ""; // enter placeholder text & default type if (kwtext) document.querySelector('#kwhiedit td:nth-of-type(1) p:nth-of-type(1)').textContent = kwtext; else document.querySelector('#kwhiedit td:nth-of-type(1) p:nth-of-type(1)').textContent = "larry|moe|curly"; document.getElementById("kwhipattype").selectedIndex = 0; // set style editing to defaults kwhieditstyle = ["rgb(0,0,255)","rgb(255,255,0)","inherit",""]; kwhiShowEditForm(); } function kwhiShowEditForm(){ var rule = "#stylecontrols>p>span{"; if (kwhieditstyle[0].length > 0) rule += "color:"+kwhieditstyle[0]+";"; if (kwhieditstyle[1].length > 0) rule += "background-color:"+kwhieditstyle[1]+";"; if (kwhieditstyle[2].length > 0) rule += "font-weight:"+kwhieditstyle[2]+";"; if (kwhieditstyle[3].length > 0) rule += kwhieditstyle[3]+";"; document.getElementById("kwhiedittemp").innerHTML = rule + "}"; populateRGB("txt",kwhieditstyle[0]); populateRGB("bkg",kwhieditstyle[1]); document.getElementById("fwsel").value = kwhieditstyle[2]; document.getElementById("kwhicustom").value = kwhieditstyle[3]; // default the reversion button to disabled var rbtn = document.getElementById("btnkwhirevert"); rbtn.setAttribute('disabled','disabled'); if (rbtn.hasAttribute('kwhiset')) rbtn.removeAttribute('kwhiset'); rbtn.setAttribute('title',''); // show form document.getElementById("kwhiedit").style.display = "block"; // check for possible reversion option var hlset = document.querySelector('#kwhiedit td:nth-of-type(1) p:nth-of-type(1)').className; if (hlset != "" && hlobj[hlset].prevkeyw && hlobj[hlset].prevkeyw != '') { rbtn.removeAttribute('disabled'); rbtn.setAttribute('kwhiset',hlset); rbtn.setAttribute('title','Revert to "' + hlobj[hlset].prevkeyw + '"'); } } function kwhiexport(e){ prompt("JSON data\nPress Ctrl+c or right-click to copy\n ", JSON.stringify(hlobj)); } function kwhiimport(e){ var txtImport = prompt("Paste in the exported data and click OK to start parsing", ""); try{ var objImport = JSON.parse(txtImport); } catch(err){ alert("Sorry, data does not appear to be in the proper format. Here's the error according to Firefox: \n\n"+err+"\n\nHopefully you can resolve that!"); return; } var keysImport = Object.keys(objImport); // Compare for duplicate set numbers var keysString = "|" + hlkeys.join("|") + "|"; var counter = 0; for (var j = 0; j < keysImport.length; ++j){ if(keysString.indexOf("|"+keysImport[j]+"|") > -1) counter++; } if (counter > 0){ var arc = prompt("Detected "+counter+" of "+keysImport.length+" set numbers to be imported already exist. Do you want to:\nAdd these sets [A]\nReplace existing sets [R]\nTotally replace all existing sets [T]\nCancel the import [C]?","A"); if (!arc) return; if (arc.length == 0) return; if (arc.toLowerCase() == "c") return; if (arc.toLowerCase() == "t"){ if(!confirm("Total replacement has no error checking. Click OK to confirm total replacement, or click Cancel to only Replace matching sets.")) arc = "R"; } } else { var arc = "A"; } if (arc.toLowerCase() == "t"){ // Total replacement hlobj = JSON.parse(txtImport); // Update the global key array hlkeys = Object.keys(hlobj); // Persist the object hljson = JSON.stringify(hlobj); GM_setValue("kwstyles",hljson); // Apply to page (see below) } else { for (var j = 0; j < keysImport.length; ++j){ // Add/replace individual sets var impset = keysImport[j]; if(keysString.indexOf("|"+impset+"|") > -1 && arc.toLowerCase() == "r"){ // replace var hlset = impset; hlobj[hlset].keywords = objImport[impset].keywords || "keywords|not|found"; hlobj[hlset].type = objImport[impset].type || "string"; hlobj[hlset].hlpat = objImport[impset].hlpat || ""; hlobj[hlset].textcolor = objImport[impset].textcolor || "rgb(0,0,255)"; hlobj[hlset].backcolor = objImport[impset].backcolor || "rgb(255,255,0)"; hlobj[hlset].fontweight = objImport[impset].fontweight || "inherit"; hlobj[hlset].custom = objImport[impset].custom || ""; hlobj[hlset].enabled = objImport[impset].enabled || "true"; hlobj[hlset].visible = objImport[impset].visible || "true"; hlobj[hlset].updated = (new Date()).toJSON(); } else { // add if(keysString.indexOf("|"+impset+"|") > -1 && arc.toLowerCase() == "a"){ // create a new set number instead var hlset = "set" + hlnextset; hlnextset += 1; GM_setValue("hlnextset",hlnextset); } else { var hlset = impset; } // add the set hlobj[hlset] = { keywords : objImport[impset].keywords || "keywords|not|found", type: objImport[impset].type || "string", hlpat : objImport[impset].hlpat || "", textcolor : objImport[impset].textcolor || "rgb(0,0,255)", backcolor : objImport[impset].backcolor || "rgb(255,255,0)", fontweight : objImport[impset].fontweight || "inherit", custom : objImport[impset].custom || "", enabled : objImport[impset].enabled || "true", visible : objImport[impset].visible || "true", updated : objImport[impset].updated || "" } } // Update the global key array hlkeys = Object.keys(hlobj); // Persist the object hljson = JSON.stringify(hlobj); GM_setValue("kwstyles",hljson); } } // TODO: Could an error prevent reaching this point, for example, if the import object is missing properties due to bad editing? // Update CSS rule and command bar list insertCSS(hlkeys); refreshSetList(); // Unhighlight all, re-highlight all, close dialog unhighlight(null); THmo_doHighlight(document.body); } function kwhihbtn(e){ if (e.target.checked == false){ hlbtnvis = "off"; GM_setValue("hlbtnvis",hlbtnvis); document.getElementById("btnshowkwhi").style.display = "none"; } else { hlbtnvis = "on"; GM_setValue("hlbtnvis",hlbtnvis); document.getElementById("btnshowkwhi").style.display = ""; } } function kwhiprecode(e){ if (e.target.checked == false){ // Update var, persist the preference, unhighlight, rehighlight hlprecode = false; GM_setValue("hlprecode",hlprecode); unhighlight(null); THmo_doHighlight(document.body); } else { // Update var, persist the preference, rehighlight hlprecode = true; GM_setValue("hlprecode",hlprecode); THmo_doHighlight(document.body); } } function kwhicancelipe(setno){ // clean up in-place editor(s) if (setno && setno != ''){ var kwdiv = document.querySelector('#kwhitbod .'+setno); if (kwdiv){ kwdiv.innerHTML = hlobj[setno].keywords; return; } } else { // Check 'em all var divs = document.querySelector('#kwhitbod div'); for (var n=0; n