Direct to 'view as plain text'

Subscribe to Direct to 'view as plain text' 5 posts, 3 voices

 
theaulddubliner Scriptwright

Hi guys

I'm trying to write a script to redirect the 'view source' on script pages directly to the plain text version [which I use most] ideally then with a link to the formatted version -- kind of like a reverse of the current process.

Unfortunately I'm just not getting the regex anywhere near correct - the 4 digit variable in the middle of the url is confusing me -- rather than at the end.

Almost embarrassed asking for what to many here will be a simple 'off-the-top-of-the-head' script :)

Also can anyone recommend a good beginner's guide to regex ?

 
Descriptor Scriptwright

Well, regex is "greedy", which makes it a little hard to match the end of a string, or anywhere in the middle for that matter.

But really, why use regex?

var viewScriptLink = document.evaluate("//a[contains(@href,'review')]", document, null, 9, null).singleNodeValue;
if(viewScriptLink.href.indexOf("?") == -1){
  viewScriptLink.href += "?format=txt";
}

 
Descriptor Scriptwright

BTW: you might find some good reading by searching for "Perl regex" or Regular Expressions, not exactly the same but very close and how I learned it, also I have a few books on Perl.

 
theaulddubliner Scriptwright

thanks for that descriptor

i've got a hell of a lot to learn ....

 
vOidSenses Scriptwright

i don't understand why use regex either, Descriptor already gave you a better solution, anyway, maybe this will help:
https://addons.mozilla.org/en-US/firefox/addon/...
http://www.cuneytyilmaz.com/prog/jrx/