Sleeper.com - FFL - Output Weekly Median.

Add week Median to league screen on Sleeper.com.

当前为 2024-10-17 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Sleeper.com - FFL - Output Weekly Median.
  3. // @description Add week Median to league screen on Sleeper.com.
  4. // @version 1.0.0
  5. // @namespace http://jbout.in/
  6. // @author Jeremy 'HLVE'
  7. // @match *://sleeper.com/leagues/*/*
  8. // @require https://code.jquery.com/jquery-1.9.1.min.js
  9. // @grant GM_setValue
  10. // @grant GM_getValue
  11. // @grant GM_addStyle
  12. // ==/UserScript==
  13.  
  14. $(window).on("load popstate", function (event) {
  15. tabIDs();
  16. if (window.location.pathname.split('/')[3].indexOf("league") != -1) {
  17. var medianValue = calculateMedian();
  18. }
  19.  
  20. $(document).on('click touchend', '#tabLeague', function () {
  21. setTimeout(function () {
  22. var medianValue = calculateMedian();
  23. }, 150);
  24. });
  25. });
  26.  
  27. function tabIDs() {
  28. const tabEl = $("div.center-tab-selector > div.item-tab"),
  29. matchupTab = $("div.center-tab-selector > div.item-tab:contains('MATCHUP')"),
  30. teamTab = $("div.center-tab-selector > div.item-tab:contains('TEAM')"),
  31. leagueTab = $("div.center-tab-selector > div.item-tab:contains('LEAGUE')"),
  32. playersTab = $("div.center-tab-selector > div.item-tab:contains('PLAYERS')"),
  33. trendTab = $("div.center-tab-selector > div.item-tab:contains('TREND')"),
  34. tradeTab = $("div.center-tab-selector > div.item-tab:contains('TRADES')"),
  35. scoreTab = $("div.center-tab-selector > div.item-tab:contains('SCORES')");
  36.  
  37. setTimeout(function () {
  38. $(matchupTab).attr('id', 'tabMatchup');
  39. $(teamTab).attr('id', 'tabTeam');
  40. $(leagueTab).attr('id', 'tabLeague');
  41. $(playersTab).attr('id', 'tabPlayers');
  42. $(trendTab).attr('id', 'tabTrending');
  43. $(tradeTab).attr('id', 'tabTrades');
  44. $(scoreTab).attr('id', 'tabScores');
  45. }, 35);
  46. }
  47.  
  48. function calculateMedian() {
  49. var matchupTitleContainer = $(".league-tab-container .title").first(),
  50. scoreContainer = $("div.league-matchups div.roster-score-and-projection-matchup div.score"),
  51. numbers = [];
  52.  
  53. $(scoreContainer).each(function () {
  54. var value = parseFloat($(this).text());
  55. if (!isNaN(value)) {
  56. numbers.push(value);
  57. }
  58. });
  59.  
  60. // Sort the scores in ascending order
  61. numbers.sort(function (a, b) {
  62. return a - b;
  63. });
  64.  
  65. // Calculate the median
  66. var median;
  67. var len = numbers.length;
  68. if (len === 0) {
  69. median = 0; // If no numbers found, median is 0
  70. } else if (len % 2 === 1) {
  71. median = numbers[Math.floor(len / 2)];
  72. } else {
  73. var mid1 = numbers[len / 2 - 1];
  74. var mid2 = numbers[len / 2];
  75. median = (mid1 + mid2) / 2;
  76. }
  77.  
  78. var calcMedian = Math.ceil(median * 100) / 100;
  79.  
  80. // Round up to the next full decimal place.
  81. if (!$(".league-panel-header .post-draft-league-header .name").text().includes('Guillotine')) {
  82. $(matchupTitleContainer).append(' (<b>Weekly Median</b>: ' + calcMedian + ')');
  83. }
  84.  
  85. // $("div.matchup-row div.roster-score-and-projection-matchup div.score").each(
  86. // function () {
  87. // const scoreText = $(this).text().trim();
  88. // if (scoreText > calcMedian) {
  89. // $(this).addClass('score-over-median');
  90. // $(this).append('<b class="score-over-median">☑</b>');
  91. // }
  92. // }
  93. // );
  94. }