forked from defpt/userChromeJs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openImgRar.uc.js
26 lines (26 loc) · 1.67 KB
/
openImgRar.uc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// ==UserScript==
// @include chrome://browser/content/browser.xul
// ==/UserScript==
location == "chrome://browser/content/browser.xul" && (function () {
(function (m) {
m.id = "openImgRar";
m.addEventListener("command", function () {
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
try {
var path = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getCharPref("browser.cache.disk.parent_directory") + "\\Cache\\" + new Date().getTime() + ".rar";
file.initWithPath(path);
} catch (e) {
var path = Components.classes["@mozilla.org/file/directory_service;1"].getService(Components.interfaces.nsIProperties).get("ProfLD", Components.interfaces.nsILocalFile).path + "\\Cache\\" + new Date().getTime() + ".rar";
}
file.initWithPath(path);
Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].createInstance(Components.interfaces.nsIWebBrowserPersist).saveURI(Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService).newURI((gContextMenu.mediaURL || gContextMenu.imageURL), null, null), null, null, null, null, file, null);
setTimeout(function () {
file.launch();
}, 100);
}, false);
m.setAttribute("label", "\u6253\u5F00\u56FE\u7247rar");
})(document.getElementById("contentAreaContextMenu").insertBefore(document.createElement("menuitem"), document.getElementById("context-openlinkintab")));
document.getElementById("contentAreaContextMenu").addEventListener("popupshowing", function () {
gContextMenu.showItem("openImgRar", gContextMenu.onImage);
}, false);
})()