Greasy Fork

Greasy Fork is available in English.

qq音乐,酷我,酷狗,虾米,咪咕,网易,千千,喜马拉雅在线音乐平台倍速播放

qq音乐,酷我,酷狗,虾米,咪咕在线可实现倍速音乐播放,那些喜欢加速播放音乐的可有福利了,音乐加速播放带感。网易,千千音乐,喜马拉雅都是利用flash生成播放的,做了特别处理,舍弃自带播放器(并不是删了)创建了一个audio播放器来操作速度

当前为 2020-07-31 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         qq音乐,酷我,酷狗,虾米,咪咕,网易,千千,喜马拉雅在线音乐平台倍速播放
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  qq音乐,酷我,酷狗,虾米,咪咕在线可实现倍速音乐播放,那些喜欢加速播放音乐的可有福利了,音乐加速播放带感。网易,千千音乐,喜马拉雅都是利用flash生成播放的,做了特别处理,舍弃自带播放器(并不是删了)创建了一个audio播放器来操作速度
// @author       YQS
// @match        *://y.qq.com/portal/player*
// @match        *://www.kuwo.cn/*
// @match        *://www.kugou.com/song/*
// @match        *://*.xiami.com/*
// @match        *://music.migu.cn/v3/music/player*
// @match        *://music.163.com/*
// @match        *://music.taihe.com/song/*
// @match        *://play.taihe.com/*
// @match        *://www.ximalaya.com/*
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_deleteValue
// @grant        GM_xmlhttpRequest
// @run-at       document-end
// ==/UserScript==

(function() {
    'use strict';
    var host = window.location.host;
    var audio = "";
    var speed = 1.0;
    var add_speed = 0.1;
    var timer = null;
    var val = null;
    var getObj = function(flag,id){
        if(flag == 1){
            return document.getElementById(id);
        }else if(flag == 2){
            return document.getElementsByTagName(id)[0];
        }
    }
    //获取url参数合集,比较简单
    var getUrlMethod = function(){
        var obj = {};
        let method = location.href;
        //console.log(method);
        var str = "";
        if(method){
            str = method.split("?")[1];
        }
        if(typeof(str) == "undefined") return obj;
        str = str.split("&");
        for(var i in str){
            obj[str[i].split("=")[0]] = str[i].split("=")[1];
        }
        return obj;
    }
    var body = getObj(2,"body");
    if(host.search("qq.com") != -1){
       timer = setInterval(function(){
           audio = getObj(1,"h5audio_media");
           if(audio){
               clearInterval(timer);
           }
       },1000);
    }else if(host.search("kuwo.cn") != -1){
        audio = getObj(2,"audio");
    }else if(host.search("kugou.com") != -1){
        audio = getObj(1,"myAudio");
    }else if(host.search("xiami.com") != -1){
        audio = getObj(2,"audio");
    }else if(host.search("migu.cn") != -1){
        audio = getObj(1,"migu_audio");
    }else if(host.search("163.com") != -1 || host.search("taihe.com") != -1 || host.search("ximalaya.com") != -1){
        /**
         * 网易云音乐是flash,所以只能获取源地址构建html audio标签播放了
         * 获取地址,必须先点击播放按钮,或点击音乐列表中的音乐才能获取源地址
         * 默认情况下是获取当前点击跳转到该音乐播放获取id,播放列表的需要点击了
        */
        var top = "";
        var doc = "";
        if(host.indexOf("163") != -1){
            top = window.top.document.body;
            doc = window.top.document;
        }else if(host.indexOf("taihe") != -1){
            //getDefalutUrl();
            top = body;
            doc = window.document;
            GM_setValue("status",true);
        }else if(host.indexOf("ximalaya") != -1){
            top = window.top.document.body;
            doc = window.top.document;
            GM_setValue("status",true);
        }
        if(GM_getValue("status")){
            var method = getUrlMethod();
            var audio_url = "";
            var get_url = "";
            if(host.indexOf("163") != -1){
                if(typeof(method.id) != "undefined"){
                    audio_url = "http://music.163.com/song/media/outer/url?id="+method.id+".mp3";
                }
            }else if(host.indexOf("taihe") != -1){
                var id = getAudioId();
                //千千音乐盒
                if(host == "play.taihe.com"){
                    getDefalutUrl();
                    var xml = new XMLHttpRequest();
                    console.log(xml.responseURL);
                    var a = getObj(1,"playTitle").getElementsByClassName("songname")[0];
                    var b = a.getAttribute("href")//.split("?")[0];
                    console.log(a);
                    var c = b.split("/");
                    id = parseInt(c[c.length-1]);

                    console.log(id);
                }
                if(typeof(id) == "number"){
                    GM_xmlhttpRequest({
                        method: "get",
                        url: "http://musicapi.taihe.com/v1/restserver/ting?method=baidu.ting.song.playAAC&format=jsonp&songid="+id+"&from=web",
                        data: "",
                        responseType:"json",
                        onload: function(res){
                            res = res.response;
                            audio_url = res.bitrate.file_link;
                        }
                    });
                }
            }else if(host.indexOf("ximalaya") != -1){
                id = getAudioId();
                var play_list1 = doc.getElementsByClassName("play-btn fR_")[0];
                if(play_list1){
                    play_list1.style.display = "none";
                }
                var p_timer = setInterval(function(){
                    var play_list2 = doc.getElementsByClassName("xm-player-list-content")[0];
                    if(play_list2){
                        var play_li = play_list2.getElementsByClassName("row");
                        var play_st = "";
                        var audio = doc.getElementById("create_audio");
                        var btn = doc.getElementsByClassName("xm-player-btns")[0].getElementsByTagName("a")[1];
                        for(var i = 0; i < play_li.length; i++){
                            play_li[i].onclick=function(){
                                play_st = doc.getElementsByClassName("xm-player-cover")[0];
                                var sp = play_st.getAttribute("href").split("/");
                                id = sp[sp.length-1];
                                GM_xmlhttpRequest({
                                    method: "get",
                                    url: "https://www.ximalaya.com/revision/play/v1/audio?id="+id+"&ptype=1",
                                    data: "",
                                    responseType:"json",
                                    onload: function(res){
                                        res = res.response
                                        audio.setAttribute("src",res.data.src);
                                        if(audio.paused){
                                            audio.play();
                                        }
                                        setTimeout(function(){
                                            if(btn.getAttribute("class") == "pause"){
                                                btn.click();
                                            }
                                        },1000);
                                    }
                                });
                            }
                        }
                        clearInterval(p_timer);
                    }
                },1000);


                if(typeof(id) == "number"){
                    GM_xmlhttpRequest({
                        method: "get",
                        url: "https://www.ximalaya.com/revision/play/v1/audio?id="+id+"&ptype=1",
                        data: "",
                        responseType:"json",
                        onload: function(res){
                            res = res.response;
                            audio_url = res.data.src;
                        }
                    });
                }

            }
            var create_adiv = document.createElement("div");
            var create_audio = document.createElement("audio");
            create_adiv.style.cssText = "position:fixed; right:53px; bottom:50px; width:400px; height:100px; border-radius:5px; background:rgba(0,0,0,.3); z-index:100000";
            create_audio.id = "create_audio";
            create_audio.setAttribute("controls","controls");
            create_audio.setAttribute("autoplay","autoplay");
            create_audio.setAttribute("src",audio_url);
            create_audio.style.cssText = "width:350px; position: absolute; top:0; left:0; bottom:0; right:0; margin:auto;";
            create_adiv.appendChild(create_audio);
            audio = create_audio;
            top.appendChild(create_adiv);
            createDocument(top);
            timer = setInterval(function(){
                if(host.indexOf("163") != -1){
                    var play = doc.getElementById("g_playlist");
                    if(play){
                        var p = play.getElementsByClassName('f-cb')[0].getElementsByTagName('li');
                        for(var i = 0; i < p.length; i++){
                            p[i].onclick=function(){
                                var id=this.getAttribute('data-id');
                                create_audio.setAttribute('src','/song/media/outer/url?id='+id+'.mp3');
                                setTimeout(function(){
                                    var ay = doc.getElementsByClassName("ply")[0];
                                    if(ay.getAttribute("data-action") == "pause"){
                                        ay.click();
                                    }
                                },1000);
                                if(create_audio.paused){
                                    create_audio.play();
                                }
                            };
                        }
                    }
                }else if(host.indexOf("ximalaya") != -1){

                }
            },1000);
            GM_deleteValue("status");
        }else{
            GM_setValue("status",true);
            setTimeout(function(){GM_deleteValue("status")},2000);
        }
    }
    if(host.indexOf("163") == -1 && host.indexOf("taihe") == -1 && host.indexOf("ximalaya") == -1){
        createDocument(body)
    }

    function createDocument(curdoc){
        var style_div = "position:fixed; right:0; bottom:50px; width:40px; height:100px;border-top-left-radius:3px; border-bottom-left-radius:3px; background:rgba(0,0,0,.3); z-index:100000";
        var style_add = "width:100%;height:40px; box-sizing: border-box; text-align:center; line-height:40px; color:white; font-size:30px; font-weight:bold;cursor: pointer;";
        var style_plus = "border-bottom:1px solid #ccc";
        var style_show = "width:100%;height:20px; box-sizing: border-box; text-align:center; line-height:20px; color:white; font-size:16px; font-weight:bold;";
        var create_div = document.createElement("div");
        var create_plus = document.createElement("div");
        var create_show = document.createElement("div");
        var create_sign = document.createElement("div");
        create_div.style.cssText = style_div;
        create_plus.innerText = "+";
        create_plus.style.cssText = style_add + style_plus;
        create_sign.innerText ="-";
        create_sign.style.cssText = style_add;
        create_show.style.cssText = style_show + style_plus;
        create_show.innerText = parseFloat(speed).toFixed(1);
        create_div.appendChild(create_plus);
        create_div.appendChild(create_show);
        create_div.appendChild(create_sign);
        curdoc.appendChild(create_div);

        create_plus.addEventListener("click",function(){
            var rate = audio.playbackRate;
            audio.playbackRate = parseFloat(rate + add_speed).toFixed(1);
            speed = audio.playbackRate;
            console.log(speed);
            create_show.innerText = speed;
        });
        create_sign.addEventListener("click",function(){
            if(speed <= add_speed){
                alert("不能再减了");
                return;
            }
            var rate = audio.playbackRate;
            audio.playbackRate = parseFloat(rate - add_speed).toFixed(1);
            speed = audio.playbackRate;
            console.log(speed);
            create_show.innerText = speed;
        });

        setInterval(function(){
            audio.playbackRate = speed;
        },500);
    }
    //获取url中音乐的id
    function getAudioId(){
        var song = location.href.split("/");
        var id = song[song.length-1];
        return parseInt(id);
    }
    function getDefalutUrl(){
       Object.defineProperty(XMLHttpRequest.prototype,"status",{
            get: function(status) {
                val = {
                    url: this.responseURL,
                    data: this.response
                };
            },
            post:function(status){
                val = {
                    url: this.responseURL,
                    data: this.response
                };
            }
        });
    }

})();