Script request: Rewrite all links

Subscribe to Script request: Rewrite all links 17 posts, 3 voices

 
raven69 User

Can some body please write this script for me , i tryed but it kept on bombing out...

the script should do the following...

if the format is .gif,.mp3.php.html.png.jpg etc ... the script mus add ?vaultx.co.za at the end

eg:
domain.com/logo.gif to domain.com/logo.gif?vaultx.co.za

2:

if the site has sum excess coding
eg:
domain.com/index.php?act=home the script should do this domain.com/index.php?act=home&sd=vaultx.co.za

...

Thanx to anyone who helps me :)

 
Gabe Gorelick Scriptwright

Something like this should work:


// ==UserScript==
// @name         URL Appender
// @description  appends ?vaultx.co.za to the end of certain URLs
// @include      http://domain.com*
// ==/UserScript==

var url = window.location.href;

//the ?vault.co.za conditional makes sure that the script only appends it once, otherwise, it continues running 
//and reloading the page with another ?vaultx.co.za

if(url.indexOf("?vaultx.co.za") == -1 && (url.indexOf(".gif") != -1 
						|| url.indexOf(".php") != -1)) //add more formats ad nauseam
{
	window.location.href += "?vaultx.co.za";
	
}

You may also want to try this using location.replace(url) instead

 
raven69 User

Thanx bro i will try it and get back tp you..:)

 
raven69 User

This script only rewrite links in the adress bar i need it to rewrite all the links on the page :)

 
OptoGeek User

Just modifying Gabe's code here. Javascript has built-in arrays for various objects. I believe links are one of them, so you should be able to loop through all the links on any given page and modify them... [the code I initially posted here was all wrong, refer below]

 
OptoGeek User

The code below should do exactly what you requested in your post, although it seems kind of odd to me that you want to append ?vaultx.co.ca to the end of a URL. That's not a correct querystring. You have the right idea with the &sd= for appending to a preexisting string. Perhaps you meant you want to append ?sd=vaultx.co.ca ... if that is what you intended, you can modify my code below to say "?sd=" rather than just "?" on line 15.


// ==UserScript==
// @name         URL Appender
// @description  appends ?vaultx.co.za to the end of certain URLs
// @include      http://domain.com*
// ==/UserScript==

var url;

for (var i=0; i<document.links.length; i++) {
	url = window.document.links[i];

	if((url.pathname.indexOf(".gif") != -1 || url.pathname.indexOf(".php") != -1)) 
	{
		if (url.href.indexOf("?") == -1) {
			window.document.links[i].href += "?";
		}
		else {
			window.document.links[i].href += "&sd=";
		}
		window.document.links[i].href += "vaultx.co.za";
	}

}

 
OptoGeek User

Also, be sure to modify the line that specifies the file extensions you want to apply it to. This is easy if there aren't many. But, if you like, I can modify the code so that there's a single variable at the top that you can modify to simply list out all the extensions you want (for example: var exts = "php,gif,png,foo";) But of course, that will require a bit more code under the hood.

 
OptoGeek User

Ok, so I decided to do it for you anyway even though you didn't ask. It's below, but I still didn't make any modifications to what you wanted appended (the whole "?" versus "?sd=" thing I mentioned above.


// ==UserScript==
// @name         URL Appender
// @description  appends ?vaultx.co.za to the end of certain URLs
// @include      http://domain.com*
// ==/UserScript==

var url;
var exts = new Array(".gif",".mp3",".php",".html",".png",".jpg");

for (var i=0; i<document.links.length; i++) {
	url = window.document.links[i];

	for (var j=0; j<exts.length; j++) {
		if(url.pathname.indexOf(exts[j]) != -1) 
		{
			if (url.href.indexOf("?") == -1) {
				window.document.links[i].href += "?";
			}
			else {
				window.document.links[i].href += "&sd=";
			}
			window.document.links[i].href += "vaultx.co.za";
		}
	}
}

 
raven69 User

Thanx man i will try it now giev me 5min :)

 
raven69 User

thanks it rights the links jus the css styles and images still dnt get rewritten///

 
raven69 User

and yes i did all the extensions to that list you gave me..

 
OptoGeek User

Perhaps I'm not understanding what you want it to do exactly. The way I understood it was that you want it to rewrite all the hyperlinks on a given page. Is that not correct? Or did you also want to append that string to any URL contained within the source code of the document? (ie., CSS includes, javascript includes, img source elements, etc.) Please try to clarify exactly what you were looking for.

 
raven69 User

i Need to append it to everythng in the soucre eg..css,images etc..

 
OptoGeek User

So what you're saying is you want it to attach to the end of any URL that appears anywhere in the document no matter what it points at or what sort of object it's a part of? Is that correct? I'm really curious as to what the ultimate goal of this is?

 
raven69 User

wana use it as a admin mod on my site will change vaultx.co.za to sumthn else ..i want it to work on my site only..il show you wat i wana do with it...can you do it fo me please..

 
OptoGeek User

I'll try to get to it sometime this weekend -- sorry, it's been a busy couple of days for me.

 
raven69 User

its ok man ou can do it wen ever you can :)