MediaWiki:Common.js: Diferență între versiuni
m |
m |
||
| Linia 17: | Linia 17: | ||
})(); | })(); | ||
| − | (function () { | + | (function() { |
| − | document.addEventListener('DOMContentLoaded', function () { | + | document.addEventListener('DOMContentLoaded', function() { |
function showLoot(monster) { | function showLoot(monster) { | ||
| − | |||
| − | |||
var lootList = document.getElementById('loot-list'); | var lootList = document.getElementById('loot-list'); | ||
| − | lootList.innerHTML = ''; | + | lootList.innerHTML = ''; |
var apiUrl = mw.util.wikiScript('api') + '?action=parse&page=' + encodeURIComponent(monster) + '&prop=wikitext&format=json&origin=*'; | var apiUrl = mw.util.wikiScript('api') + '?action=parse&page=' + encodeURIComponent(monster) + '&prop=wikitext&format=json&origin=*'; | ||
| − | |||
fetch(apiUrl) | fetch(apiUrl) | ||
| − | .then(function (response) { | + | .then(function(response) { |
if (!response.ok) { | if (!response.ok) { | ||
throw new Error('Network response was not ok: ' + response.statusText); | throw new Error('Network response was not ok: ' + response.statusText); | ||
| Linia 35: | Linia 32: | ||
return response.json(); | return response.json(); | ||
}) | }) | ||
| − | .then(function (data) { | + | .then(function(data) { |
| − | console.log( | + | var wikitext = data.parse.wikitext['*']; |
| + | console.log(wikitext); | ||
| − | |||
if (wikitext.startsWith('#Redirect')) { | if (wikitext.startsWith('#Redirect')) { | ||
var targetPageMatch = wikitext.match(/\[\[([^\]]+)\]\]/); | var targetPageMatch = wikitext.match(/\[\[([^\]]+)\]\]/); | ||
| Linia 45: | Linia 42: | ||
var redirectUrl = mw.util.wikiScript('api') + '?action=parse&page=' + encodeURIComponent(targetPage) + '&prop=wikitext&format=json&origin=*'; | var redirectUrl = mw.util.wikiScript('api') + '?action=parse&page=' + encodeURIComponent(targetPage) + '&prop=wikitext&format=json&origin=*'; | ||
return fetch(redirectUrl) | return fetch(redirectUrl) | ||
| − | .then(function (response) { | + | .then(function(response) { |
if (!response.ok) { | if (!response.ok) { | ||
throw new Error('Redirect Network response was not ok: ' + response.statusText); | throw new Error('Redirect Network response was not ok: ' + response.statusText); | ||
| Linia 55: | Linia 52: | ||
return data; | return data; | ||
}) | }) | ||
| − | .then(function (data) { | + | .then(function(data) { |
var wikitext = data.parse.wikitext['*']; | var wikitext = data.parse.wikitext['*']; | ||
var weapondropsMatch = wikitext.match(/\|Weapondrops\s*=\s*([^\n|]*)/); | var weapondropsMatch = wikitext.match(/\|Weapondrops\s*=\s*([^\n|]*)/); | ||
| Linia 62: | Linia 59: | ||
var lootItems = weapondrops.split('::'); | var lootItems = weapondrops.split('::'); | ||
| − | lootItems.forEach(function (item) { | + | lootItems.forEach(function(item) { |
if (item.trim()) { | if (item.trim()) { | ||
var li = document.createElement('li'); | var li = document.createElement('li'); | ||
| Linia 74: | Linia 71: | ||
lootList.appendChild(li); | lootList.appendChild(li); | ||
} | } | ||
| − | } | + | }, function(error) { |
| − | + | console.error('Error:', error); | |
| − | console.error('Error | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
}); | }); | ||
} | } | ||
var items = document.querySelectorAll('#monster-list li'); | var items = document.querySelectorAll('#monster-list li'); | ||
| − | items.forEach(function (item) { | + | items.forEach(function(item) { |
| − | item.addEventListener('click', function () { | + | item.addEventListener('click', function() { |
showLoot(item.getAttribute('data-monster')); | showLoot(item.getAttribute('data-monster')); | ||
}); | }); | ||
Versiunea de la data 22 august 2024 11:43
/* Any JavaScript here will be loaded for all users on every page load. */
(function () {
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) {
var lootList = document.getElementById('loot-list');
lootList.innerHTML = '';
var apiUrl = mw.util.wikiScript('api') + '?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) {
var wikitext = data.parse.wikitext['*'];
console.log(wikitext);
if (wikitext.startsWith('#Redirect')) {
var targetPageMatch = wikitext.match(/\[\[([^\]]+)\]\]/);
if (targetPageMatch) {
var targetPage = targetPageMatch[1];
var redirectUrl = mw.util.wikiScript('api') + '?action=parse&page=' + encodeURIComponent(targetPage) + '&prop=wikitext&format=json&origin=*';
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;
})
.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);
}
}, function(error) {
console.error('Error:', error);
});
}
var items = document.querySelectorAll('#monster-list li');
items.forEach(function(item) {
item.addEventListener('click', function() {
showLoot(item.getAttribute('data-monster'));
});
});
});
})();