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

Pages: (2): « First [ 1 ] 2 » Last »
Greasemonkey message box / redirect
Author: Message:
Jimbo
Veteran Member
*****

Avatar

Posts: 1650
Reputation: 18
32 / Male / Flag
Joined: Jul 2006
O.P. Greasemonkey message box / redirect
Is there a way to look for a word on a page using Greasemonkey, and if that word appears anywhere on the page, either display a message box, that the user has to click OK, or just redirect to another page instantly?
01-16-2010 11:14 PM
Profile E-Mail PM Find Quote Report
andrey
elite shoutboxer
****

Avatar

Posts: 795
Reputation: 48
– / Male / Flag
Joined: Aug 2004
RE: Greasemonkey message box / redirect
how about
JS code:
if (/someword/m.test(document.body.innerText)) alert("OMFG")
but that would include any other inline stuff in the source (js in <script> tags, css etc)
[Image: w2kzw8qp-sq2_dz_b_xmas.png]
01-17-2010 12:21 AM
Profile PM Find Quote Report
Jimbo
Veteran Member
*****

Avatar

Posts: 1650
Reputation: 18
32 / 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?

js 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
stoshrocket
Senior Member
****

Avatar
formerly methos

Posts: 748
Reputation: 31
34 / Male / Flag
Joined: Aug 2005
RE: Greasemonkey message box / redirect
To prevent alert spamming you could just build in a variable in place of the alert that is changed to 1 when a word is found, then after the search has been made, check the variable, if = 1, alert...

js code:
    // ==UserScript==
    // @name          Alert
    // @namespace     http://sammyservers.com
    // @description   Alert
    // @include   *
     
    // ==/UserScript==
     
    (function() {
     
    const WORD = {
      "test": {"color": "red"},
    };
   
    //build in the global variable...
    var j = 0;
     
    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];
              //changes the global variable to 1
              j = 1;         
            }
          }
        }
      }
    }
      highlightText();
      if(j = 1){
        alert("test");
      }
    })();

I'm, not too strong on the javascript front so the code might not be solid, but in theory it should work!

As for searching the word outside of the source I have no clue...
formerly methos
01-17-2010 11:44 AM
Profile PM Web Find Quote Report
Jimbo
Veteran Member
*****

Avatar

Posts: 1650
Reputation: 18
32 / Male / Flag
Joined: Jul 2006
O.P. RE: Greasemonkey message box / redirect
Oh yeah, don't know why I didnt think of doing that. Thanks a lot.

IF anyone has any suggestions on how to search for the word outside of the page source, I would be highly grateful.
01-17-2010 01:38 PM
Profile E-Mail PM Find Quote Report
stoshrocket
Senior Member
****

Avatar
formerly methos

Posts: 748
Reputation: 31
34 / Male / Flag
Joined: Aug 2005
RE: Greasemonkey message box / redirect
quote:
Originally posted by Jimbo
Oh yeah, don't know why I didnt think of doing that. Thanks a lot.

IF anyone has any suggestions on how to search for the word outside of the page source, I would be highly grateful.
I don't actually get what you're trying to do tbh, I understand about looking for a word in a page source, but when would you find, or even look, for a word outside of that? Example of where you're trying to find the word?
formerly methos
01-17-2010 03:52 PM
Profile PM Web Find Quote Report
Jimbo
Veteran Member
*****

Avatar

Posts: 1650
Reputation: 18
32 / Male / Flag
Joined: Jul 2006
O.P. RE: Greasemonkey message box / redirect
Well, this is for a friend of mine, and its for a game called Pokemon battle arena. He wants it to alert him when the word "shiny" is found in the page, but since this isnt hardcoded, and the URL has a random set of arguments for each pokemon encounter, I was wondering if there would be a way to scan the page body, even if the word wasnt in the source.
01-17-2010 04:46 PM
Profile E-Mail PM Find Quote Report
stoshrocket
Senior Member
****

Avatar
formerly methos

Posts: 748
Reputation: 31
34 / Male / Flag
Joined: Aug 2005
RE: Greasemonkey message box / redirect
quote:
Originally posted by Jimbo
Well, this is for a friend of mine, and its for a game called Pokemon battle arena. He wants it to alert him when the word "shiny" is found in the page, but since this isnt hardcoded, and the URL has a random set of arguments for each pokemon encounter, I was wondering if there would be a way to scan the page body, even if the word wasnt in the source.
Ah, I've just taken a look at the game. I see what you mean about it not actually being in the source, but I can see where the text is meant to appear in the source, it's just been hidden. Hmm... I'm not too sure at the moment, if I think of a method I'll let you know.
formerly methos
01-17-2010 05:23 PM
Profile PM Web Find Quote Report
Jimbo
Veteran Member
*****

Avatar

Posts: 1650
Reputation: 18
32 / Male / Flag
Joined: Jul 2006
O.P. RE: RE: Greasemonkey message box / redirect
quote:
Originally posted by stoshrocket
quote:
Originally posted by Jimbo
Well, this is for a friend of mine, and its for a game called Pokemon battle arena. He wants it to alert him when the word "shiny" is found in the page, but since this isnt hardcoded, and the URL has a random set of arguments for each pokemon encounter, I was wondering if there would be a way to scan the page body, even if the word wasnt in the source.
Ah, I've just taken a look at the game. I see what you mean about it not actually being in the source, but I can see where the text is meant to appear in the source, it's just been hidden. Hmm... I'm not too sure at the moment, if I think of a method I'll let you know.
Okay then, thank you very much.
01-17-2010 05:40 PM
Profile E-Mail PM Find Quote Report
andrey
elite shoutboxer
****

Avatar

Posts: 795
Reputation: 48
– / Male / Flag
Joined: Aug 2004
RE: Greasemonkey message box / redirect
just to make sure i'm getting this right, this is where the "shiny whatever" will appear?
[Image: attachment.php?pid=985063]

.png File Attachment: Screenshot.png (13.49 KB)
This file has been downloaded 1760 time(s).
[Image: w2kzw8qp-sq2_dz_b_xmas.png]
01-17-2010 06:42 PM
Profile PM Find Quote Report
Pages: (2): « First [ 1 ] 2 » Last »
« Next Oldest Return to Top Next Newest »


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