LootRare

Help you choose Loot Bag

  1. // ==UserScript==
  2. // @name LootRare
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.38
  5. // @description Help you choose Loot Bag
  6. // @author dashuo
  7. // @match https://opensea.io/collection/lootproject
  8. // @match https://opensea.io/assets/lootproject?*
  9. // @match https://opensea.io/collection/lootproject?*
  10. // @icon https://www.google.com/s2/favicons?domain=opensea.io
  11. // @grant GM_getResourceText
  12. // @resource DATALootRare https://raw.githubusercontent.com/Anish-Agnihotri/dhof-loot/master/output/rare.json
  13. // @resource DATALootItems https://raw.githubusercontent.com/Anish-Agnihotri/dhof-loot/master/output/occurences.json
  14. // @resource DATALootBags https://raw.githubusercontent.com/ruyan768/loot-tools/main/loot.json
  15. // ==/UserScript==
  16.  
  17. var dataRare = GM_getResourceText('DATALootRare')
  18. var dataItems = GM_getResourceText('DATALootItems')
  19. var dataBags = GM_getResourceText('DATALootBags')
  20. var gLootRare = JSON.parse(dataRare);
  21. var gLootItems = JSON.parse(dataItems);
  22. var gLootBags = JSON.parse(dataBags);
  23.  
  24.  
  25. var inited = false;
  26.  
  27. function findRareByLootId(lootid) {
  28. var index = gLootRare.findIndex(function (x) { return x.lootId === lootid;} );
  29. return gLootRare[index];
  30. }
  31.  
  32. function findBagByLootId(lootid) {
  33. var index = gLootBags.findIndex(function (x) { return x.id === lootid;} );
  34. return gLootBags[index];
  35. }
  36.  
  37. function parseLootId(bagName) {
  38. var paragraph = bagName;
  39. var regex = /Bag #(\d+)/;
  40. var found = paragraph.match(regex);
  41. return parseInt(found[1]);
  42. }
  43.  
  44. function getRarity(name) {
  45. var result = gLootItems.hasOwnProperty(name);
  46. if (!result) {
  47. return 0;
  48. }
  49. return gLootItems[name];
  50. }
  51.  
  52. function rarityCSS(value) {
  53. let types = ["common", "uncommon", "rare", "epic", "legendary", "mythic"];
  54. if (value == 1) {
  55. return "mythic";
  56. }
  57. else if (value <= 10) {
  58. return "legendary";
  59. }
  60. return "base"
  61. }
  62.  
  63. function genSVG(bag) {
  64. let parts = ""
  65. let y = 20;
  66. parts = '<svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMinYMin meet" viewBox="0 0 350 350"><style>.base { fill: white; font-family: serif; font-size: 14px; } .legendary { fill: rgb(248, 183, 62); font-family: serif; font-size: 14px; } .mythic { fill: rgb(255, 68, 183); font-family: serif; font-size: 14px; }</style><rect width="100%" height="100%" fill="black" />';
  67. bag.items.forEach(itemname => {
  68. let rarity = getRarity(itemname);
  69. parts += '<text x="10" y="'+ y +'" class="' + rarityCSS(rarity) + '">';
  70. parts += itemname;
  71. parts += '</text>';
  72. y += 20;
  73. });
  74. parts += '<text x="10" y="280" class="base">###PATCHED###</text>';
  75. parts += '</svg>';
  76. return parts;
  77. }
  78.  
  79. function onwheelevent(event) {
  80. event.preventDefault();
  81.  
  82.  
  83. var elements = document.getElementsByClassName("AssetCardFooter--name");
  84. for (var i = 0; i < elements.length; i++) {
  85. elements[i].style.color = "red";
  86. var bagLabel = elements[i].innerText;
  87. var lootid = parseLootId(bagLabel);
  88. var loot = findRareByLootId(lootid);
  89. var bag = findBagByLootId(lootid);
  90. var staticSVG = genSVG(bag);
  91.  
  92. var encodedData = btoa(staticSVG);
  93. var base64SvgImage = 'data:image/svg+xml;base64,' + encodedData;
  94. var descDIV = elements[i].parentElement.parentElement.parentElement;
  95. var girdDIV = descDIV.parentElement;
  96. var imgsvg = girdDIV.getElementsByClassName('Image--image')[0];
  97.  
  98. imgsvg.src = base64SvgImage;
  99.  
  100. var annotations = descDIV.getElementsByClassName('AssetCardFooter--annotations');
  101. if (annotations !== undefined) {
  102. var parentItem = annotations[0];
  103. var result = parentItem.getElementsByClassName('lootrare-label');
  104. if (result.length === 0) {
  105. var newNode = document.createElement('div');
  106. newNode.className = 'lootrare-label';
  107. newNode.innerHTML = "<div class='lootrare-label'> score:" + loot.score + " rarest:" + loot.rarest + " </div>";
  108. parentItem.prepend(newNode);
  109. }
  110. }
  111. }
  112. }
  113.  
  114. (function() {
  115. 'use strict';
  116.  
  117. if (document.readyState == "complete" || document.readyState == "loaded" || document.readyState == "interactive") {
  118. document.addEventListener('wheel', onwheelevent);
  119. }
  120. })();