Automatic Jango Downloader

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

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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);