MediaWiki:Common.js: Diferență între versiuni
m |
m |
||
Linia 1: | Linia 1: | ||
− | |||
− | |||
(function () { | (function () { | ||
+ | // Load GDPR Cookie Script | ||
var req = new XMLHttpRequest(); | var req = new XMLHttpRequest(); | ||
req.addEventListener('load', function (ev) { | req.addEventListener('load', function (ev) { | ||
Linia 20: | Linia 19: | ||
document.addEventListener('DOMContentLoaded', function() { | document.addEventListener('DOMContentLoaded', function() { | ||
function showLoot(monster) { | function showLoot(monster) { | ||
+ | console.log('showLoot called with monster:', monster); | ||
var lootList = document.getElementById('loot-list'); | var lootList = document.getElementById('loot-list'); | ||
lootList.innerHTML = ''; | lootList.innerHTML = ''; | ||
var apiUrl = 'https://ro-wiki.metin2.gameforge.com/api.php?action=parse&page=' + encodeURIComponent(monster) + '&prop=wikitext&format=json&origin=*'; | var apiUrl = 'https://ro-wiki.metin2.gameforge.com/api.php?action=parse&page=' + encodeURIComponent(monster) + '&prop=wikitext&format=json&origin=*'; | ||
+ | console.log('Fetching data from URL:', apiUrl); | ||
fetch(apiUrl) | fetch(apiUrl) | ||
Linia 33: | Linia 34: | ||
}) | }) | ||
.then(function(data) { | .then(function(data) { | ||
− | console.log('API Data:', data); | + | console.log('API Data:', data); |
− | var wikitext = data.parse.wikitext['*']; | + | if (data.parse && data.parse.wikitext) { |
− | + | var wikitext = data.parse.wikitext['*']; | |
+ | console.log('Wikitext:', wikitext); | ||
− | + | if (wikitext.startsWith('#Redirect')) { | |
− | + | var targetPageMatch = wikitext.match(/\[\[([^\]]+)\]\]/); | |
− | + | if (targetPageMatch) { | |
− | + | var targetPage = targetPageMatch[1]; | |
− | + | var redirectUrl = 'https://ro-wiki.metin2.gameforge.com/api.php?action=parse&page=' + encodeURIComponent(targetPage) + '&prop=wikitext&format=json&origin=*'; | |
− | + | console.log('Redirecting to URL:', redirectUrl); // Debugging line | |
− | + | return fetch(redirectUrl) | |
− | + | .then(function(response) { | |
− | + | if (!response.ok) { | |
− | + | throw new Error('Redirect Network response was not ok: ' + response.statusText); | |
− | + | } | |
− | + | return response.json(); | |
+ | }); | ||
+ | } | ||
} | } | ||
+ | return data; | ||
+ | } else { | ||
+ | throw new Error('Unexpected data format'); | ||
} | } | ||
− | |||
}) | }) | ||
.then(function(data) { | .then(function(data) { | ||
Linia 73: | Linia 79: | ||
} | } | ||
}) | }) | ||
+ | .catch(function(error) { | ||
+ | console.error('Error:', error); | ||
+ | }); | ||
} | } | ||
var items = document.querySelectorAll('#monster-list li'); | var items = document.querySelectorAll('#monster-list li'); | ||
+ | console.log('Items found:', items.length); | ||
items.forEach(function(item) { | items.forEach(function(item) { | ||
item.addEventListener('click', function() { | item.addEventListener('click', function() { | ||
− | + | var monster = item.getAttribute('data-monster'); | |
+ | console.log('Clicked monster:', monster); | ||
+ | showLoot(monster); | ||
}); | }); | ||
}); | }); | ||
}); | }); | ||
})(); | })(); |
Versiunea de la data 22 august 2024 11:50
(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() {
document.addEventListener('DOMContentLoaded', function() {
function showLoot(monster) {
console.log('showLoot called with monster:', monster);
var lootList = document.getElementById('loot-list');
lootList.innerHTML = '';
var apiUrl = 'https://ro-wiki.metin2.gameforge.com/api.php?action=parse&page=' + encodeURIComponent(monster) + '&prop=wikitext&format=json&origin=*';
console.log('Fetching data from URL:', apiUrl);
fetch(apiUrl)
.then(function(response) {
if (!response.ok) {
throw new Error('Network response was not ok: ' + response.statusText);
}
return response.json();
})
.then(function(data) {
console.log('API Data:', data);
if (data.parse && data.parse.wikitext) {
var wikitext = data.parse.wikitext['*'];
console.log('Wikitext:', wikitext);
if (wikitext.startsWith('#Redirect')) {
var targetPageMatch = wikitext.match(/\[\[([^\]]+)\]\]/);
if (targetPageMatch) {
var targetPage = targetPageMatch[1];
var redirectUrl = 'https://ro-wiki.metin2.gameforge.com/api.php?action=parse&page=' + encodeURIComponent(targetPage) + '&prop=wikitext&format=json&origin=*';
console.log('Redirecting to URL:', redirectUrl); // Debugging line
return fetch(redirectUrl)
.then(function(response) {
if (!response.ok) {
throw new Error('Redirect Network response was not ok: ' + response.statusText);
}
return response.json();
});
}
}
return data;
} else {
throw new Error('Unexpected data format');
}
})
.then(function(data) {
var wikitext = data.parse.wikitext['*'];
var weapondropsMatch = wikitext.match(/\|Weapondrops\s*=\s*([^\n|]*)/);
if (weapondropsMatch) {
var weapondrops = weapondropsMatch[1].trim();
var lootItems = weapondrops.split('::');
lootItems.forEach(function(item) {
if (item.trim()) {
var li = document.createElement('li');
li.textContent = item.trim();
lootList.appendChild(li);
}
});
} else {
var li = document.createElement('li');
li.textContent = 'No weapon drops found';
lootList.appendChild(li);
}
})
.catch(function(error) {
console.error('Error:', error);
});
}
var items = document.querySelectorAll('#monster-list li');
console.log('Items found:', items.length);
items.forEach(function(item) {
item.addEventListener('click', function() {
var monster = item.getAttribute('data-monster');
console.log('Clicked monster:', monster);
showLoot(monster);
});
});
});
})();