What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » Greasemonkey message box / redirect

Greasemonkey message box / redirect
Author: Message:
Jimbo
Veteran Member
*****

Avatar

Posts: 1650
Reputation: 18
31 / Male / Flag
Joined: Jul 2006
O.P. RE: Greasemonkey message box / redirect
Well, I've managed to come up with this, although it spams the alert for every instance of the word. How could I make it only alert once?

Javascript code:
    // ==UserScript==
    // @name          Alert
    // @namespace    --
    // @description   Alert
    // @include   *
     
    // ==/UserScript==
     
    (function() {
     
    const WORD = {
      "test": {"color": "red"},
    };
     
    function highlightText() {
     
      var allTextNodes = document.evaluate('//text()', document, null,
                                           XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
                                           null);
     
      for (var i = 0; i < allTextNodes.snapshotLength; i++) {
        var ele = allTextNodes.snapshotItem(i);
        for (var key in WORD) {
       
          if (ele.nodeValue.toLowerCase().indexOf(key) != -1) {
            var span = document.createElement("span");
            ele.parentNode.replaceChild(span, ele);
            span.appendChild(ele);
       
            for (var css in WORD[key]) {
              span.style[css] = WORD[key][css];
              alert("test");
         
            }
          }
        }
      }
    }
     
      highlightText();
    })();

Also, what if the word wasnt actually hardcoded into the page source, but retrieved from a session, or something, how could I detect the word then?

This post was edited on 03-23-2011 at 06:17 PM by Jimbo.
01-17-2010 12:52 AM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
Greasemonkey message box / redirect - by Jimbo on 01-16-2010 at 11:14 PM
RE: Greasemonkey message box / redirect - by andrey on 01-17-2010 at 12:21 AM
RE: Greasemonkey message box / redirect - by Jimbo on 01-17-2010 at 12:52 AM
RE: Greasemonkey message box / redirect - by stoshrocket on 01-17-2010 at 11:44 AM
RE: Greasemonkey message box / redirect - by Jimbo on 01-17-2010 at 01:38 PM
RE: Greasemonkey message box / redirect - by stoshrocket on 01-17-2010 at 03:52 PM
RE: Greasemonkey message box / redirect - by Jimbo on 01-17-2010 at 04:46 PM
RE: Greasemonkey message box / redirect - by stoshrocket on 01-17-2010 at 05:23 PM
RE: RE: Greasemonkey message box / redirect - by Jimbo on 01-17-2010 at 05:40 PM
RE: Greasemonkey message box / redirect - by andrey on 01-17-2010 at 06:42 PM
RE: Greasemonkey message box / redirect - by Jimbo on 01-17-2010 at 07:02 PM
RE: Greasemonkey message box / redirect - by kezz on 01-17-2010 at 10:01 PM
RE: Greasemonkey message box / redirect - by Jimbo on 01-17-2010 at 10:08 PM
RE: Greasemonkey message box / redirect - by andrey on 01-17-2010 at 11:32 PM
RE: Greasemonkey message box / redirect - by Jimbo on 01-18-2010 at 12:10 AM
RE: Greasemonkey message box / redirect - by andrey on 01-18-2010 at 12:29 AM
RE: Greasemonkey message box / redirect - by Jimbo on 01-18-2010 at 12:49 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On