为什么 dojo.xhrGet 需要不同类型的 url 才能在不同的计算机(pc/mac)上工作?

发布于 2024-10-12 08:28:23 字数 1823 浏览 2 评论 0原文

我正在为别人写一个greatmonkey 脚本。他是主持人,而我不是。剧本会帮助他做一些主持的事情。

现在这个脚本对我有用。只要它对我有用。(因为我不是mod) 但即使那些对我有用的东西对他也不起作用..

我检查了他的greasemonkey插件和firefox版本,他是最新的。 唯一真正不同的是我使用的是 Mac,而他使用的是 PC,但我认为这不会有任何问题。

这是对他不起作用的功能之一。他确实收到了第一条和第三条 GM_log 消息。但不是第二个(“有一些(1)..”)。

kmmh.trackNames = function(){
GM_log("starting to get names from the first "+kmmh.topAmount+" page(s) from leaderboard.");
kmmh.leaderboardlist = [];
for (var p=1; p<=(kmmh.topAmount); p++){
    var page = "http://www.somegamesite.com/leaderboard?page="+ p;  
    var boardHTML = "";
    dojo.xhrGet({
        url: page,
        sync: true,
        load: function(response){   
            boardHTML = response;
            GM_log("got some (1) => "+boardHTML.length);
        },
        handleAs: "text"
    });

    GM_log("got some (2) => "+boardHTML.length);

    //create dummy div and place leaderboard html in there
    var dummy = dojo.create('div', {    innerHTML: boardHTML    });
//search through it
    var searchN = dojo.query('.notcurrent', dummy).forEach(function(node,index){
        if(index >= 10){
            kmmh.leaderboardlist.push(node.textContent);    // add names to array
        }
    });
}
GM_log("all names from "+ kmmh.topAmount +" page(s) of leaderboard ==> "+ kmmh.leaderboardlist);

有谁知道这可能是什么原因造成的?

编辑:我知道我必须根据他在模组屏幕上看到的内容来写。所以我让他复制粘贴页面源等等。除此之外,这部分脚本并不取决于是否是 mod。

我让其他一切都为他工作。只是这个功能在他的两台电脑上仍然没有。

EDIT2(改变问题):好的。所以经过更多的尝试和错误后,我让它工作了,但它仍然很奇怪。 当我删除 dojo.xhrGet() 中使用的 url 的 www 部分时,我最终得到了与他得到的相同的错误。所以我让他将 www 添加到他的中,现在它可以工作了。 奇怪的是,他现在使用的脚本的网址包含“www”,而我使用的脚本的网址不包含“www”......

所以对我来说: var page = "http://somegamesite.com/leaderboard?page="+ p; 对他来说: var page = "http://www.somegamesite.com/leaderboard?page="+ p;

i'm writing an greasemonkey script for somebody else. he is a moderator and i am not. and the script will help him do some moderating things.

now the script works for me. as far as it can work for me.(as i am not a mod)
but even those things that work for me are not working for him..

i checked his version of greasemonkey plugin and firefox and he is up to date.
only thing that's really different is that i'm on a mac and he is pc, but i wouldn't think that would be any problem.

this is one of the functions that is not working for him. he does gets the first and third GM_log message. but not the second one ("got some(1) ..").

kmmh.trackNames = function(){
GM_log("starting to get names from the first "+kmmh.topAmount+" page(s) from leaderboard.");
kmmh.leaderboardlist = [];
for (var p=1; p<=(kmmh.topAmount); p++){
    var page = "http://www.somegamesite.com/leaderboard?page="+ p;  
    var boardHTML = "";
    dojo.xhrGet({
        url: page,
        sync: true,
        load: function(response){   
            boardHTML = response;
            GM_log("got some (1) => "+boardHTML.length);
        },
        handleAs: "text"
    });

    GM_log("got some (2) => "+boardHTML.length);

    //create dummy div and place leaderboard html in there
    var dummy = dojo.create('div', {    innerHTML: boardHTML    });
//search through it
    var searchN = dojo.query('.notcurrent', dummy).forEach(function(node,index){
        if(index >= 10){
            kmmh.leaderboardlist.push(node.textContent);    // add names to array
        }
    });
}
GM_log("all names from "+ kmmh.topAmount +" page(s) of leaderboard ==> "+ kmmh.leaderboardlist);

does anyone have any idea what could be causing this ??

EDIT: i know i had to write according to what he would see on his mod screen. so i asked him to copy paste source of pages and so on. and besides that, this part of the script is not depending on being a mod or not.

i got everything else working for him. just this function still doesn't on neither of his pc's.

EDIT2 (changed question): OK. so after some more trial and error, i got it to work, but it's still weird.
when i removed the www-part of the url thats being use in the dojo.xhrGet() i got the finally the same error he got. so i had him add www to his and now it works.
the odd thing is he now uses a script with the url containing "www" and i'm using a script with an url without "www"...

so for me:
var page = "http://somegamesite.com/leaderboard?page="+ p;
and for him:
var page = "http://www.somegamesite.com/leaderboard?page="+ p;

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

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

发布评论

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

评论(2

稳稳的幸福 2024-10-19 08:28:23

为什么不让他尝试登录一个不是主持人帐户的帐户,以便从问题空间中消除变量之一。

版主的页面 DOM 可能与普通用户的页面 DOM 不同。如果您作为普通用户对页面做出的假设与主持人的身份不符,则可能会导致问题。

我怀疑要修复它,您可能需要访问主持人帐户,以便您可以更轻松地复制该行为。

Why don't you have him try logging into an account that is not a moderator account so that you eliminate one of your variables from your problem space.

It's possible that the DOM of the page is different for a moderator than for a regular user. If you're making assumptions about the page as a regular user that are not true as a moderator, that could cause problems.

I suspect that to fix it, you may need access to a moderator account so you can more easily replicate the behavior.

聊慰 2024-10-19 08:28:23

哎呀。该游戏网站的 URL 似乎可以通过 www.gamesite.com 和 gamesite.com 访问(不带 www. 部分)。这导致了问题。

很抱歉打扰大家。

我现在羞愧地躲起来……

ooops. it seemed that the url of this gamesite is accessible as www.gamesite.com as well as gamesite.com (without the www.part). this caused the problem.

sorry to bother you'all.

i go hide in shame now...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文