Automatic Jango Downloader

Automatically download all songs played in jango.com while listening.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name       	Automatic Jango Downloader
// @author      Finomosec
// @namespace  	http://meinebasis.de/
// @description Automatically download all songs played in jango.com while listening.
// @version    	1.3
// @grant       GM.xmlHttpRequest
// @match       https://www.jango.com/*
// @license     MIT
// ==/UserScript==

const storagePrefix = "D:";

var originalAudio = window.Audio;
unsafeWindow.Audio = exportFunction(function() {
  var audioElement = new originalAudio();
  audioElement.addEventListener('loadeddata', function() {
    var url = audioElement.src;
    if (url.indexOf(".jango.com/") == -1) {
      return;
    }

    var fileName = url.substring(url.lastIndexOf("/") + 1);
    var fileSuffix = url.substring(url.lastIndexOf("."));
    var niceFileName = unsafeWindow.document.title.replace(": ", " - ").replace(" - Jango", "").replace("&", "&") + fileSuffix;

    if (localStorage.getItem(storagePrefix + fileName)) {
      // console.info('Already downloaded:', niceFileName);
      return;
    }

    // console.info('Downloading:', niceFileName);
    GM.xmlHttpRequest({
      method: "GET",
      url: url,
      responseType: 'arraybuffer',
      onload: function(response) {
        var blob = new Blob([response.response], {type: "audio/" + fileSuffix.substring(1)});
        var url = URL.createObjectURL(blob);
        var link = document.createElement('a');
        link.href = url;
        link.download = niceFileName;
        link.click();
        localStorage.setItem(storagePrefix + fileName, "1");
      }
    });
  });
  return audioElement;
}, unsafeWindow);