Simple Request

in Ideas and script requests
Subscribe to Simple Request 3 posts, 2 voices



boof User
FirefoxWindows

Could someone make a script so that when I click a link of this format:
"http://*****.com/tos.php?id=*****"

This: "&temporaryStatus=0"

is added to the end of the URL?

Thaaank yaa!

 
ekbworldwide Scriptwright
FirefoxWindows

stuff = document.getElementsByTagName("A");

for (var i = 0; i < stuff.length; i++) {
	stuff[i].href = stuff[i].href.replace(/^(http:\/\/[A-Za-z0-9\.]+\.com\/tos\.php\?id=.+?)$/, "$1&temporaryStatus=0");
}

I tested it with these:

<a href="http://example.com/tos.php?id=1">example 1</a>
<a href="http://www.example.com/tos.php?id=02">example 2</a>
<a href="http://www.example.com/tos.php?id=">example 3</a>
<a href="http://www.example.com.au/tos.php?id=04">example 4</a>

Note that
example 3 will not change since nothing comes after id=
example 4 will not change since it has example.com.au/ and not example.com/

It's probably best if you give links to example pages.

My code checks all the links on the page - and you probably only need to check parts of the page.

[A-Za-z0-9\.]+\.com is a very crude test since domain stuff in urls can be very tricky to figure out.

example.com
example.com.au
example.co.uk
example.jp
etc etc etc

Also - having examples helps to find problems and bugs. Without examples - I have no way of knowing if my code will actually work correctly.

__________________
edit

I just realized that my code fails on links that start with https

Do you want https links checked too?

 
boof User
FirefoxWindows

Thanks a lot! It's works perfectly. It does exactly what I needed it to. The only links that I needed the script were of the format I posted above. i.e. no https

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel