MediaWiki:Common.js: Diferență între versiuni
m |
m |
||
| Linia 17: | Linia 17: | ||
| − | mw.hook('wikipage.content').add(function() { | + | (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'); | ||
| + | li.textContent = lootText; | ||
| + | lootList.appendChild(li); | ||
| + | } | ||
| + | } | ||
| + | }); | ||
| + | } else { | ||
var li = document.createElement('li'); | var li = document.createElement('li'); | ||
| − | li.textContent = | + | li.textContent = 'No weapon drops found'; |
lootList.appendChild(li); | lootList.appendChild(li); | ||
} | } | ||
| − | }); | + | } else { |
| + | var li = document.createElement('li'); | ||
| + | li.textContent = 'No weapon drops found'; | ||
| + | lootList.appendChild(li); | ||
| + | } | ||
} else { | } else { | ||
| − | + | console.error('Unexpected data format:', data); | |
| − | |||
| − | |||
} | } | ||
| − | + | }) | |
| − | + | } | |
| − | |||
| − | |||
| − | |||
| − | + | var items = document.querySelectorAll('#monster-list li'); | |
| − | + | items.forEach(function(item) { | |
| − | + | item.addEventListener('click', function() { | |
| − | + | var monster = item.getAttribute('data-monster'); | |
| − | + | showLoot(monster); | |
| + | }); | ||
}); | }); | ||
}); | }); | ||
| − | }); | + | })(); |
Versiunea de la data 22 august 2024 12:02
(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');
li.textContent = lootText;
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);
}
})
}
var items = document.querySelectorAll('#monster-list li');
items.forEach(function(item) {
item.addEventListener('click', function() {
var monster = item.getAttribute('data-monster');
showLoot(monster);
});
});
});
})();