2

我正在嘗試爲某個文件類型編寫插件,並且我想在「打開方式」和「保存文件」選項下的「下載文件」對話框中添加「發送到MyAddonName」選項。不提及下載管理器。在「下載文件」對話框中添加一個選項?

有沒有什麼辦法可以實現這個使用Firefox Addon SDK?這是我的第一個擴展,所以我對SDK或更高級的XUL插件不是很熟悉。

回答

2

我不知道如何用addon sdk做到這一點。但這是我如何從bootstrap插件做到這一點。

我會用Services.wm.addEventListener添加這個,聽的chrome://mozapps/content/downloads/unknownContentType.xul

var windowListener = { 
    //DO NOT EDIT HERE 
    onOpenWindow: function(aXULWindow) { 
     // Wait for the window to finish loading 
     let aDOMWindow = aXULWindow.QueryInterface(Ci.nsIInterfaceRequestor).getInterface(Ci.nsIDOMWindowInternal || Ci.nsIDOMWindow); 
     aDOMWindow.addEventListener('load', function() { 
      aDOMWindow.removeEventListener('load', arguments.callee, false); 
      windowListener.loadIntoWindow(aDOMWindow); 
     }, false); 
    }, 
    onCloseWindow: function(aXULWindow) {}, 
    onWindowTitleChange: function(aXULWindow, aNewTitle) {}, 
    register: function() { 
     // Load into any existing windows 
     let DOMWindows = Services.wm.getEnumerator(null); 
     while (DOMWindows.hasMoreElements()) { 
      let aDOMWindow = DOMWindows.getNext(); 
      windowListener.loadIntoWindow(aDOMWindow); 
     } 
     // Listen to new windows 
     Services.wm.addListener(windowListener); 
     registered = true; 
    }, 
    unregister: function() { 
     // Unload from any existing windows 
     let DOMWindows = Services.wm.getEnumerator(null); 
     while (DOMWindows.hasMoreElements()) { 
      let aDOMWindow = DOMWindows.getNext(); 
      windowListener.unloadFromWindow(aDOMWindow); 
     } 
     for (var u in unloaders) { 
      unloaders[u](); 
     } 
     //Stop listening so future added windows dont get this attached 
     Services.wm.removeListener(windowListener); 
    }, 
    //END - DO NOT EDIT HERE 
    loadIntoWindow: function(aDOMWindow) { 
     if (!aDOMWindow) { 
      return; 
     } 
     if (aDOMWindow.location == 'chrome://mozapps/content/downloads/unknownContentType.xul'); { 
      //check file type 
      var fileName = aDOMWindow.document.getElementById('location').value; 
      var fileType = fileName.substr(fileName.lastIndexOf('.')); 

      if (fileType == 'zip') { 
       var myxul = document.createElementNS('xul namescpae here look it up', 'element you want'); 
       aDOMWindow.document.insertBefore(elementToInsertBefore, myXul); 
      } 
     } 
    }, 
    unloadFromWindow: function(aDOMWindow) { 
     if (!aDOMWindow) { 
      return; 
     } 
    } 
} 
}; 
窗口負荷
相關問題