Text Hilite

Highlights matched text on page

  1. // ==UserScript==
  2. // @name Text Hilite
  3. // @namespace muroph
  4. // @description Highlights matched text on page
  5. // @include *
  6. // @version 1
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. //----CONFIGURATION EXAMPLE
  11. // Each rule must use the following blocks:
  12. //
  13. //AD.push(/<regex1>/i); //regex matching the URL of the page(s) for this rule
  14. //MA.push(/(<regex2>)/i); //regex matching the desired text. round brackets are mandatory
  15. //ST.push('<style>'); //style to use on the matched text
  16. //
  17. // You can use multiple rules
  18.  
  19. var AD=new Array();var MA=new Array();var ST=new Array();
  20.  
  21. //----RULES LIST
  22. AD.push(/^https?:\/\/greasyfork\.org.*$/i); //regex to match a site
  23. MA.push(/(script)/i); //regex to find some text
  24. ST.push('color: #fff;background: #f00;font-weight: bold;'); //style applied to text
  25.  
  26. AD.push(/^https?:\/\/greasyfork\.org.*$/i);
  27. MA.push(/(user)/i);
  28. ST.push('color: #9ff;background: #00f;text-decoration: underline;');
  29.  
  30. //------------------------
  31. for(ind in AD){
  32. if(AD[ind].test(window.location.href)==true){
  33. for(var tx=document.evaluate('//text()[normalize-space(.)!=""]',document,null,6,null),t,i=0;t=tx.snapshotItem(i);i++){
  34. var before=t.textContent,st,matched=false;
  35. if(t.parentNode.tagName=='STYLE'||t.parentNode.tagName=='SCRIPT') continue;
  36. while((st=before.search(MA[ind]))!=-1){
  37. t.parentNode.insertBefore(document.createTextNode(before.substr(0,st)),t);
  38. with(t.parentNode.insertBefore(document.createElement('span'),t))
  39. textContent=RegExp.$1,
  40. style.cssText=ST[ind];
  41. matched=true;
  42. before=before.substr(st+RegExp.$1.length);
  43. }
  44. if(matched) t.textContent=before;
  45. }
  46. }
  47. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址