Created
October 12, 2022 12:15
-
-
Save ceving/fc73d25a18b0b441fc29dffaee988424 to your computer and use it in GitHub Desktop.
Fetch Diablo 2 Terror Zone
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
#! /usr/bin/node | |
const jsdom = require('jsdom') | |
const { JSDOM } = jsdom; | |
(async () => { | |
var dom; | |
if (process.argv.length > 2) { | |
dom = await JSDOM.fromFile (process.argv[2]); | |
} else { | |
let options = {}; | |
if (process.env.https_proxy) { | |
options = { | |
resources: new jsdom.ResourceLoader ({ | |
proxy: process.env.https_proxy | |
}) | |
}; | |
dom = await JSDOM.fromURL ('https://d2runewizard.com/terror-zone-tracker', | |
options); | |
} | |
} | |
const path = 'html body div main div div div div div h2'; | |
const nodes = Array.from (dom.window.document | |
.querySelector (path) | |
.parentElement.childNodes); | |
const zone = nodes[0].textContent; | |
const names = {f: 'fire', | |
c: 'cold', | |
ph: 'physical', | |
m: 'magical', | |
l: 'lightning', | |
p: 'poison'}; | |
const immunities = [...nodes[1].querySelectorAll ('span span')] | |
.slice (1) | |
.map (node => names[node.textContent]) | |
.sort () | |
.join (', '); | |
const super_unique = [...nodes[2].childNodes] | |
.slice (1) | |
.map (node => node.textContent.trim()) | |
.reduce ((acc, val) => val === '' ? acc : acc.concat (val), []) | |
.join (''); | |
const boss_packs = [...nodes[3].childNodes] | |
.slice (1) | |
.map (node => node.textContent.trim()) | |
.reduce ((acc, val) => val === '' ? acc : acc.concat (val), []) | |
.join (' '); | |
const remaining = nodes[4].textContent; | |
process.stdout.write (`Zone: ${zone} | |
Immunities: ${immunities} | |
Super Unique: ${super_unique} | |
Boss Packs: ${boss_packs} | |
Remaining: ${remaining} | |
`); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment