// ==UserScript== // @name Download Comment for Fx // @include main // @description ãã¦ã³ãã¼ããã¡ã¤ã«ã®ã¹ãããã©ã¤ãã³ã¡ã³ãã«URIãæ¸ãè¾¼ã // @compatibility Firefox 2.0 3.0 // @Last Change: 2008-06-04. // ==/UserScript== var ucjsDownloadComment = { initialized: false, observerService: Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService), init: function() { if (this.initialized) return; this.initialized = true; // Add download observer this.observerService.addObserver(this, "dl-done", false); }, uninit: function() { if (!this.initialized) return; this.initialized = false; this.observerService.removeObserver(this, "dl-done"); }, writeComment: function(aFile, aComment) { // get chrome directory try { var scpt = Components.classes["@mozilla.org/file/directory_service;1"] .getService(Components.interfaces.nsIProperties) .get("UChrm", Components.interfaces.nsIFile); scpt.append("WriteComment.scpt"); var osascript = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); osascript.initWithPath("/usr/bin/osascript"); if (!scpt.exists() || !osascript.exists) return; var process = Components.classes["@mozilla.org/process/util;1"].createInstance(Components.interfaces.nsIProcess); process.init(osascript); var args = [scpt.path, aFile, aComment]; process.run(false, args, args.length); } catch(e) {} }, observe: function (subject, topic, state) { var oDownload = subject.QueryInterface(Components.interfaces.nsIDownload); //**** Get Download file object var oFile = null; try{ oFile = oDownload.targetFile.path; // New firefox 0.9+ } catch (e){ oFile = oDownload.target.path; // Old firefox 0.8 } var sourceURI = oDownload.source.spec; //**** Download Success // alert('Done download from - '+sourceURI+' to - '+oFile.path); this.writeComment(oFile, sourceURI); } } ucjsDownloadComment.init(); window.addEventListener("unload", function() { if (!ucjsDownloadComment.initialized) return; ucjsDownloadComment.uninit(); }, false);