tags:

views:

155

answers:

4

I want to increment a url automatically using javascript and use it in Greasemonky on "Firefox"

ex:

www.google.com/id=1
www.google.com/id=01
www.google.com/id=001
www.google.com/id=0001

how can I achieve that using javascript???

here is what I wrote


var numberr = “2”;
var totall = “”;
var timeout = 12000;

setTimeout(function() {
    var numm = “0” + numberr;
    totall = “http://www.google.com/id=0” + numm;
    window.location.href = totall;
}, timeout);


but i doesn't increment the zeros as i expected,

can anybody help me?

I don't know what is the problem, maybe it is the Greasemonkey?? I don't know

---------------------------------------------------------------

OK, It seems to be a javascript unfixable problem, So I'll implement the logic in a Windows application using C#, BUT I neet to know how to access [[firefox]] url , and reload action through C# in a windows application, can anybody help?????

A: 

What number are you coming up with? it looks like you are always going to be adding one more 0 than your description indicates since you are automatically adding one 0 with

var numm = “0” + numberr;
totall = “http://www.google.com/id=0” + numm;

by the look of those lines, even if you start out with "2", your first request will be

www.google.com/id=002

edit: and another thing, you are going to need to assign numm to numberrr at the end of the function call. Is this what you are trying to achieve?

var numberr = “2”;
var totall = “”;
var timeout = 12000;

setTimeout(function() {
var numm = “0” + numberr;
totall = “http://www.google.com/id=” + numm;
window.location.href = totall;
numberr = numm;
}, timeout);

edit again: ya, what Zed says, once you change your page location everything will reset anyways.

Mike_G
I did the last line "numberr = numm;"but nothing happenedI tryed that
A: 

try this:

var numberr = “2”;
var totall = “”;
var timeout = 12000;
var numm;
setTimeout(function() {
    numm += “0”;
    totall = “http://www.google.com/id=0” + numm + numberr;
    window.location.href = totall;
}, timeout);
Jason
since numm is a local variable, its always going to be null when the function is called right?
Mike_G
hm good call... fixed
Jason
ok its always going to be null, but I assign it at the beginning of the function "var numm = “0” + numberr;"see, It isn't supposed to be null, right?
A: 
var xcall = function()
{
 this.url = "http://www.google.com/id=";
 this.count = 0;
 this.numberr = '1';
 this.timeout = 12000;
};

xcall.prototype.ceros = function() {
 var ret = "";
 for(var x=0; x<this.count; x++){
  ret += "0";
 }
 this.count++;
 return ret;
};

xcall.prototype.sto = function() {
 var locat = this.url + this.ceros() + this.numberr;
 alert(locat);
 //window.location.href = this.url + this.ceros + this.numberr;
};

var calls = new xcall();

setTimeout("calls.sto()", calls.timeout);
setTimeout("calls.sto()", calls.timeout);
andres descalzo
I don't understand this code, "javascript is not my language", but I used it with Greasemonkey, but it didn't work at all, I don't know why?I'd appreciated if you try it on your browser "firefox" using greasemonkey
+1  A: 

Your variable values won't persist between page loads, thus resetting the counter each time. There is a solution, however!

GM_setValue(key, value);
GM_getValue(key[, defaultValue]);

http://diveintogreasemonkey.org/advanced/gm_getvalue.html

Alternatively, you can parse the current URL to determine your location within the loop. Try this:

// ==UserScript==
// @name           Incremental URL
// @include        http://www.google.com/*
// ==/UserScript==

var url = 'http://www.google.com/id=',
    start = '2',
    prepend = '0',
    limit = 10,
    timeout = 1000*12,

    regex = new RegExp('^' + url + '(' + prepend + '{0,' + (limit-1) + '})' + start + '$');
    matches = window.location.href.match(regex);


if(matches) {
    setTimeout(function() {
     window.location.href = url + prepend + matches[1] + start;
    }, timeout);
}
Kevin
I tryed this code, but it didn't work at all, nothing happened,BUT I want to try the [GM_setValue, GM_getValue] but how can I put them in my code?i am not a javascript expert!
It's DONE, I tryed the GM_setValue and GM_getValue, it works,thanks a lot
Andrew, for the userscript above, you'll need to go to http://www.google.com/id=2 to start the loop. I'm glad you got the GM_set/getValue working.
Kevin