tags:

views:

63

answers:

1

Hi all,

I'm pretty new to jquery and greasemonkey. So if someone could help me out it would be great.

Here is an example url I get values from.

Org: http://www.example.com/index.php?value1=blabla1&sid=blabla2&mid=blabla3 Result I want: link://www.example.com/blabla1/data/blabla2/blabla3.ext

example: var sid=document.URL.substring(document.URL.indexOf('sid=')+15); // How do I set the lenght of blabla2 ? -7 ?

Anyway, Hopefully someone understand what I mean and can help me out alittle.

+1  A: 

Use regular-expression searches to get the values. If you know the param names in advance, it's more straightforward than it looks...

var searchableStr   = document.URL + '&';

var value1  = searchableStr.match (/[\?\&]value1=([^\&\#]+)[\&\#]/i) [1];
var sid     = searchableStr.match (/[\?\&]sid=([^\&\#]+)[\&\#]/i)    [1];
var mid     = searchableStr.match (/[\?\&]mid=([^\&\#]+)[\&\#]/i)    [1];

.
The last bit is then something like:

var domain  = searchableStr.match (/\/\/([w\.]*[^\/]+)/i) [1];

var newlink = '//' + domain + '/' + value1 + '/data/' + sid + '/' + mid + '.ext';  

.

 .

PS: It's only slightly more work if you don't know the names in advance.
PPS: This is educational code. Beware of extra spaces and malicious data, when using in the wild.

Brock Adams
Bulfen
You didn't ask about every link, you asked about document url. It's not good to change the question midstream. ;-)Anyway, for every link, you would grab them with an XPATH search or something like `document.getElementsByTagName ('a')`.But, you should open a new question for that, and post a link to the web page in question -- or at least include a paste of the exact link-code in question.Mark this question answered to increase the odds that the next one will be too.
Brock Adams
Sorry about that. :P Thank you very much for the help Brock. I'll figure it out with some reading and testing. ;)
Bulfen