MediaWiki:Common.js: Diferență între versiuni

m
m
Linia 16: Linia 16:
 
     req.send();
 
     req.send();
 
})();
 
})();
 
// JavaScript code to fetch and display loot information
 
  
 
function showLoot(monster) {
 
function showLoot(monster) {
 +
    console.log('Clicked monster:', monster);
 
     var lootList = document.getElementById('loot-list');
 
     var lootList = document.getElementById('loot-list');
 
     lootList.innerHTML = ''; // Clear existing content
 
     lootList.innerHTML = ''; // Clear existing content
  
    // Construct the API URL to fetch the page content
 
 
     var apiUrl = mw.util.wikiScript('api') + `?action=parse&page=${monster}&prop=wikitext&format=json&origin=*`;
 
     var apiUrl = mw.util.wikiScript('api') + `?action=parse&page=${monster}&prop=wikitext&format=json&origin=*`;
 +
    console.log('Fetching from URL:', apiUrl);
  
 
     fetch(apiUrl)
 
     fetch(apiUrl)
 
         .then(response => response.json())
 
         .then(response => response.json())
 
         .then(data => {
 
         .then(data => {
 +
            console.log('API response:', data);
 
             var wikitext = data.parse.wikitext['*'];
 
             var wikitext = data.parse.wikitext['*'];
 
             var weapondropsMatch = wikitext.match(/\|Weapondrops\s*=\s*(.*?)(\n|$)/s);
 
             var weapondropsMatch = wikitext.match(/\|Weapondrops\s*=\s*(.*?)(\n|$)/s);
 +
            console.log('Weapondrops match:', weapondropsMatch);
  
 
             if (weapondropsMatch) {
 
             if (weapondropsMatch) {
Linia 56: Linia 57:
 
         });
 
         });
 
}
 
}
 
document.addEventListener('DOMContentLoaded', function() {
 
    var items = document.querySelectorAll('#monster-list li');
 
    items.forEach(function(item) {
 
        item.addEventListener('click', function() {
 
            showLoot(item.getAttribute('data-monster'));
 
        });
 
    });
 
});
 

Versiunea de la data 22 august 2024 09:41

/* 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 showLoot(monster) {
    console.log('Clicked monster:', monster);
    var lootList = document.getElementById('loot-list');
    lootList.innerHTML = ''; // Clear existing content

    var apiUrl = mw.util.wikiScript('api') + `?action=parse&page=${monster}&prop=wikitext&format=json&origin=*`;
    console.log('Fetching from URL:', apiUrl);

    fetch(apiUrl)
        .then(response => response.json())
        .then(data => {
            console.log('API response:', data);
            var wikitext = data.parse.wikitext['*'];
            var weapondropsMatch = wikitext.match(/\|Weapondrops\s*=\s*(.*?)(\n|$)/s);
            console.log('Weapondrops match:', weapondropsMatch);

            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(error => {
            var li = document.createElement('li');
            li.textContent = 'Error fetching loot';
            lootList.appendChild(li);
            console.error('Error:', error);
        });
}