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