如何在每个特定间隔“Javascript”中用零递增 url?

发布于 2024-07-29 19:21:09 字数 793 浏览 2 评论 0原文

我想使用 javascript 自动增加一个 url,并在“Firefox”上的 Greasemonky 中使用它

,例如:

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

如何使用 javascript 实现这一点???

这是我写的


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);

,但我没有按预期增加零,

有人可以帮助我吗?

我不知道是什么问题,也许是油猴的问题? 我不知道

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

好的,这似乎是一个 javascript 无法修复的问题,所以我将使用 C# 在 Windows 应用程序中实现逻辑,但我需要知道如何访问 [[firefox]] url ,并在 Windows 应用程序中通过 C# 重新加载操作,有人可以帮忙吗???

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?????

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

深海少女心 2024-08-05 19:21:09

您的变量值不会在页面加载之间持续存在,因此每次都会重置计数器。 不过,有一个解决方案!

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

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

或者,您可以解析当前用于确定您在循环中的位置的 URL。 尝试这个:

// ==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);
}

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);
}
忘东忘西忘不掉你 2024-08-05 19:21:09

你想出什么数字? 看起来您总是会比您的描述指示多添加一个 0,因为根据

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

这些行的外观,您会自动添加一个 0,即使您从“2”开始,您的第一个请求也将被

www.google.com/id=002

编辑:并且另一件事,您需要在函数调用结束时将 numm 分配给 numberrr 。 这是您想要实现的目标吗?

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);

再次编辑:是的,Zed 所说的,一旦您更改页面位置,一切都会重置。

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.

起风了 2024-08-05 19:21:09

尝试这个:

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);

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);
情愿 2024-08-05 19:21:09
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);
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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文