url surrogate

Ask for help about NoScript, no registration needed to post
uriadder

url surrogate

Post by uriadder »

I'd like to automatically add a parameter to the links of a certain website by using the surrogate feature.

Example:
Clicking an internal link of a wordpress blog it always redirects from http://www.example.net/blogentry/ to http://www.example.net/blogentry/?ModPagespeed=noscript

To avoid annoying redirections, how do I write a surrogate to add that "?ModPagespeed=noscript" parameter to the url links of that specific site?
I was looking into the "noscript.surrogate.glinks.replacement" surrogate trying to understand how it works. But unfortunately that one removes parts of the url rather than adding stuff, so it wasn't of great help.
Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20100101 Firefox/17.0
User avatar
Thrawn
Master Bug Buster
Posts: 3106
Joined: Mon Jan 16, 2012 3:46 am
Location: Australia
Contact:

Re: url surrogate

Post by Thrawn »

You could still adapt that surrogate, but instead of

Code: Select all

a.href.replace(/.*\/url.*[?&](?:url|q)=(http[^&]+).*/,function(a,b)decodeURIComponent(b));
use

Code: Select all

a.href.replace(/$/, '?ModPagespeed=noscript');
Haven't tested it myself, so no guarantees.
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0
uriadder

Re: url surrogate

Post by uriadder »

It does indeed work, thank you!

However, I just realized that "noscript.surrogate.example.sources" actually defines the domain the replacement is working on - in contrast to what I hoped for the linked url itself - which means that every link on example.net gets passed that parameter, even external ones. Unfortunately I have zero experience in JavaScript, but do you know how to exclude the surrogate if the link is not example.net?
Also the parameter doesn't work on links with a hash tag: example.net/blogentry/#comments How would you prevent a surrogate here? Or alternatively how to replace the hash tag with the parameter?

Is it possible to also define globally valid url surrogates by specifying placeholder sources like "noscript.surrogate.example.sources;*" or "noscript.surrogate.example.sources;!@^https?://[^/]+*\..*/" or similar?
Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20100101 Firefox/17.0
Post Reply