|
|
|
||||||||||||||||||||||||
MediaWiki:FeaturedCreatures.js: mudanças entre as edições
Ir para navegação
Ir para pesquisar
| Linha 1: | Linha 1: | ||
$(document).ready(function () { | $(document).ready(function () { | ||
function | $.ajax({ | ||
$.ajax({ | url: 'https://api.tibiadata.com/v3/creatures', dataType: 'json', success: function (res) { | ||
searchCreatureData(res.creatures.boosted, $('#boostedcreature_home_img'), $('#boostedcreature_home_txt')) | |||
} | |||
}) | |||
} | |||
} | $.ajax({ | ||
url: 'https://api.tibiadata.com/v3/boostablebosses', dataType: 'json', success: function (res) { | |||
searchCreatureData(res.boostable_bosses.boosted, $('#boostedboss_home_img'), $('#boostedboss_home_txt')) | |||
} | |||
}) | |||
function searchCreatureData (boosted) { | function searchCreatureData (boosted, targetImg, targetTxt) { | ||
$.ajax({ | $.ajax({ | ||
url: '/index.php?action=raw&title=' + boosted.name, | url: '/index.php?action=raw&title=' + boosted.name, | ||
success: function (data) { | success: function (data) { | ||
if (data.match(/Infobox[_ ]Criatura/)) { | if (data.match(/Infobox[_ ]Criatura/)) { | ||
targetImg.html(`<a href="/wiki/${boosted.name}"><img src="/wiki/Especial:Redirecionar/file/${boosted.name}.gif" alt="${boosted.name}" style="height: 64px;"></a>`) | |||
targetTxt.html(`<a style="color:#FFFFFF; text-decoration:none;" class="plainlinks" href="/wiki/${boosted.name}">${boosted.name}</a>`) | |||
} else { | } else { | ||
fallback(boosted) | fallback(boosted, targetImg, targetTxt) | ||
} | } | ||
}, | }, | ||
error: _ => fallback(boosted) | error: _ => fallback(boosted, targetImg, targetTxt) | ||
}) | }) | ||
} | } | ||
function fallback (boosted) { | function fallback (boosted, targetImg, targetTxt) { | ||
if ( | if (targetImg.children('a').length === 0) { | ||
targetImg.html(`<a href="#"><img src="${boosted.image_url}" alt="${boosted.name}"></a>`) | |||
targetTxt.html(`<a style="color:#FFFFFF; text-decoration:none;" class="plainlinks" href="#">${boosted.name}</a>`) | |||
} | } | ||
} | } | ||
}) | }) | ||
Edição das 22h22min de 4 de agosto de 2022
$(document).ready(function () {
$.ajax({
url: 'https://api.tibiadata.com/v3/creatures', dataType: 'json', success: function (res) {
searchCreatureData(res.creatures.boosted, $('#boostedcreature_home_img'), $('#boostedcreature_home_txt'))
}
})
$.ajax({
url: 'https://api.tibiadata.com/v3/boostablebosses', dataType: 'json', success: function (res) {
searchCreatureData(res.boostable_bosses.boosted, $('#boostedboss_home_img'), $('#boostedboss_home_txt'))
}
})
function searchCreatureData (boosted, targetImg, targetTxt) {
$.ajax({
url: '/index.php?action=raw&title=' + boosted.name,
success: function (data) {
if (data.match(/Infobox[_ ]Criatura/)) {
targetImg.html(`<a href="/wiki/${boosted.name}"><img src="/wiki/Especial:Redirecionar/file/${boosted.name}.gif" alt="${boosted.name}" style="height: 64px;"></a>`)
targetTxt.html(`<a style="color:#FFFFFF; text-decoration:none;" class="plainlinks" href="/wiki/${boosted.name}">${boosted.name}</a>`)
} else {
fallback(boosted, targetImg, targetTxt)
}
},
error: _ => fallback(boosted, targetImg, targetTxt)
})
}
function fallback (boosted, targetImg, targetTxt) {
if (targetImg.children('a').length === 0) {
targetImg.html(`<a href="#"><img src="${boosted.image_url}" alt="${boosted.name}"></a>`)
targetTxt.html(`<a style="color:#FFFFFF; text-decoration:none;" class="plainlinks" href="#">${boosted.name}</a>`)
}
}
})