Alternative pp data scaling

Shows alternatively scaled pp data on osu!

  1. // ==UserScript==
  2. // @name Alternative pp data scaling
  3. // @namespace http://osu.ppy.sh/u/Kert
  4. // @description Shows alternatively scaled pp data on osu!
  5. // @include http*://osu.ppy.sh/u/*
  6. // @include http*://osu.ppy.sh/p/pp*
  7. // @grant none
  8. // @version 1.1
  9. // ==/UserScript==
  10.  
  11. // Super mega sophisticated formula
  12. // Thanks to FullTablet http://osu.ppy.sh/u/Full_Tablet
  13. function GetScaledPP(pp){
  14. // 20 = 1 / (1 - 0.95)
  15. // the magic number is mathematically justified due to how pp weightnings work
  16. return pp / 20;
  17. }
  18.  
  19. // Profile pages
  20. function ProfileProc(){
  21. // ensure the needed element loaded
  22. var a = null;
  23. while(a === null){
  24. a = document.getElementsByClassName("profileStatLine")[0].getElementsByTagName("b")[0].getElementsByTagName("a")[0];
  25. }
  26.  
  27. var all = document.getElementsByClassName("profileStatLine")[0].getElementsByTagName("b")[0].innerHTML;
  28. var link = document.getElementsByClassName("profileStatLine")[0].getElementsByTagName("b")[0].getElementsByTagName("a")[0].outerHTML;
  29.  
  30. var text = '';
  31. for (var i = link.length+2; i < all.length; i++){
  32. text += all[i];
  33. }
  34. // skip non-players
  35. if(text != "-"){
  36. var arr = text.split('pp');
  37. var pp = arr[0].replace(",", "");
  38. var scaled = GetScaledPP(pp);
  39. var rounded = Math.round(scaled);
  40. var res = link + ": [" + rounded + "] " + arr[0] + "pp" + arr[1];
  41. document.getElementsByClassName("profileStatLine")[0].getElementsByTagName("b")[0].innerHTML = res;
  42. document.getElementsByClassName("profileStatLine")[0].getElementsByTagName("b")[0].setAttribute("title", "Scaled pp: [" + scaled +"]");
  43. }
  44. }
  45.  
  46. // Performance ranking page
  47. function PerformanceProc(){
  48. var tables = document.getElementsByClassName("beatmapListing")[0].getElementsByTagName("tr");
  49. for(var i = 1; i < tables.length; i++){
  50. var curTable = document.getElementsByClassName("beatmapListing")[0].getElementsByTagName("tr")[i];
  51. var old = curTable.getElementsByTagName("td")[4].getElementsByTagName("span")[0].innerHTML;
  52. var arr = old.split('pp');
  53. var pp = arr[0].replace(",", "");
  54. var scaled = GetScaledPP(pp);
  55. var rounded = Math.round(scaled);
  56. var res = "[" + rounded + "] " + arr[0] + "pp";
  57. curTable.getElementsByTagName("td")[4].getElementsByTagName("span")[0].innerHTML = res;
  58. curTable.getElementsByTagName("td")[4].setAttribute("title", "Scaled pp: [" + scaled +"]");
  59. }
  60. }
  61.  
  62. window.addEventListener("load", function(e) {
  63. // Selecting which function to use
  64. if(document.URL.match(/http.:\/\/osu\.ppy\.sh\/u\//i))
  65. ProfileProc();
  66. else
  67. PerformanceProc();
  68. }, false);