dotgrid

Help you choose Loot Bag

  1. // ==UserScript==
  2. // @name dotgrid
  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/art-blocks-factory
  8. // @match https://opensea.io/assets/art-blocks-factory?*
  9. // @match https://opensea.io/collection/art-blocks-factory?*
  10. // @icon https://www.google.com/s2/favicons?domain=opensea.io
  11. // @grant GM_getResourceText
  12. // @resource DATALootRare https://raw.githubusercontent.com/a-dwarf/loot/main/dotgrid.json
  13. // @resource DATALootItems https://raw.githubusercontent.com/a-dwarf/loot/main/output/fatales/occurences.json
  14. // @resource DATALootBags https://raw.githubusercontent.com/a-dwarf/loot/main/output/fatales/fateles_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 === (115000000 + Number(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 = /Dot Grid #(\d+)/;
  40. var found = paragraph.match(regex);
  41. return 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. console.log(loot)
  90.  
  91. var descDIV = elements[i].parentElement.parentElement.parentElement;
  92.  
  93. var annotations = descDIV.getElementsByClassName('AssetCardFooter--collection-name');
  94. if (annotations !== undefined) {
  95. var parentItem = annotations[0];
  96. var result = parentItem.getElementsByClassName('lootrare-label');
  97. if (result.length === 0) {
  98. var newNode = document.createElement('div');
  99. newNode.className = 'lootrare-label';
  100. newNode.innerHTML = "<div class='lootrare-label' style='color: red'> score:" + Number(loot.score).toFixed(2) + " rarest:" + loot.rarest + " </div>";
  101. parentItem.prepend(newNode);
  102. }
  103. }
  104. }
  105. }
  106.  
  107. (function() {
  108. 'use strict';
  109.  
  110. if (document.readyState == "complete" || document.readyState == "loaded" || document.readyState == "interactive") {
  111. document.addEventListener('wheel', onwheelevent);
  112. }
  113. })();