|
|
Linia 1: |
Linia 1: |
− | (function () {
| + | <div class="encyclopedia-container"> |
− | mw.hook('wikipage.content').add(function() { | + | <div class="encyclopedia-title">Enciclopedia Monștrilor</div> |
− | var selectedMonster = null; | + | |
− | var selectedCategory = 'Weapondrops'; | + | <!-- Column for Monsters --> |
| + | <div class="encyclopedia-column"> |
| + | <div class="encyclopedia-list-container"> |
| + | <ul class="encyclopedia-list" id="monster-list"> |
| + | <li data-monster="Câine_Sălbatic">Câine Sălbatic</li> |
| + | <li data-monster="Câine_Sălbatic_Flămând">Câine Sălbatic Flămând</li> |
| + | <li data-monster="Lup">Lup</li> |
| + | <li data-monster="Lup_Alpha">Lup Alpha</li> |
| + | <li data-monster="Lup_Albastru">Lup Albastru</li> |
| + | <li data-monster="Lup_Alpha_Albastru">Lup Alpha Albastru</li> |
| + | <li data-monster="Lup_Gri">Lup Gri</li> |
| + | <li data-monster="Lup_Alpha_Gri">Lup Alpha Gri</li> |
| + | <li data-monster="Mistret_Salbatic">Mistreț Sălbatic</li> |
| + | <li data-monster="Mistreț_Sălbatic_Roșu">Mistreț Sălbatic Roșu</li> |
| + | </ul> |
| + | </div> |
| + | </div> |
| | | |
− | function showLoot(monster, category) { | + | <!-- Column for Categories --> |
− | var lootList = document.getElementById('loot-list'); | + | <div class="encyclopedia-column"> |
− | if (!lootList) return; | + | <div class="encyclopedia-list-container"> |
− | lootList.innerHTML = '';
| + | <ul class="encyclopedia-list" id="category-list"> |
| + | <li data-category="Weapondrops">Arme</li> |
| + | <li data-category="Armordrops">Armuri</li> |
| + | <li data-category="Otherdrops">Drop General</li> |
| + | </ul> |
| + | </div> |
| + | </div> |
| | | |
− | var apiUrl = 'https://ro-wiki.metin2.gameforge.com/api.php?action=parse&page=' + encodeURIComponent(monster) + '&prop=wikitext&format=json&origin=*';
| + | <!-- Column for Possible Loot --> |
− | | + | <div class="encyclopedia-column"> |
− | fetch(apiUrl)
| + | <div class="encyclopedia-list-container"> |
− | .then(function(response) {
| + | <ul class="encyclopedia-list" id="loot-list"> |
− | if (!response.ok) {
| + | <li>Selectează un monstru pentru a vedea prada</li> |
− | throw new Error('Network response was not ok: ' + response.statusText);
| + | </ul> |
− | }
| + | </div> |
− | return response.json();
| + | </div> |
− | })
| + | </div> |
− | .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 regex = new RegExp('\\|' + dropType + '\\s*=([\\s\\S]*?)(?=(\\n\\|\\w+\\s*=|$))', 'i');
| |
− | var match = wikitext.match(regex);
| |
− | if (match && match[1].trim()) {
| |
− | 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);
| |
− | }
| |
− | });
| |
− | | |
− | var itemsToDisplay = drops[category] || [];
| |
− | | |
− | itemsToDisplay.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';
| |
− | link.style.color = 'white';
| |
− | | |
− | li.appendChild(link);
| |
− | lootList.appendChild(li);
| |
− | });
| |
− | | |
− | if (lootList.children.length === 0) {
| |
− | var li = document.createElement('li');
| |
− | li.textContent = 'Nu am gasit nimic pentru aceasta categorie.';
| |
− | li.classList.add('loot-list-item');
| |
− | lootList.appendChild(li);
| |
− | }
| |
− | } else {
| |
− | console.error('Unexpected data format:', data);
| |
− | }
| |
− | })
| |
− | }
| |
− | | |
− | function updateHighlighting() { | |
− | var monsterItems = document.querySelectorAll('#monster-list li');
| |
− | monsterItems.forEach(function(item) {
| |
− | item.classList.remove('highlighted');
| |
− | if (item.getAttribute('data-monster') === selectedMonster) {
| |
− | item.classList.add('highlighted');
| |
− | }
| |
− | });
| |
− | | |
− | var categoryItems = document.querySelectorAll('#category-list li'); | |
− | categoryItems.forEach(function(item) {
| |
− | item.classList.remove('highlighted');
| |
− | if (item.getAttribute('data-category') === selectedCategory) {
| |
− | item.classList.add('highlighted');
| |
− | }
| |
− | });
| |
− | }
| |
− | | |
− | var monsterItems = document.querySelectorAll('#monster-list li');
| |
− | monsterItems.forEach(function(item) {
| |
− | item.addEventListener('click', function() {
| |
− | selectedMonster = item.getAttribute('data-monster'); | |
− | selectedCategory = 'Weapondrops';
| |
− | showLoot(selectedMonster, selectedCategory);
| |
− | updateHighlighting();
| |
− | });
| |
− | });
| |
− | | |
− | var categoryItems = document.querySelectorAll('#category-list li');
| |
− | categoryItems.forEach(function(item) {
| |
− | item.addEventListener('click', function() { | |
− | selectedCategory = item.getAttribute('data-category');
| |
− | | |
− | categoryItems.forEach(function(catItem) {
| |
− | catItem.classList.remove('highlighted');
| |
− | });
| |
− | | |
− | item.classList.add('highlighted');
| |
− |
| |
− | if (selectedMonster) {
| |
− | showLoot(selectedMonster, selectedCategory);
| |
− | }
| |
− | updateHighlighting();
| |
− | });
| |
− | }); | |
− | | |
− | if (monsterItems.length > 0) {
| |
− | selectedMonster = monsterItems[0].getAttribute('data-monster');
| |
− | showLoot(selectedMonster, selectedCategory);
| |
− | updateHighlighting();
| |
− | }
| |
− | }); | |
− | })();
| |