Last active
November 20, 2023 20:56
-
-
Save GavinRay97/e845bed455f0ffb092e793e0317c5375 to your computer and use it in GitHub Desktop.
Hunt Weapon extraction script
This file contains 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
// Script to run on https://huntshowdown.rocks/en/weapons to extract weapon info | |
const meleeVariantNames = [ | |
"Precision", | |
"Deadeye", | |
"Marksman", | |
"Sniper", | |
"Bayonet", | |
"Riposte", | |
"Trauma", | |
"Striker", | |
"Brawler", | |
"Mace", | |
"Talon", | |
"Aperture", | |
"Swift", | |
"Match", | |
"Precision", | |
"Claw", | |
] | |
const weaponProperties = { | |
"damage": "damage", | |
"cycleTime": "cycle_time", | |
"verticalRecoil": "vertical_recoil", | |
"melee": "melee", | |
"heavyMelee": "hmelee", | |
"cost": "cost", | |
"effectiveRange": "effective", | |
"rateOfFire": "fire_rate", | |
"spread": "spread", | |
"reloadSpeed": "reload", | |
"sway": "sway", | |
"muzzleVelocity": "velocity", | |
} | |
const ammoNames = ["compact", "medium", "long", "shotgun"] | |
function extractWeaponInfo() { | |
const weaponEls = document.querySelectorAll(".weapon") | |
const weaponInfo = [] | |
weaponEls.forEach((weaponEl) => { | |
const weaponName = weaponEl.querySelector(".weaponname")?.textContent.trim() | |
const weaponStats = {} | |
Object.entries(weaponProperties).forEach(([key, value]) => { | |
const statElement = weaponEl.querySelector(`.weaponTopLine[data-type="${value}"]`) | |
if (statElement) { | |
const stat = statElement.querySelector("span").textContent.trim() | |
weaponStats[key] = ["cycleTime", "reloadSpeed"].includes(key) ? parseFloat(stat) : parseInt(stat) | |
} | |
}) | |
const imageEls = Array.from(weaponEl.querySelectorAll("div.special > img")) || [] | |
const ammoType = ammoNames.find((it) => imageEls.some((el) => el.src.includes(it))) || "unknown" | |
const isSilenced = weaponName?.includes("Silencer") | |
const hasFMJ = imageEls.some((it) => it.src.includes("fullmetaljacket")) | |
const hasDumDum = imageEls.some((it) => it.src.includes("dumdum")) | |
const hasHighVelocity = imageEls.some((it) => it.src.includes("velocity")) | |
const hasIncendiary = imageEls.some((it) => it.src.includes("incendiary")) | |
const hasSpitzer = imageEls.some((it) => it.src.includes("spitzer")) | |
const hasPoison = imageEls.some((it) => it.src.includes("poison")) | |
const hasSlug = imageEls.some((it) => it.src.includes("slug")) | |
const hasFlechette = imageEls.some((it) => it.src.includes("flechette")) | |
const hasDragonbreath = imageEls.some((it) => it.src.includes("dragon")) | |
const hasPennyshot = imageEls.some((it) => it.src.includes("penny")) | |
const ammoVariantMap = { | |
FMJ: hasFMJ, | |
DUMDUM: hasDumDum, | |
HIGH_VELOCITY: hasHighVelocity, | |
INCENDIARY: hasIncendiary, | |
SPITZER: hasSpitzer, | |
POISON: hasPoison, | |
SLUG: hasSlug, | |
FLECHETTE: hasFlechette, | |
DRAGONBREATH: hasDragonbreath, | |
PENNYSHOT: hasPennyshot, | |
} | |
const ammoVariants = Object.keys(ammoVariantMap).filter((key) => ammoVariantMap[key]) | |
weaponInfo.push({ | |
name: weaponName, | |
ammoType, | |
isSilenced, | |
ammoVariants, | |
stats: weaponStats, | |
}) | |
}) | |
return weaponInfo.sort((a, b) => a.name.localeCompare(b.name)) | |
} | |
function main() { | |
const weapons = extractWeaponInfo() | |
console.log(JSON.stringify(weapons, null, 4)) | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment