Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Highlight Words
- // @author bpm
- // @version 1.1
- // @description Highlights works from an array
- // @include https://*
- // @include http://*
- // ==/UserScript==
- // 1.1 Updated by Frenzie, added easy to configure wordlist
- (function () {
- var wordlist=[
- /*@Wordlist (quote properly and use commas between values)@string@*/
- "and",
- "und",
- "or",
- "oder",
- /*@*/
- ];
- // other config
- var highlightBgColor = /*@Highlight background color@string@*/'blue'/*@*/;
- var highlightColor = /*@Highlight font color@string@*/'yellow'/*@*/;
- function hilite(text){
- var count=0,dv;
- dv=document.defaultView;
- function searchWithinNode(node,te,len){
- var pos,skip,spannode,middlebit,endbit,middleclone;
- skip=0;
- if(node.nodeType==3){
- pos=node.data.toUpperCase().indexOf(te);
- if(pos>=0){
- spannode=document.createElement('SPAN');
- spannode.style.backgroundColor=highlightBgColor;
- spannode.style.color=highlightColor;
- spannode.style.fontWeight='bold';
- middlebit=node.splitText(pos);
- endbit=middlebit.splitText(len);
- middleclone=middlebit.cloneNode(true);
- spannode.appendChild(middleclone);
- middlebit.parentNode.replaceChild(spannode,middlebit);
- ++count;
- skip=1;
- }
- }
- else if(node.nodeType==1&& node.childNodes && node.tagName.toUpperCase()!='SCRIPT' && node.tagName.toUpperCase!='STYLE'){
- for (var child=0;child<node.childNodes.length;++child){
- child=child+searchWithinNode(node.childNodes[child],te,len);
- }
- }
- return skip;
- }
- searchWithinNode(document.body,text.toUpperCase(),text.length);
- }
- document.addEventListener('DOMContentLoaded',function() {
- for (i=0; i<wordlist.length; i++) {
- hilite(wordlist[i]);
- }
- }, false);
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement