pp for osu score pages

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

当前为 2014-08-31 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name pp for osu score pages
  3. // @namespace http://osustats.ppy.sh
  4. // @description shows pp data from osustats.ppy.sh on osu score pages.
  5. // @include http*://osu.ppy.sh/b/*
  6. // @include http*://osu.ppy.sh/s/*
  7. // @include http*://osu.ppy.sh/p/beatmap?b=*
  8. // @grant GM_setValue
  9. // @grant GM_getValue
  10. // @grant GM_xmlhttpRequest
  11. // @version 1
  12. // ==/UserScript==
  13.  
  14.  
  15. var requestingPage=false;
  16. var result=null;
  17. function ShowAlert()
  18. {
  19. var mapTab = document.getElementsByClassName("beatmapTab active");
  20. if(mapTab.length==1)
  21. {
  22. var split = mapTab[0].href.split("/")[4];
  23. mapID = split.split("&")[0];
  24. GetPage(mapID,function(res){
  25. result = JSON.parse(res);
  26.  
  27. var rows,thisImg,username,score,row,pp;
  28.  
  29. rows = document.evaluate('//div[@class=\'beatmapListing\']/table/tbody/tr',
  30. document,
  31. null,
  32. XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
  33. null);
  34. rows.snapshotItem(0).children[5].innerHTML="Combo / pp";
  35.  
  36. for (var i=1;i<rows.snapshotLength;i++) {
  37. row = rows.snapshotItem(i);
  38. username = row.children[4].children[1].innerHTML;
  39. score = row.children[2].innerHTML.replace(/,/g,'').replace(/<b>/g,'').replace(/<\/b>/g,'');
  40. pp = GetPpFromUsername(username,score);
  41. if(pp!=null)
  42. { if(pp!="s")
  43. row.children[5].innerHTML += " / "+(Math.round(pp * 100) / 100)+"pp";
  44. else
  45. row.children[5].innerHTML += " / N/U";
  46. }
  47. else
  48. row.children[5].innerHTML += " / N/D";
  49. }
  50. });
  51. }
  52. }
  53. function GetPpFromUsername(username,score)
  54. {
  55. for (var i=0;i<result.length;i++) {
  56. if(username == result[i].name)
  57. {
  58. if(score == result[i].score)
  59. {
  60. return result[i].pp;
  61. }
  62. return "s";
  63. }
  64. }
  65. return null;
  66. }
  67. function GetPage(mapID,callback) {
  68. GM_xmlhttpRequest({
  69. method: "GET",
  70. url: "http://osustats.ppy.sh/API/beatmap.php?mode=0&id=" + mapID,
  71. synchronous: true,
  72. headers: {
  73. Referer: location.href
  74. },
  75. onload: function(resp) {
  76. callback(resp.responseText);
  77. }
  78. });
  79.  
  80. }
  81. window.addEventListener('load', function() {
  82. ShowAlert();
  83. }, false);