adam-bomb-squad

Help you choose Loot Bag

  1. // ==UserScript==
  2. // @name adam-bomb-squad
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.4
  5. // @description Help you choose Loot Bag
  6. // @author dashuo
  7. // @match https://opensea.io/collection/adam-bomb-squad
  8. // @match https://opensea.io/assets/adam-bomb-squad?*
  9. // @match https://opensea.io/collection/adam-bomb-squad?*
  10. // @match https://opensea.io/account
  11. // @match https://opensea.io/assets*
  12. // @icon https://www.google.com/s2/favicons?domain=opensea.io
  13. // @grant GM_getResourceText
  14. // @resource DATALootRare https://raw.githubusercontent.com/a-dwarf/loot/main/adam-bomb-squad.json
  15. // @resource DATALootItems https://raw.githubusercontent.com/a-dwarf/loot/main/output/fatales/occurences.json
  16. // @resource DATALootBags https://raw.githubusercontent.com/a-dwarf/loot/main/output/fatales/fateles_loot.json
  17. // ==/UserScript==
  18.  
  19. var dataRare = GM_getResourceText('DATALootRare')
  20. var dataItems = GM_getResourceText('DATALootItems')
  21. var dataBags = GM_getResourceText('DATALootBags')
  22. var gLootRare = JSON.parse(dataRare);
  23. var gLootItems = JSON.parse(dataItems);
  24. var gLootBags = JSON.parse(dataBags);
  25.  
  26.  
  27. var inited = false;
  28.  
  29. function findRareByLootId(lootid) {
  30. var index = gLootRare.findIndex(function (x) { return x.lootId === lootid;} );
  31. return gLootRare[index];
  32. }
  33.  
  34. function findBagByLootId(lootid) {
  35. var index = gLootBags.findIndex(function (x) { return x.id === lootid;} );
  36. return gLootBags[index];
  37. }
  38.  
  39. function parseLootId(bagName) {
  40. var paragraph = bagName;
  41. var regex = /Meebit #(\d+)/;
  42. var found = paragraph.match(regex);
  43. return found[1];
  44. }
  45.  
  46. function getRarity(name) {
  47. var result = gLootItems.hasOwnProperty(name);
  48. if (!result) {
  49. return 0;
  50. }
  51. return gLootItems[name];
  52. }
  53.  
  54. function rarityCSS(value) {
  55. let types = ["common", "uncommon", "rare", "epic", "legendary", "mythic"];
  56. if (value == 1) {
  57. return "mythic";
  58. }
  59. else if (value <= 10) {
  60. return "legendary";
  61. }
  62. return "base"
  63. }
  64.  
  65. function genSVG(bag) {
  66. let parts = ""
  67. let y = 20;
  68. 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" />';
  69. bag.items.forEach(itemname => {
  70. let rarity = getRarity(itemname);
  71. parts += '<text x="10" y="'+ y +'" class="' + rarityCSS(rarity) + '">';
  72. parts += itemname;
  73. parts += '</text>';
  74. y += 20;
  75. });
  76. parts += '<text x="10" y="280" class="base">###PATCHED###</text>';
  77. parts += '</svg>';
  78. return parts;
  79. }
  80.  
  81. window.onload=function(){
  82. var annotations1 = document.getElementsByClassName('item--media-frame');
  83. var parentItem1 = annotations1[0];
  84. var lootid1 = window.location.pathname.split('/')[3];
  85. var loot1 = findRareByLootId(lootid1);
  86. var newNode1 = document.createElement('div');
  87. newNode1.className = 'lootrare-label';
  88. newNode1.innerHTML = "<div class='lootrare-label' style='color: blue'> score:" + Number(loot1.score).toFixed(2) + " rarest:" + loot1.rarest + " </div>";
  89. parentItem1.prepend(newNode1);
  90. };
  91.  
  92. function onwheelevent(event) {
  93. event.preventDefault();
  94.  
  95.  
  96. var elements = document.getElementsByClassName("AssetCardFooter--name");
  97. for (var i = 0; i < elements.length; i++) {
  98. elements[i].style.color = "red";
  99. var bagLabel = elements[i].innerText;
  100. // var lootid = parseLootId(bagLabel);
  101. var loot = findRareByLootId(bagLabel);
  102.  
  103. var descDIV = elements[i].parentElement.parentElement.parentElement;
  104.  
  105. var annotations = descDIV.getElementsByClassName('AssetCardFooter--collection-name');
  106. if (annotations !== undefined) {
  107. var parentItem = annotations[0];
  108. var result = parentItem.getElementsByClassName('lootrare-label');
  109. if (result.length === 0) {
  110. var newNode = document.createElement('div');
  111. newNode.className = 'lootrare-label';
  112. newNode.innerHTML = "<div class='lootrare-label' style='color: red'> score:" + Number(loot.score).toFixed(2) + " rarest:" + loot.rarest + " </div>";
  113. parentItem.prepend(newNode);
  114. }
  115. }
  116. }
  117. }
  118.  
  119. (function() {
  120. 'use strict';
  121.  
  122. if (document.readyState == "complete" || document.readyState == "loaded" || document.readyState == "interactive") {
  123. document.addEventListener('wheel', onwheelevent);
  124. }
  125. })();