pp for osu score pages

shows pp data from osustats.ppy.sh on osu score pages.

当前为 2014-09-03 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        pp for osu score pages
// @namespace   http://osustats.ppy.sh
// @description shows pp data from osustats.ppy.sh on osu score pages.
// @include     http*://osu.ppy.sh/b/*
// @include     http*://osu.ppy.sh/s/*
// @include     http*://osu.ppy.sh/p/beatmap?b=*
// @include     http*://osu.ppy.sh/p/beatmap?s=*
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_xmlhttpRequest
// @version     2
// ==/UserScript==

 

var requestingPage=false;
var result=null;
var socket=null;
function ShowAlert()
{
	var mapTab = document.getElementsByClassName("beatmapTab active");
	if(mapTab.length==1)
	{
		var mapID = mapTab[0].href.split("/")[4];
		mapID = mapID.split("&")[0];

		mapMode = document.getElementsByClassName("active");
		mapMode = mapMode[mapMode.length-1].href.split("&m=")[1];
	
		GetPage(mapID,mapMode,function(res){
			result = JSON.parse(res);

			var rows,thisImg,username,score,row,pp;

			rows = document.evaluate('//div[@class=\'beatmapListing\']/table/tbody/tr',
			  document,
			  null,
			  XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
			  null);
			rows.snapshotItem(0).children[5].innerHTML="Combo / pp";

			for (var i=1;i<rows.snapshotLength;i++) {
				row = rows.snapshotItem(i);
				username = row.children[4].children[1].innerHTML;
				score = row.children[2].innerHTML.replace(/,/g,'').replace(/<b>/g,'').replace(/<\/b>/g,'');
				pp = GetPpFromUsername(username,score);
				row.children[5].innerHTML += pp; 
			}
		});
	}
}
function GetPpFromUsername(username,score)
{
	for (var i=0;i<result.length;i++) {
		if(username == result[i].name)
		{
			if(score == result[i].score)
			{
				return " / "+(Math.round(result[i].pp * 100) / 100)+"pp";
			}
			return " / N/U";
		}
	}
	return " / N/D";
}
function GetPage(mapID,mapMode,callback) {
	GM_xmlhttpRequest({
		method: "GET",
		url: "http://osustats.ppy.sh/API/beatmap.php?mode=" + mapMode + "&id=" + mapID,
		synchronous: true,
		headers: {
			Referer: location.href
		},
		onload: function(resp) {
			callback(resp.responseText);
		}
	});

}
window.addEventListener('load', function() {
    ShowAlert();
}, false);