|
|
| Linia 1: |
Linia 1: |
| − | (function () {
| + | <div style="display: flex; border: 1px solid #8B4513; padding: 5px; width: 100%; background-color: #26211D; color: white;"> |
| − | document.addEventListener('DOMContentLoaded', function () { | + | <!-- Column for Monsters --> |
| − | function showLoot(monster) { | + | <div style="flex: 1; border-right: 1px solid #8B4513; padding: 5px;"> |
| − | var lootList = document.getElementById('loot-list'); | + | <div style="height: 200px; overflow-y: scroll;"> |
| − | lootList.innerHTML = ''; // Clear existing content | + | <ul id="monster-list" style="list-style-type: none; padding-left: 0;"> |
| | + | <li data-monster="Câine_Sălbatic">Câine Sălbatic</li> |
| | + | <li data-monster="Lup">Lup</li> |
| | + | <li data-monster="Lup_Alpha">Lup Alpha</li> |
| | + | <!-- Add more items as needed --> |
| | + | </ul> |
| | + | </div> |
| | + | </div> |
| | | | |
| − | var apiUrl = mw.util.wikiScript('api') + '?action=parse&page=' + encodeURIComponent(monster) + '&prop=wikitext&format=json&origin=*';
| + | <!-- Column for Possible Loot --> |
| − | | + | <div style="flex: 1; padding: 5px;"> |
| − | fetch(apiUrl)
| + | <div style="height: 200px; overflow-y: scroll;"> |
| − | .then(function (response) {
| + | <ul id="loot-list" style="list-style-type: none; padding-left: 0;"> |
| − | 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) {
| |
| − | var wikitext = data.parse.wikitext['*'];
| |
| − | console.log(wikitext);
| |
| − | | |
| − | // Handle redirects
| |
| − | 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);
| |
| − | }
| |
| − | })
| |
| − | .catch(function (error) {
| |
| − | var lootList = document.getElementById('loot-list');
| |
| − | if (lootList) {
| |
| − | var li = document.createElement('li');
| |
| − | li.textContent = 'Error fetching loot: ' + error.message;
| |
| − | lootList.appendChild(li);
| |
| − | } else {
| |
| − | console.error('Element with ID "loot-list" not found.');
| |
| − | }
| |
| − | console.error('Error:', error);
| |
| − | }); | |
| − | }
| |
| − | | |
| − | var items = document.querySelectorAll('#monster-list li');
| |
| − | items.forEach(function (item) {
| |
| − | item.addEventListener('click', function () { | |
| − | showLoot(item.getAttribute('data-monster'));
| |
| − | });
| |
| − | }); | |
| − | }); | |
| − | })();
| |