dotgrid

Help you choose Loot Bag

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

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