Last active
September 5, 2021 10:45
-
-
Save WunGCQ/f1b756c7d9fc03a87630fe98aa453f5a to your computer and use it in GitHub Desktop.
loot rare list v0.4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name LootRare | |
// @namespace http://tampermonkey.net/ | |
// @version 0.40 | |
// @description Help you choose Loot Bag | |
// @author dashuo | |
// @match https://opensea.io/collection/lootproject | |
// @match https://opensea.io/assets/lootproject?* | |
// @match https://opensea.io/collection/lootproject?* | |
// @icon https://www.google.com/s2/favicons?domain=opensea.io | |
// @grant GM_getResourceText | |
// @resource DATALootRare https://raw.githubusercontent.com/Anish-Agnihotri/dhof-loot/master/output/rare.json | |
// @resource DATALootItems https://raw.githubusercontent.com/Anish-Agnihotri/dhof-loot/master/output/occurences.json | |
// @resource DATALootBags https://raw.githubusercontent.com/ruyan768/loot-tools/main/loot.json | |
// ==/UserScript== | |
var dataRare = GM_getResourceText('DATALootRare') | |
var dataItems = GM_getResourceText('DATALootItems') | |
var dataBags = GM_getResourceText('DATALootBags') | |
var gLootRare = JSON.parse(dataRare); | |
var gLootItems = JSON.parse(dataItems); | |
var gLootBags = JSON.parse(dataBags); | |
var inited = false; | |
function findRareByLootId(lootid) { | |
var index = gLootRare.findIndex(function (x) { return x.lootId === lootid;} ); | |
return gLootRare[index]; | |
} | |
function findBagByLootId(lootid) { | |
var index = gLootBags.findIndex(function (x) { return x.id === lootid;} ); | |
return gLootBags[index]; | |
} | |
function parseLootId(bagName) { | |
var paragraph = bagName; | |
var regex = /Bag #(\d+)/; | |
var found = paragraph.match(regex); | |
return parseInt(found[1]); | |
} | |
function getRarity(name) { | |
var result = gLootItems.hasOwnProperty(name); | |
if (!result) { | |
return 0; | |
} | |
return gLootItems[name]; | |
} | |
const rareLevel = [ | |
[1, "mythic"], | |
[9, "legendary"], | |
[100, "epic"], | |
[357, "rare"], | |
[374, "uncommon"], | |
[65535, "common"], | |
]; | |
function rarityCSS(value) { | |
for(var i = 0; i< rareLevel.length; i++) { | |
var min = rareLevel[i][0]; | |
if(value <= min) return rareLevel[i][1]; | |
} | |
} | |
function genSVG(bag) { | |
let parts = ""; | |
let y = 20; | |
parts = `<svg xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMinYMin meet" viewBox="0 0 350 210"> | |
<style> | |
.base { fill: white; font-family: serif; font-size: 14px; } | |
.id { fill: rgb(96,96,96); font-family: Consolas; font-style: italic; font-size: 14px; } | |
.legendary { fill: rgb(248 183 62); font-family: serif; font-size: 14px; } | |
.uncommon { fill: rgb(47 209 17); font-family: serif; font-size: 14px; } | |
.common { fill: white; font-family: serif; font-size: 14px; } | |
.rare { fill: rgb(46 130 255); font-family: serif; font-size: 14px; } | |
.epic { fill: rgb(193 60 255); font-family: serif; font-size: 14px; } | |
.mythic { fill: rgb(250 98 192); font-family: serif; font-size: 14px; } | |
</style> | |
<rect width="100%" height="100%" fill="black" />`; | |
bag.items.forEach((itemname) => { | |
let rarity = getRarity(itemname); | |
parts += '<text x="10" y="' + y + '" class="' + rarityCSS(rarity) + '">'; | |
parts += itemname; | |
parts += ` [${rarity}]`; | |
parts += "</text>"; | |
y += 20; | |
}); | |
parts += `<text x="10" y="190" class="id">Bag #${bag.id} </text>`; | |
parts += "</svg>"; | |
return parts; | |
} | |
function onwheelevent(event) { | |
event.preventDefault(); | |
var elements = document.getElementsByClassName("AssetCardFooter--name"); | |
for (var i = 0; i < elements.length; i++) { | |
elements[i].style.color = "red"; | |
var bagLabel = elements[i].innerText; | |
var lootid = parseLootId(bagLabel); | |
var loot = findRareByLootId(lootid); | |
var bag = findBagByLootId(lootid); | |
var staticSVG = genSVG(bag); | |
var encodedData = btoa(staticSVG); | |
var base64SvgImage = 'data:image/svg+xml;base64,' + encodedData; | |
var descDIV = elements[i].parentElement.parentElement.parentElement; | |
var girdDIV = descDIV.parentElement; | |
var imgsvg = girdDIV.getElementsByClassName('Image--image')[0]; | |
imgsvg.src = base64SvgImage; | |
var imageWrap = descDIV.previousSibling; | |
imageWrap.style.height = "auto"; | |
var annotations = descDIV.getElementsByClassName('AssetCardFooter--annotations'); | |
if (annotations !== undefined) { | |
var parentItem = annotations[0]; | |
var result = parentItem.getElementsByClassName('lootrare-label'); | |
if (result.length === 0) { | |
var newNode = document.createElement('div'); | |
newNode.className = 'lootrare-label'; | |
newNode.innerHTML = "<div class='lootrare-label'> score:" + loot.score + " rarest:" + loot.rarest + " </div>"; | |
parentItem.prepend(newNode); | |
} | |
} | |
} | |
} | |
(function() { | |
'use strict'; | |
if (document.readyState == "complete" || document.readyState == "loaded" || document.readyState == "interactive") { | |
document.addEventListener('wheel', onwheelevent); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment