Created
April 27, 2013 11:38
-
-
Save yume-chan/5472799 to your computer and use it in GitHub Desktop.
Copy Download link
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @id copyDownloadLink | |
// @name Copy Download Link | |
// @version 1.2 | |
// @namespace simon | |
// @author Simon Chan | |
// @description Add a button to copy download link. | |
// @include chrome://mozapps/content/downloads/unknownContentType.xul | |
// @run-at document-end | |
// ==/UserScript== | |
(function() { | |
if(window.location.href != "chrome://mozapps/content/downloads/unknownContentType.xul") | |
return; | |
const {classes: Cc, interfaces: Ci, results: Cr} = Components; | |
const CB = Cc['@mozilla.org/widget/clipboardhelper;1'] | |
.getService(Ci.nsIClipboardHelper); | |
var copyButton = document.createElement("button"); | |
copyButton.className = "dialog-button"; | |
copyButton.setAttribute("label", "Copy Link"); | |
copyButton.addEventListener("click", function () { | |
// GM_setClipboard(dialog.mLauncher.source.spec); | |
CB.copyString(dialog.mLauncher.source.spec); | |
}); | |
var saveButton = document.documentElement.getButton("accept");; | |
saveButton.parentNode.insertBefore(copyButton, saveButton); | |
document.querySelector("#mode").addEventListener("select", function () { | |
if (dialog.dialogElement("save").selected) { | |
if (!document.querySelector("#locationtext")) { | |
var locationtext = document.querySelector("#location").parentNode.insertBefore(document.createElement("textbox"), document.querySelector("#location")); | |
locationtext.id = "locationtext"; | |
locationtext.setAttribute("style", "margin-top:-2px;margin-bottom:-3px"); | |
locationtext.value = document.querySelector("#location").value; | |
} | |
document.querySelector("#location").hidden = true; | |
document.querySelector("#locationtext").hidden = false; | |
} else { | |
document.querySelector("#locationtext").hidden = true; | |
document.querySelector("#location").hidden = false; | |
} | |
}, false) | |
dialog.dialogElement("save").selected && dialog.dialogElement("save").click(); | |
window.addEventListener("dialogaccept", function () { | |
if ((document.querySelector("#locationtext").value != document.querySelector("#location").value) && dialog.dialogElement("save").selected) { | |
dialog.mLauncher.saveToDisk(dialog.promptForSaveToFile(dialog.mLauncher, window, document.querySelector("#locationtext").value), 1); | |
dialog.onCancel = null; | |
document.documentElement.removeAttribute("ondialogaccept"); | |
} | |
}); | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment