osu top ranks data adder

Adds beatmap difficulty data/images/sound previews to user top ranks

  1. // ==UserScript==
  2. // @name osu top ranks data adder
  3. // @namespace
  4. // @version 0.1
  5. // @description Adds beatmap difficulty data/images/sound previews to user top ranks
  6. // @author Piotrekol
  7. // @match *://osu.ppy.sh/u/*
  8. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  9. // @grant GM_xmlhttpRequest
  10. // ==/UserScript==
  11. /* jshint -W097 */
  12. 'use strict';
  13. //==============================
  14. //==============================
  15. //==============================
  16. var YOUR_OSU_API_KEY = "FILL WITH YOUR KEY THERE";
  17. //==============================
  18. //==============================
  19. //==============================
  20. //Do not edit below unless you know what you are doing
  21.  
  22. var imageField = "<td width=\"61\">\
  23. <a href=\"#\" onclick=\"playBeatmapPreview({0}); return false;\">\
  24. <img height=\"45\" src=\"https://b.ppy.sh/thumb/{0}.jpg\">\
  25. </a>\
  26. </td>";
  27. var dataField = "</br>\
  28. <b>AR</b> {0}"+
  29. " <b>CS</b> {1}"+
  30. " <b>OD</b> {2}"+
  31. " <b>HP</b> {3}"+
  32. " ({4}<div class=\"starfield\" style=\"width:14px; display:inline-block;\"><div class=\"active\" style=\"width:14px\"></div></div>)";
  33. var useTest=false;
  34. if(useTest){
  35. var highlightScore = function(LookFor,node){
  36. if(node.text().indexOf(LookFor) > -1)
  37. node.css({
  38. "background-color": "#B0C4DE"
  39. });
  40. }
  41. }
  42.  
  43. function createObserver(target,cfg,nodeCallback){
  44. var observer = new MutationObserver(function( mutations ) {
  45. mutations.forEach(function( mutation ) {
  46. var newNodes = mutation.addedNodes;
  47. if( newNodes !== null ) {
  48. var $nodes = $( newNodes );
  49. $nodes.each(function() {
  50. nodeCallback($(this));
  51. });
  52. }
  53. });
  54. });
  55. try{
  56. observer.observe(target, cfg);
  57. }catch(e){}
  58. }
  59.  
  60.  
  61. function run(){
  62. var target_top = $( "#leader" )[0];
  63. var target_fav = $("#beatmaps")[0];
  64. createObserver(target_top,{
  65. childList: true,
  66. subtree: true
  67. },function(node){
  68. var node = node.find(".h b a[href]")[0];
  69.  
  70. if (typeof node != 'undefined')
  71. {
  72. var mapID = node.attributes.href.value.split("/")[2].split("?")[0];
  73. GetPage("https://osu.ppy.sh/api/get_beatmaps?k="+YOUR_OSU_API_KEY+"&b="+mapID,0,function(data){
  74. data = JSON.parse(data);
  75. $(node.parentNode.parentNode.parentNode.parentNode).prepend(imageField.format(data[0].beatmapset_id));
  76. $(node.parentNode.parentNode).append(dataField.format(data[0].diff_approach,data[0].diff_size,
  77. data[0].diff_overall,data[0].diff_drain,(Math.round(data[0].difficultyrating*100)/100)));
  78. if(useTest){
  79. highlightScore("HR",$(node.parentNode.parentNode.parentNode.parentNode));
  80. }
  81. });
  82. }
  83. });
  84. }
  85.  
  86. function GetPage(url,retryNumber,callback) {
  87. GM_xmlhttpRequest({
  88. method: "GET",
  89. url: url,
  90. synchronous: false,
  91. timeout: 10000,
  92. headers: {
  93. Referer: location.href
  94. },
  95. onload: function(resp) {
  96. callback(resp.responseText);
  97. },
  98. ontimeout: function() {
  99. if(retryNumber<1){
  100. retryNumber++;
  101. setTimeout(function(){
  102. GetPage(url,retryNumber,callback);
  103. },1500);
  104. }else{
  105. callback(null);
  106. }
  107. }
  108. });
  109. }
  110. if (!String.prototype.format) {
  111. String.prototype.format = function() {
  112. var args = arguments;
  113. return this.replace(/{(\d+)}/g, function(match, number) {
  114. return typeof args[number] != 'undefined'
  115. ? args[number]
  116. : match
  117. ;
  118. });
  119. };
  120. }
  121.  
  122. run();

QingJ © 2025

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