BorisChenTiers

Library that generates the BorisChen player name to tier map

目前为 2021-09-08 提交的版本。查看 最新版本

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.gf.qytechs.cn/scripts/431916/968458/BorisChenTiers.js

  1. // ==UserScript==
  2. // @name BorisChenTiers
  3. // @namespace BorisChenTiers
  4. // @version 1
  5. // @author https://github.com/William-Bulovas
  6. // @grant GM.xmlHttpRequest
  7. // ==/UserScript==
  8. const getHttp = (url) => {
  9. return new Promise(resolve => {
  10. GM.xmlHttpRequest({
  11. method: "GET",
  12. url: url,
  13. headers: {
  14. "Accept": "text/plain"
  15. },
  16. onload: resolve
  17. });
  18. });
  19. }
  20. const scoring = {
  21. PPR: "PPR",
  22. Standard: "STANDARD",
  23. Half: "HALF"
  24. }
  25.  
  26. const teamNames = {
  27. standard: "standard",
  28. yahoo: "yahoo",
  29. espn: "espn"
  30. }
  31.  
  32. const suffixForScoring = {
  33. "PPR": "-PPR",
  34. "HALF": "-HALF",
  35. "STANDARD": ""
  36. }
  37. const generateTiers = async (scoring, teamNames = teamNames.standard) => {
  38. const tierMap = {};
  39. const wrPromise = getHttp("https://s3-us-west-1.amazonaws.com/fftiers/out/text_WR" + suffixForScoring[scoring] + ".txt")
  40. .then(response => parseTierText(response.responseText))
  41. .then(wrTierMap => Object.assign(tierMap, wrTierMap));
  42. const rbPromise = getHttp("https://s3-us-west-1.amazonaws.com/fftiers/out/text_RB" + suffixForScoring[scoring] + ".txt")
  43. .then(response => parseTierText(response.responseText))
  44. .then(rbTierMap => Object.assign(tierMap, rbTierMap));
  45. const qbPromise = getHttp("https://s3-us-west-1.amazonaws.com/fftiers/out/text_QB.txt")
  46. .then(response => parseTierText(response.responseText))
  47. .then(qbTierMap => Object.assign(tierMap, qbTierMap));
  48. const tePromise = getHttp("https://s3-us-west-1.amazonaws.com/fftiers/out/text_TE" + suffixForScoring[scoring] + ".txt")
  49. .then(response => parseTierText(response.responseText))
  50. .then(teTierMap => Object.assign(tierMap, teTierMap));
  51. const dstPromise = getHttp("https://s3-us-west-1.amazonaws.com/fftiers/out/text_DST.txt")
  52. .then(response => {
  53. if (teamNames === teamNames.yahoo) {
  54. return parseTierText(response.responseText, santizeTeamYahooString);
  55. } else if (teamNames === teamNames.espn) {
  56. return parseTierText(response.responseText, santizeTeamEspnString);
  57. }
  58. return parseTierText(response.responseText)
  59. })
  60. .then(dstTierMap => Object.assign(tierMap, dstTierMap));
  61. const kPromise = getHttp("https://s3-us-west-1.amazonaws.com/fftiers/out/text_K.txt")
  62. .then(response => parseTierText(response.responseText))
  63. .then(kTierMap => Object.assign(tierMap, kTierMap));
  64. await Promise.all([wrPromise, rbPromise, qbPromise, tePromise, dstPromise, kPromise]);
  65. return tierMap;
  66. }
  67. const parseTierText = (rawStr, sanitize = santizeString) => {
  68. const tierMap = {};
  69. const tiers = rawStr.split(/\r?\n/);
  70. tiers.forEach((tierStr, tier) => {
  71. if (tierStr != "") {
  72. const playerStr = tierStr.substring(tierStr.indexOf(":") + 2);
  73. const players = playerStr.split(', ');
  74. players.forEach((player) => {
  75. tierMap[sanitize(player)] = tier;
  76. });
  77. }
  78. });
  79. return tierMap;
  80. }
  81. const santizeString = (str) => {
  82. if (str === "Darrell Henderson") {
  83. str = "darrell henderson jr";
  84. }
  85. return str.toLowerCase()
  86. .replace(/\./g, '')
  87. .replace(/'/g, '')
  88. .replace(' ii', '');
  89. };
  90. const santizeTeamYahooString = (str) => {
  91. str = str.substring(0, str.lastIndexOf(" "));
  92. if (str === "Washington Football") {
  93. str = "Washington";
  94. }
  95. return santizeString(str);
  96. }
  97.  
  98. const santizeTeamEspnString = (str) => {
  99. str = str.substring(str.lastIndexOf(" "), str.length);
  100. if (str === "Team") {
  101. str = "Washington";
  102. }
  103. return santizeString(str);
  104. }
  105.  
  106.  

QingJ © 2025

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