mikecoding / QQ Music Download

// ==UserScript==
// @name         QQ Music Download
// @namespace    https://openuserjs.org/user/mikecoding
// @version      0.3
// @description  下载【正在播放】的QQ音乐
// @author       mikecoding
// @match        https://y.qq.com/portal/player.html
// @copyright 2019, mikecoding (https://openuserjs.org/users/mikecoding)
// @require    http://code.jquery.com/jquery-1.11.0.min.js
// @grant unsafeWindow
// @license MIT
// ==/UserScript==
(function () {
  'use strict';
  var playurl;
  jQuery.fn.wait = function (func, times, interval) {
    var _times = times || -1, //100次
      _interval = interval || 20, //20毫秒每次
      _self = this,
      _selector = this.selector, //选择器
      _iIntervalID; //定时器id
    if (this.length) { //如果已经获取到了,就直接执行函数
      func && func.call(this);
    }
    else {
      _iIntervalID = setInterval(function () {
        if (!_times) { //是0就退出
          clearInterval(_iIntervalID);
        }
        _times <= 0 || _times--; //如果是正数就 --

        _self = $(_selector); //再次选择
        if (_self.length) { //判断是否取到
          func && func.call(_self);
          clearInterval(_iIntervalID);
        }
      }, _interval);
    }
    return this;
  }
  $(".list_menu__icon_add").wait(function () {
    $('<a href="javascript:;" class="list_menu__item list_menu__down monkey_down" title="直链下载"><i class="list_menu__icon_down"></i><span class="icon_txt">直链下载</span></a>').appendTo(".mod_list_menu");
    $(".monkey_down").click(function (e) {
      e.currentTarget.parentElement.children[0].click()
      window.setTimeout(function () {
        window.open(playurl)
      }, 2700);
    });
  });
  var oldLog = unsafeWindow.console.log;
  unsafeWindow.console.log = function (text) {
    oldLog(text);
    if (text.match("expPlayUL")) {
      playurl = text.substr(text.search("h"));
    }
  };
})();