Skip to content

Instantly share code, notes, and snippets.

@VitorLuizC
Created February 13, 2024 21:55
Show Gist options
  • Save VitorLuizC/ab127dcd9838ccf71e241a40df06937a to your computer and use it in GitHub Desktop.
Save VitorLuizC/ab127dcd9838ccf71e241a40df06937a to your computer and use it in GitHub Desktop.
Download Tibia bosses information from their site.
function download(fileBlob, fileName) {
const anchor = window.document.createElement('a')
anchor.rel = 'noreferrer noopener'
anchor.href = window.URL.createObjectURL(fileBlob)
anchor.target = '_blank'
anchor.download = fileName
window.document.body.appendChild(anchor)
anchor.click()
window.setTimeout(() => window.document.body.removeChild(anchor), 1_000)
}
const BOSSES_SELECTOR = '#boostablebosses .Creatures > div'
const bosses = []
window.document.querySelectorAll(BOSSES_SELECTOR).forEach((container) => {
const name = container.querySelector('div')
const image = container.querySelector('img')
window
.fetch(image.src)
.then((response) => response.blob())
.then((blob) => download(blob, image.src.split('/').at(-1)))
bosses.push({
name: name.textContent.trim(),
cooldown: 1_000 * 60 * 60 * 20,
image_uri: '/image/boss/'.concat(image.src.split('/').at(-1)),
})
})
download(
new Blob([JSON.stringify(bosses, null, 2)], {
type: 'application/json',
}),
'bosses.json',
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment