2011-07-10 100 views
0

我需要擴展firebug以使用從網頁中提取的鏈接(當從頁面中的任何鏈接下載時發送)將其發送到將要下載它的另一臺機器。我打算使用螢火蟲爲我提取這個鏈接。如果有任何其他的方式,我可以從瀏覽器中獲取這些信息,即使是這樣,我們將不勝感激。如何爲Firebug創建擴展

+0

您正在尋找的下載管理行爲的自定義類型。我沒有看到Firebug與它有什麼關係。 –

+0

您可能會使用Firebug來幫助開發擴展程序,但這聽起來不像是需要擴展螢火蟲的東西。您可能想要完整擴展或使用GreaseMonkey。 – joshhendo

+0

如果不是螢火蟲,那麼當用戶點擊一個鏈接進行下載時,有沒有辦法檢測到下載從何處開始的鏈接。 – SThomas

回答

0

實際上,它的壞主意使用事件來檢測HTTP請求等功能,Firefox的強大功能xul語言使您能夠檢測所有瀏覽器請求/響應,然後您可以決定從請求/響應標題:
你可以使用「http-observe」巫婆其實Firebug用於網絡面板
- 這裏是mozilla MDN中的「http-observe」的鏈接[https://developer.mozilla.org/en/ Setting_HTTP_request_headers] [1]
- 這裏也爲一個簡單的例子 「HTTP-觀察」

// first create observerService component as a property into your extension javascript object 
    var myExtension = { observerService:Components.classes["@mozilla.org/observerservice;1"].getService(Components.interfaces.nsIObserverService), 
     init:function(){ 
      // in the init function setup the observe service and set witch javascript object is the listener for http response for example "this" 
      this.observerService.addObserver(this,"http-on-examine-response", false); 
      this.observerService.addObserver(this,"http-on-examine-cached-response", false); 
     }, 
     observe: function(aSubject, aTopic, aData){ // the observe function 
      if (aTopic == "http-on-examine-response" || aTopic == "http-on-examine-cached-response"){ 
       var httpChannel = aSubject.QueryInterface(Components.interfaces.nsIHttpChannel); 
       var URI = httpChannel.originalURI.spec;      
       if (aSubject.loadFlags & httpChannel.LOAD_INITIAL_DOCUMENT_URI){ // this detect if the response is primery request 
        var contentType = httpChannel.getResponseHeader("content-type"); // check the heder content-type 
        if (contentType == "what ever you want"){ // you can check if it zip/html/xml ...etc 
       //do what ever you want 
       } 
       } 
      } 
     } 
    }