Advertisement
TwisterMc

Twitter Keyword Highlight for Fluid

Mar 4th, 2013
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Highlight
  3. // @namespace   http://fluidapp.com
  4. // @description What does this do?
  5. // @include     *
  6. // @author      Someone
  7. // ==/UserScript==
  8.  
  9. (function () {
  10.     if (window.fluid) {
  11.         setInterval(function () {
  12.         highlightWord(document.body,'WordPress');
  13.         highlightWord(document.body,'Minnesota');
  14.         highlightWord(document.body,'Mac');
  15.         highlightWord(document.body,'free');
  16.         highlightWord(document.body,'Free');
  17.         highlightWord(document.body,'Apple');
  18.        
  19.         function highlightWord(root,word){
  20.           textNodesUnder(root).forEach(highlightWords);
  21.        
  22.           function textNodesUnder(root){
  23.             var walk=document.createTreeWalker(root,NodeFilter.SHOW_TEXT,null,false),
  24.                 text=[], node;
  25.             while(node=walk.nextNode()) text.push(node);
  26.             return text;
  27.           }
  28.            
  29.           function highlightWords(n){
  30.             for (var i; (i=n.nodeValue.indexOf(word,i)) > -1; n=after){
  31.               var after = n.splitText(i+word.length);
  32.               var highlighted = n.splitText(i);
  33.               var span = document.createElement('span');
  34.               span.className = 'highlighted';
  35.               span.appendChild(highlighted);
  36.               after.parentNode.insertBefore(span,after);
  37.             }
  38.           }
  39.         }
  40.     }, 10000)
  41.  
  42.     }
  43. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement