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.
url surrogate
Re: url surrogate
You could still adapt that surrogate, but instead of
use
Haven't tested it myself, so no guarantees.
Code: Select all
a.href.replace(/.*\/url.*[?&](?:url|q)=(http[^&]+).*/,function(a,b)decodeURIComponent(b));
Code: Select all
a.href.replace(/$/, '?ModPagespeed=noscript');
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:22.0) Gecko/20100101 Firefox/22.0
-
uriadder
Re: url surrogate
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?
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