阅读:3354回复:12
【已解决】哪位大侠能修改一下downloadSoundPlay.uc.js,让它在26中可用
下载完成后发出声音的uc脚本,在26中不能用了,哪位高手能修改一下昵,多谢!
// ==UserScript== // @name downloadSoundPlay.uc // @namespace http://space.geocities.yahoo.co.jp/gl/alice0775 // @description ダウンロードマネージャー用のダウンロードを監視し音を鳴らす // @include main // @compatibility Firefox 3.0 more // @author Alice0775 // @version 2009/11/28 // ==/UserScript== var downloadPlaySound = { // -- config -- DL_START : "", DL_DONE : "file:///C:/WINDOWS/Media/chimes.wav", DL_CANCEL: "", DL_FAILED: "", // -- config -- observerService: null, init: function sampleDownload_init() { //window.removeEventListener("load", this, false); window.addEventListener("unload", this, false); //**** ダウンロード監視の追加 this.observerService = Components.classes["@mozilla.org/observer-service;1"] .getService(Components.interfaces.nsIObserverService); this.observerService.addObserver(this, "dl-start", false); this.observerService.addObserver(this, "dl-done", false); this.observerService.addObserver(this, "dl-cancel", false); this.observerService.addObserver(this, "dl-failed", false); }, uninit: function() { window.removeEventListener("unload", this, false); this.observerService.removeObserver(this, "dl-start"); this.observerService.removeObserver(this, "dl-done"); this.observerService.removeObserver(this, "dl-cancel"); this.observerService.removeObserver(this, "dl-failed"); }, // ****************************** // DownloadObserver // ****************************** observe: function (subject, topic, state) { var oDownload = subject.QueryInterface(Components.interfaces.nsIDownload); //**** ダウンロードファイルを持つオブジェクトを取得 var oFile = null; try{ oFile = oDownload.targetFile; // New firefox 0.9+ } catch (e){ oFile = oDownload.target; // Old firefox 0.8 } //**** ダウンロード開始イベント if (topic == "dl-start"){ //alert('Start download to - '+oFile.path); if (this.DL_START) this.playSoundFile(this.DL_START); } //**** ダウンロードキャンセルイベント if(topic == "dl-cancel"){ //alert('Canceled download to - '+oFile.path); if (this.DL_CANCEL) this.playSoundFile(this.DL_CANCEL); } //**** ダウンロード失敗 else if(topic == "dl-failed"){ //alert('Failed download to - '+oFile.path); if (this.DL_FAILED) this.playSoundFile(this.DL_FAILED); } //**** ダウンロード完了 else if(topic == "dl-done"){ //alert('Done download to - '+oFile.path); if (this.DL_DONE) this.playSoundFile(this.DL_DONE); } }, playSoundFile: function(aFilePath) { var ios = Components.classes["@mozilla.org/network/io-service;1"] .createInstance(Components.interfaces["nsIIOService"]); try { var uri = ios.newURI(aFilePath, "UTF-8", null); } catch(e) { return; } var file = uri.QueryInterface(Components.interfaces.nsIFileURL).file; if (!file.exists()) return; this.play(uri); }, play: function(aUri) { var sound = Components.classes["@mozilla.org/sound;1"] .createInstance(Components.interfaces["nsISound"]); sound.play(aUri); }, handleEvent: function(event) { switch (event.type) { case "load": this.init(); break; case"unload": this.uninit(); break; } } } //window.addEventListener("load", downloadPlaySound.init, false); downloadPlaySound.init(); |
|
1楼#
发布于:2013-12-13 23:35
用户被禁言,该主题自动屏蔽! |
|
2楼#
发布于:2013-12-14 11:46
bugmenot:我找到拥有类似功能的两款扩展:Navigational Sounds不错,26有效,还可以自定义声音 |
|
3楼#
发布于:2013-12-14 13:46
在用dta
|
|
4楼#
发布于:2013-12-16 14:30
个人不需要这些其他的功能,不想再安装一个扩展,再求一下哪位能修改一下顶楼的脚本,使其在新版上可以使用!!
|
|
5楼#
发布于:2013-12-16 16:23
|
|
|
6楼#
发布于:2013-12-16 16:30
|
|
7楼#
发布于:2013-12-16 16:45
jinke679:哦,哎,不会js啊,这不是硬逼着我要学js嘛,有的扩展已经能够实现了,不知道能不能改写出来,最近就追这个问题了,我实在是太闲了,回到原帖绝对支持你自学成才。 具体变化可以看这个帖子里面的 XPCOM 的修改第一条: https://www.firefox.net.cn/read-48052 |
|
|
8楼#
发布于:2013-12-17 10:26
用户被禁言,该主题自动屏蔽! |
|
9楼#
发布于:2013-12-18 12:00
// ==UserScript== // @name downloadSoundPlay_Fx26.uc.js // @namespace http://space.geocities.yahoo.co.jp/gl/alice0775 // @description ダウンロードマネージャー用のダウンロードを監視し音を鳴らす // @include main // @compatibility Firefox 26 // @author Alice0775 // @version 2013/12/18 11:00 defineLazyModuleGetter for Firefox26 // @version 2013/12/18 Firefox26 // @version 2009/11/28 // ==/UserScript== var downloadPlaySound = { // -- config -- DL_START : null, DL_DONE : "file:///C:/WINDOWS/Media/chimes.wav", DL_CANCEL: null, DL_FAILED: null, // -- config -- _list: null, init: function sampleDownload_init() { XPCOMUtils.defineLazyModuleGetter(window, "Downloads", "resource://gre/modules/Downloads.jsm"); //window.removeEventListener("load", this, false); window.addEventListener("unload", this, false); //**** ダウンロード監視の追加 if (!this._list) { Downloads.getList(Downloads.ALL).then(list => { this._list = list; return this._list.addView(this); }).then(null, Cu.reportError); } }, uninit: function() { window.removeEventListener("unload", this, false); if (this._list) { this._list.removeView(this); } }, onDownloadAdded: function (aDownload) { //**** ダウンロード開始イベント if (this.DL_START); this.playSoundFile(this.DL_START); }, onDownloadChanged: function (aDownload) { //**** ダウンロードキャンセル if (aDownload.canceled && this.DL_CANCEL) this.playSoundFile(this.DL_CANCEL) //**** ダウンロード失敗 if (aDownload.error && this.DL_FAILED) this.playSoundFile(this.DL_FAILED) //**** ダウンロード完了 if (aDownload.succeeded && this.DL_DONE) this.playSoundFile(this.DL_DONE) }, playSoundFile: function(aFilePath) { if (!aFilePath) return; var ios = Components.classes["@mozilla.org/network/io-service;1"] .createInstance(Components.interfaces["nsIIOService"]); try { var uri = ios.newURI(aFilePath, "UTF-8", null); } catch(e) { return; } var file = uri.QueryInterface(Components.interfaces.nsIFileURL).file; if (!file.exists()) return; this.play(uri); }, play: function(aUri) { var sound = Components.classes["@mozilla.org/sound;1"] .createInstance(Components.interfaces["nsISound"]); sound.play(aUri); }, handleEvent: function(event) { switch (event.type) { case "unload": this.uninit(); break; } } } downloadPlaySound.init(); |
|
10楼#
发布于:2013-12-18 12:58
user:// ==UserScript==赞!Alice0775终于出了新版了 |
|
11楼#
发布于:2013-12-18 15:23
bugmenot:有没有人能向Download Manager Tweak作者提出建议,建议他在下一个版本中添加“下载完成声音”的功能回到原帖我用 https://addons.mozilla.org/en-US/firefox/addon/download-dialog-tweak/?src=api |
|
|
12楼#
发布于:2013-12-18 15:47
user:// ==UserScript==作者更新了,感谢分享 |
|