Old and deprecated method:
You must add listener on mutation event to target window or element
which will slow browser performance.
http://www.w3.org/TR/DOM-Level-3-Events/#events-mutationevents

// ==UserScript==
// @name           nobble
// @namespace      http://news.bbc.co.uk/weather/forecast/346
// @include        http://news.bbc.co.uk/weather/forecast/*
// ==/UserScript==

var div = document.getElementById("Forecast_main");
div.addEventListener("DOMNodeInserted", function() {
  var textNodes = document.evaluate( "//text()", document, null,
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
  var searchRE = new RegExp('mb','g');// I know doesn't need regexp for this
  var replace = 'MB';
  for (var i=0;i<textNodes.snapshotLength;i++) {
    var node = textNodes.snapshotItem(i);
    node.data = node.data.replace(searchRE, replace);
  }
}, false);


Newer and better method(s):
http://www.w3.org/2008/webapps/wiki/MutationReplacement



On Fri, Aug 5, 2011 at 15:42, SA <[email protected]> wrote:
> I have a simple script to search and replace stuff on the web - as a
> trivial example here:
>
> // ==UserScript==
> // @name           nobble
> // @namespace      http://news.bbc.co.uk/weather/forecast/346
> // @include        *
> // ==/UserScript==
> textNodes = document.evaluate( "//text()", document, null,
> XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
> var searchRE = new RegExp('mb','g');// I know doesn't need regexp for
> this
> var replace = 'MB';
> for (var i=0;i<textNodes.snapshotLength;i++){
>        var node = textNodes.snapshotItem(i);
>        node.data = node.data.replace(searchRE, replace);
>        }
>
> On the bbc weather forecast this works fine initially:
> http://news.bbc.co.uk/weather/forecast/4168
> but if the 24hour forecast button is pressed the resulting webpage is
> unaffected.
>
> Any ideas?
>
> --
> You received this message because you are subscribed to the Google Groups 
> "greasemonkey-users" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/greasemonkey-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"greasemonkey-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/greasemonkey-users?hl=en.

Reply via email to