- Firefox-Version
 - 136.0
 - Betriebssystem
 - Windows 11 Professional 64 bit 24H2
 
Dieses Skript spielt keinen Ton mehr ab, wenn ein Download fertig ist, seit dem Update auf Fx 136.
JavaScript: downloadSoundPlay.uc.js
		
					
				// ==UserScript==
// @name           downloadSoundPlay_Fx26.uc.js
// @namespace      http://space.geocities.yahoo.co.jp/gl/alice0775
// @description    Downloads überwachen und Ton Dateien für Download-Manager abspielen
// @include        main
// @compatibility  Firefox 115
// @author         Alice0775
// @version        2023/10/13 use ChromeUtils.import instead of XPCOMUtils.defineLazyModuleGetter
// @version        2016/03/15 hack of selection chanhe
// @version        2015/01/15 1:00 Fixed strictmode
// @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/tada.wav",
  DL_CANCEL: null,
  DL_FAILED: "file:///C:/Windows/Media/XP/Windows Error.wav",
  // -- config --
  _list: null,
  init: function sampleDownload_init() {
    const { Downloads } = ChromeUtils.import(
    "resource://gre/modules/Downloads.jsm");
    //window.removeEventListener("load", this, false);
    window.addEventListener("unload", this, false);
    //**** Download-Überwachung hinzufügen
    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) {
    //**** Startereignis herunterladen
    if (this.DL_START)
      this.playSoundFile(this.DL_START);
  },
  onDownloadChanged: function (aDownload) {
    //**** Download abbrechen
    if (aDownload.canceled && this.DL_CANCEL)
      this.playSoundFile(this.DL_CANCEL)
    //**** Herunterladen fehlgeschlagen
    if (aDownload.error && this.DL_FAILED)
      this.playSoundFile(this.DL_FAILED)
    //**** Download abgeschlossen
    if (typeof aDownload.downloadPlaySound == "undefined" &&
        aDownload.succeeded && aDownload.stopped && this.DL_DONE) {
      aDownload.downloadPlaySound = true;
      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();
	
			Alles anzeigen
	Die Fehlerkonsole wirft den Fehler aus, dass in Zeile 26 ChromeUtils.import keine Funktion ist.
Nach der Änderung in ChromeUtils.importESModule kommt die Fehlermeldung
"Failed to load resource://gre/modules/Downloads.jsm"
Edit: Doch noch selbst herausgefunden. Das hier funktioniert.
JavaScript: downloadSoundPlay.uc.js
		
					
				// ==UserScript==
// @name           downloadSoundPlay_Fx26.uc.js
// @namespace      http://space.geocities.yahoo.co.jp/gl/alice0775
// @description    Downloads überwachen und Ton Dateien für Download-Manager abspielen
// @include        main
// @compatibility  Firefox 115
// @author         Alice0775
// @version        2023/10/13 use ChromeUtils.import instead of XPCOMUtils.defineLazyModuleGetter
// @version        2016/03/15 hack of selection chanhe
// @version        2015/01/15 1:00 Fixed strictmode
// @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/tada.wav",
  DL_CANCEL: null,
  DL_FAILED: "file:///C:/Windows/Media/XP/Windows Error.wav",
  // -- config --
  _list: null,
  init: function sampleDownload_init() {
    const { Downloads } = ChromeUtils.importESModule(
    "resource://gre/modules/Downloads.sys.mjs");
    //window.removeEventListener("load", this, false);
    window.addEventListener("unload", this, false);
    //**** Download-Überwachung hinzufügen
    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) {
    //**** Startereignis herunterladen
    if (this.DL_START)
      this.playSoundFile(this.DL_START);
  },
  onDownloadChanged: function (aDownload) {
    //**** Download abbrechen
    if (aDownload.canceled && this.DL_CANCEL)
      this.playSoundFile(this.DL_CANCEL)
    //**** Herunterladen fehlgeschlagen
    if (aDownload.error && this.DL_FAILED)
      this.playSoundFile(this.DL_FAILED)
    //**** Download abgeschlossen
    if (typeof aDownload.downloadPlaySound == "undefined" &&
        aDownload.succeeded && aDownload.stopped && this.DL_DONE) {
      aDownload.downloadPlaySound = true;
      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();
	
			Alles anzeigen