doubanFM2NetEase

doubanFM searching in netease cloud music

目前为 2016-10-23 提交的版本。查看 最新版本

// ==UserScript==
// @name         doubanFM2NetEase
// @namespace    https://gf.qytechs.cn/zh-CN/scripts/11674-doubanfm2netease
// @version      0.25
// @description  doubanFM searching in netease cloud music
// @author       xavier skip
// @match        http*://douban.fm/*
// @grant        none
// @run-at document-load
// ==/UserScript==

function addGlobalStyle(css) {
	var head, style;
	head = document.getElementsByTagName('head')[0];
	if (!head) { return; }
	style = document.createElement('style');
	style.type = 'text/css';
	style.innerHTML = css;
	head.appendChild(style);
}

function NetEase(){
    //不知道为什么豆瓣存储的信息song.artist和song.album总是一样的
    return{
        check: function(){
            var e = document.querySelector('.send-song-to-phone');
            this.version = e?1:2;
            return this.version;
        },
        v1: function(){
            var info = JSON.parse(window.localStorage.getItem('bubbler_song_info'));
            return {
                song: info.song_name,
                album: info.album,
                artist: info.artist
            };
        },
        v2: function(){
            var info = JSON.parse(window.localStorage.getItem('simpleStorage'))['douradio-player-state'].current_song;
            return {
                song: info.title,
                album: info.albumtitle ,
                artist: info.artist
            };
        },
        search: function(){
            var v = this.check();
            var info;
            if ( v == 1 ) {
                info = this.v1();
            }else{
                info = this.v2();
            }
            return this.search_url(info);
        },
        search_url: function(info){
            var keywords;
            if(info.song.length>30){
                keywords = info.song;
            }else if( (info.song.length + info.album.length)>40){
                keywords = [info.song, info.album].join(' ');
            }else{
                keywords = [info.song, info.album, info.artist].join(' ');
            }
            return "http://music.163.com/#/search/m/?s="+encodeURIComponent(keywords);
        },
        get_element :function(){
            var that = this;
            var a = document.createElement('a');
            a.id = "netease";
            a.target="_blank";
            a.innerText = "在网易云音乐中查找当前播放歌曲";
            a.href = this.search();
            a.addEventListener("click",function(e){
                a.href = that.search();
                console.log('a click');
                e.stopImmediatePropagation();
            }, true);
            return a;
        },
        into: function(ele){
            ele.appendChild(this.get_element());
        }
    };
}

var insert_queryname = '.sub-buttons-wrapper';
var div = document.createElement('div');
var p = document.createElement('p');
div.appendChild(p);
var netease = new NetEase();
window.addEventListener('load', function(e){
    var content = document.querySelector(insert_queryname);
    var again = function(){
        var content = document.querySelector(insert_queryname);
        if(content){
            content.appendChild(div);
            netease.into(p);
        }else{
            setTimeout(again, 700);
        }
    };
    console.log('load!!!', content);
    if(content){
        setTimeout(again, 700);
    }else{
        again();
    }
}, false);
addGlobalStyle('#netease{color:#888;z-index:9999;}#netease:hover{background:0;color:#5b9;}');

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址