MediaWiki:Common.js: Diferență între versiuni
m |
m |
||
Linia 43: | Linia 43: | ||
if (lootItems) { | if (lootItems) { | ||
lootItems.forEach(function(item) { | lootItems.forEach(function(item) { | ||
− | var textMatch = item.match(/\|\s*([^}]+)\s*\}\}/); | + | var textMatch = item.match(/\|\s*([^|}]+)\s*\}\}/); |
if (textMatch) { | if (textMatch) { | ||
var lootText = textMatch[1].trim(); | var lootText = textMatch[1].trim(); | ||
if (lootText) { | if (lootText) { | ||
var li = document.createElement('li'); | var li = document.createElement('li'); | ||
− | + | var link = document.createElement('a'); | |
+ | link.textContent = lootText; | ||
+ | link.href = 'https://ro-wiki.metin2.gameforge.com/index.php/' + encodeURIComponent(lootText); | ||
+ | link.target = '_blank'; | ||
+ | li.appendChild(link); | ||
lootList.appendChild(li); | lootList.appendChild(li); | ||
} | } | ||
Linia 67: | Linia 71: | ||
} | } | ||
}) | }) | ||
+ | .catch(function(error) { | ||
+ | console.error('Error:', error); | ||
+ | }); | ||
} | } | ||
Versiunea de la data 22 august 2024 12:04
(function () {
// Load GDPR Cookie Script
var req = new XMLHttpRequest();
req.addEventListener('load', function (ev) {
if (this.status >= 200 && this.status < 300) {
var data = JSON.parse(this.responseText);
if (data.hasOwnProperty('version')) {
var gdpr = document.createElement("script");
gdpr.src = "https://s3-static.geo.gfsrv.net/cookiebanner/" + data.version + "/cookie.min.js";
document.head.appendChild(gdpr);
}
}
});
req.open('GET', "https://s3-static.geo.gfsrv.net/cookiebanner/version.json");
req.send();
})();
(function () {
mw.hook('wikipage.content').add(function() {
function showLoot(monster) {
var lootList = document.getElementById('loot-list');
if (!lootList) return;
lootList.innerHTML = '';
var apiUrl = 'https://ro-wiki.metin2.gameforge.com/api.php?action=parse&page=' + encodeURIComponent(monster) + '&prop=wikitext&format=json&origin=*';
fetch(apiUrl)
.then(function(response) {
if (!response.ok) {
throw new Error('Network response was not ok: ' + response.statusText);
}
return response.json();
})
.then(function(data) {
if (data.parse && data.parse.wikitext) {
var wikitext = data.parse.wikitext['*'];
var weapondropsMatch = wikitext.match(/\|Weapondrops\s*=\s*([\s\S]*?)(?=\n\|)/);
if (weapondropsMatch) {
var weapondrops = weapondropsMatch[1].trim();
var lootItems = weapondrops.match(/\{\{Ti\|[^}]+\}\}/g);
if (lootItems) {
lootItems.forEach(function(item) {
var textMatch = item.match(/\|\s*([^|}]+)\s*\}\}/);
if (textMatch) {
var lootText = textMatch[1].trim();
if (lootText) {
var li = document.createElement('li');
var link = document.createElement('a');
link.textContent = lootText;
link.href = 'https://ro-wiki.metin2.gameforge.com/index.php/' + encodeURIComponent(lootText);
link.target = '_blank';
li.appendChild(link);
lootList.appendChild(li);
}
}
});
} else {
var li = document.createElement('li');
li.textContent = 'No weapon drops found';
lootList.appendChild(li);
}
} else {
var li = document.createElement('li');
li.textContent = 'No weapon drops found';
lootList.appendChild(li);
}
} else {
console.error('Unexpected data format:', data);
}
})
.catch(function(error) {
console.error('Error:', error);
});
}
var items = document.querySelectorAll('#monster-list li');
items.forEach(function(item) {
item.addEventListener('click', function() {
var monster = item.getAttribute('data-monster');
showLoot(monster);
});
});
});
})();