1

GM_xmlhttpReqeustGreasemonkey スクリプトで次のように関数をセットアップしています (簡易版)。

  GM_xmlhttpRequest({
    synchronous: false,
    method: "HEAD",
    url: "http://www.example1.com",
    onload: function(response){console.debug(url);},
  });
  • GM_xmlhttpReqeust私のコードでは非同期モードで呼び出されます。

  • アクセスするとhttp://www.example1.com302 リダイレクトが行われますhttp://www.example2.com

  • コールバック関数内の元のurlパラメータ ( )の値にアクセスしたいと思います。http://www.example1.comonload

  • GM_xmlhttpReqeust ドキュメントに従って、コールバック内http://www.example2.comで見つけることができます。response.finalUrlonload

誰かが適切な Greasemonkey/JavaScript の方法を教えてくれませんか?

4

3 に答える 3

2

以下に愚かな解決策があります。うまくいくことを願っています。

GM_xmlhttpRequest ( {
    synchronous:    false,
    method:         "HEAD",
    url:            "http://www.google.com",
    onload:         function (response) {
        console.debug (this.url);
    }
} );
于 2013-01-10T06:22:57.717 に答える
2

response渡されるのonloadは、次の主要なプロパティを持つオブジェクトです。

  • 準備完了状態
  • 応答ヘッダー
  • 応答テキスト
  • 状態
  • ステータステキスト
  • 最終 URL

あなたがしたいfinalUrl、あなたはそれを次のように取得します:

GM_xmlhttpRequest ( {
    synchronous:    false,
    method:         "HEAD",
    url:            "http://www.google.com",
    onload:         function (response) {
        console.debug (response.finalUrl);
    }
} );


改訂/明確化された質問の更新:

最初に要求された URL を取得/知るにはGM_xmlhttpRequest()クロージャを呼び出す必要があります。そのようです:

var origURL = "http://www.google.com";

(function (targURL) {
    GM_xmlhttpRequest ( {
        synchronous:    false,
        method:         "HEAD",
        url:            targURL,
        onload:         function (response) {
            console.log ("orig URL: ", targURL);
            console.log ("final URL: ", response.finalUrl);
        }
    } );
} ) (origURL);
于 2013-01-10T06:40:40.627 に答える
0

を参照して

http://userscripts-mirror.org/topics/51161

まず、次のものが必要です。

var method = this;
  var oldargs = [].slice.call( arguments, 1 );
  return function () {
    var newargs = [].slice.call( arguments );
    return method.apply( thisObject, oldargs.concat( newargs ));
  };
}

次に、同じように...

ここに画像の説明を入力

于 2016-11-19T04:25:13.507 に答える