Skip to content

Instantly share code, notes, and snippets.

@linusyu
Last active August 29, 2015 14:01
Show Gist options
  • Save linusyu/859e7936f226a3746b6c to your computer and use it in GitHub Desktop.
Save linusyu/859e7936f226a3746b6c to your computer and use it in GitHub Desktop.
虾米猜显示歌曲评论。
// ==UserScript==
// @name xiamia
// @namespace http://www.xiami.com/
// @include http://www.xiami.com/radio/play/*
// @version 1
// @grant none
// ==/UserScript==
;(function($){
var wl = $("#radio_wall");
wl.html("<img src='http://img.xiami.net/res/img/default/loading.gif'>");
unsafeWindow.Fm_beforeplay=function(a){var b,c,d,e,f;unsafeWindow.nowSoundObj=a,document.title=a.songName+"——虾小米打碟中……",radioSong=a.songName,radioArtist=a.artist,$(".reasons").hide(),a.artisId!=relate_arid&&(relate_arid=a.artisId,$(".artist_relate_main").replaceWith('<img class="artist_relate_main" src="http://img.xiami.net/res/img/default/loading.gif" width="16" height="16" alt="加载中">'),wall_post(a.songId),$.post("/radio/relate-info",{arid:a.artisId,_xiamitoken:_xiamitoken},function(a){$(".artist_relate_main").replaceWith('<div class="artist_relate_main clearfix"></div>'),a&&$(".artist_relate_main").html(a).fadeIn()})),a.songId&&($(".lyric_v3").children().find(".more").hide(),$(".lyric").replaceWith('<img class="lyric" src="http://img.xiami.net/res/img/default/loading.gif" width="16" height="16" alt="加载中">'),$.post("/radio/lyric",{sid:a.songId},function(a){$(".lyric").replaceWith('<div class="lyric less_lrc"></div>'),a&&(a.indexOf("这首歌还没有歌词")<=0&&($(".lyric_v3").children().find(".more").show(),$.cookie("showlyric")&&($(".lyric").removeClass("less_lrc"),$("a.mr").attr("id","show_more").html("收起"))),$(".lyric").html(a).fadeIn())}),a.reason&&""!=a.reason&&(b=a.reason,b&&(c="",d="","虾小米为你推荐"==b.content?c='<a href="http://www.xiami.com/u/86" target="blank">虾小米</a>为你推荐':""!=b.url||""!=b.title?(e="",b.artist&&(e=" - "+b.artist),c=b.content+' <a href="'+b.url+'" title="'+b.title+'" target="blank">'+b.title+e+"</a>",d='╮(╯3╰)╭ <a href="###" onclick="reasonSayNo(); return false;">我不赞同</a>'):c=b.content,""!=d&&$(".reasons").find("span").html(d),c&&($(".reasons").find("p").html(c),$(".reasons").show()))),f=$("#RadioIdHidden").val(),$(".r_s").attr("onClick","recommend("+f+",313,"+a.songId+")")),$("#RadioArtistHidden").val(a.artisId),CheckLoad("onclickup",10,a.artisId)}
function wall_post(id){
wl.html("<img src='http://img.xiami.net/res/img/default/loading.gif'>");
$.get("/song/"+id,function(data){
var doc = document.implementation.createHTMLDocument("newHTMLDocument");
doc.documentElement.innerHTML = data;
var list = doc.querySelector("#wall");
wl.html(list.innerHTML);
ajaxTurnPage('',4);
doc = null;
})
}
ajaxTurnPage = function(data,type){
if(data){
var $wallCount = $(".wall_list_count").clone();
$commentDiv = $(".wall_list");
$commentDiv.empty().append(data);
$commentDiv.prepend($wallCount);
}
$("#wall_list .all_page>a").each(function(){
var href=$(this).attr('href');
var patrn=/page\/(\d+)/;
var page = patrn.exec(href);
if(page) {
href = '/commentlist/turnpage/id/'+unsafeWindow.nowSoundObj.songId+'/page/'+page[1]+'/ajax/1';
$(this).attr('href','javascript:;').click(function(){
var location = String(window.location).split("#");
$("#wall_list .all_page").empty().append($loading2);
$.post(href,{'type':type},function(data){ window.location = location[0]+"#wall_list";ajaxTurnPage(data,type);});
});
}
});
unsafeWindow.regEvent();
unsafeWindow.regReportEvent();
}
})(unsafeWindow.jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment