I’m looking for a way to create an automatic forwarder (web-browser userscript) if a specific piece of HTML source code matches.
The code <span class="redux">$STRING</span> should be searched and if this span class is found and the $STRING part matches a certain value the redirect has to be sent.
Unfortunately I’m very bad at web-based scripting, which is why I’m asking here.
An exact HTML snippet I’m looking for would be <span class="tit">mash</span>.
Other answers have espoused jQuery, which is no bad thing. If for any reason you want to do this natively, here’s two approaches (one if you need to support older browsers, one using newer JS).
Method 1 (works in older browsers)
Method 2 (newer browsers)
One advantage of the latter is it uses the newer DOMContentLoaded event, which is preferable in this case (whereas onload waits for images and other assets to load before firing).
[EDIT – as Brock points out,
location.replace()overwrites the history entry for the current page. With some redirects (most?) this is what you want, but not necessarily. If not, uselocation.href = ...instead.]