MediaWiki:Common.js: Diferență între versiuni
m |
m |
||
Linia 36: | Linia 36: | ||
if (data.parse && data.parse.wikitext) { | if (data.parse && data.parse.wikitext) { | ||
var wikitext = data.parse.wikitext['*']; | var wikitext = data.parse.wikitext['*']; | ||
− | var | + | var drops = { |
− | + | Weapondrops: [], | |
− | + | Armordrops: [], | |
− | + | Otherdrops: [] | |
+ | }; | ||
− | if ( | + | ['Weapondrops', 'Armordrops', 'Otherdrops'].forEach(function(dropType) { |
− | + | var match = wikitext.match(new RegExp('\\|' + dropType + '\\s*=\\s*([\\s\\S]*?)(?=\\n\\|)', 'i')); | |
− | var textMatch = item.match(/\| | + | if (match) { |
+ | var items = match[1].trim().split(/\n\s*::\s*/); | ||
+ | drops[dropType] = items.map(function(item) { | ||
+ | var textMatch = item.match(/\{\{Ti\|[^}]+\}\}/); | ||
if (textMatch) { | if (textMatch) { | ||
− | var | + | var linkTextMatch = textMatch[0].match(/\|\s*([^|}]+)\s*\}\}/); |
− | if ( | + | if (linkTextMatch) { |
− | + | return linkTextMatch[1].trim(); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
} | } | ||
− | + | return null; | |
− | + | }).filter(Boolean); | |
− | |||
− | |||
− | |||
− | |||
} | } | ||
− | } | + | }); |
+ | |||
+ | for (var category in drops) { | ||
+ | if (drops.hasOwnProperty(category)) { | ||
+ | if (drops[category].length > 0) { | ||
+ | var header = document.createElement('li'); | ||
+ | header.textContent = category; | ||
+ | header.style.fontWeight = 'bold'; | ||
+ | lootList.appendChild(header); | ||
+ | |||
+ | drops[category].forEach(function(item) { | ||
+ | var li = document.createElement('li'); | ||
+ | li.classList.add('loot-list-item'); | ||
+ | var link = document.createElement('a'); | ||
+ | link.textContent = item; | ||
+ | link.href = 'https://ro-wiki.metin2.gameforge.com/index.php/' + encodeURIComponent(item); | ||
+ | link.target = '_blank'; // Open link in a new tab | ||
+ | link.style.color = 'white'; // Make link text white | ||
+ | |||
+ | li.appendChild(link); | ||
+ | lootList.appendChild(li); | ||
+ | }); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | |||
+ | if (lootList.children.length === 0) { | ||
var li = document.createElement('li'); | var li = document.createElement('li'); | ||
− | li.textContent = 'No | + | li.textContent = 'No items found'; |
− | li. | + | li.classList.add('loot-list-item'); |
lootList.appendChild(li); | lootList.appendChild(li); | ||
} | } | ||
Linia 81: | Linia 93: | ||
} | } | ||
}) | }) | ||
+ | .catch(function(error) { | ||
+ | console.error('Error:', error); | ||
+ | }); | ||
} | } | ||
− | var | + | var monsterItems = document.querySelectorAll('#monster-list li'); |
− | + | monsterItems.forEach(function(item) { | |
item.addEventListener('click', function() { | item.addEventListener('click', function() { | ||
var monster = item.getAttribute('data-monster'); | var monster = item.getAttribute('data-monster'); | ||
showLoot(monster); | showLoot(monster); | ||
+ | }); | ||
+ | }); | ||
+ | |||
+ | var categoryItems = document.querySelectorAll('#category-list li'); | ||
+ | categoryItems.forEach(function(item) { | ||
+ | item.addEventListener('click', function() { | ||
+ | var category = item.textContent.trim(); | ||
+ | var categoryMap = { | ||
+ | 'Arme': 'Weapondrops', | ||
+ | 'Armuri': 'Armordrops', | ||
+ | 'Drop General': 'Otherdrops' | ||
+ | }; | ||
+ | var categoryType = categoryMap[category]; | ||
+ | if (categoryType) { | ||
+ | var monster = document.querySelector('#monster-list li.active'); | ||
+ | if (monster) { | ||
+ | var monsterName = monster.getAttribute('data-monster'); | ||
+ | showLoot(monsterName, categoryType); | ||
+ | } | ||
+ | } | ||
}); | }); | ||
}); | }); | ||
}); | }); | ||
})(); | })(); |
Versiunea de la data 22 august 2024 12:29
(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 drops = {
Weapondrops: [],
Armordrops: [],
Otherdrops: []
};
['Weapondrops', 'Armordrops', 'Otherdrops'].forEach(function(dropType) {
var match = wikitext.match(new RegExp('\\|' + dropType + '\\s*=\\s*([\\s\\S]*?)(?=\\n\\|)', 'i'));
if (match) {
var items = match[1].trim().split(/\n\s*::\s*/);
drops[dropType] = items.map(function(item) {
var textMatch = item.match(/\{\{Ti\|[^}]+\}\}/);
if (textMatch) {
var linkTextMatch = textMatch[0].match(/\|\s*([^|}]+)\s*\}\}/);
if (linkTextMatch) {
return linkTextMatch[1].trim();
}
}
return null;
}).filter(Boolean);
}
});
for (var category in drops) {
if (drops.hasOwnProperty(category)) {
if (drops[category].length > 0) {
var header = document.createElement('li');
header.textContent = category;
header.style.fontWeight = 'bold';
lootList.appendChild(header);
drops[category].forEach(function(item) {
var li = document.createElement('li');
li.classList.add('loot-list-item');
var link = document.createElement('a');
link.textContent = item;
link.href = 'https://ro-wiki.metin2.gameforge.com/index.php/' + encodeURIComponent(item);
link.target = '_blank'; // Open link in a new tab
link.style.color = 'white'; // Make link text white
li.appendChild(link);
lootList.appendChild(li);
});
}
}
}
if (lootList.children.length === 0) {
var li = document.createElement('li');
li.textContent = 'No items found';
li.classList.add('loot-list-item');
lootList.appendChild(li);
}
} else {
console.error('Unexpected data format:', data);
}
})
.catch(function(error) {
console.error('Error:', error);
});
}
var monsterItems = document.querySelectorAll('#monster-list li');
monsterItems.forEach(function(item) {
item.addEventListener('click', function() {
var monster = item.getAttribute('data-monster');
showLoot(monster);
});
});
var categoryItems = document.querySelectorAll('#category-list li');
categoryItems.forEach(function(item) {
item.addEventListener('click', function() {
var category = item.textContent.trim();
var categoryMap = {
'Arme': 'Weapondrops',
'Armuri': 'Armordrops',
'Drop General': 'Otherdrops'
};
var categoryType = categoryMap[category];
if (categoryType) {
var monster = document.querySelector('#monster-list li.active');
if (monster) {
var monsterName = monster.getAttribute('data-monster');
showLoot(monsterName, categoryType);
}
}
});
});
});
})();