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

m
m
Linia 67: Linia 67:
 
                             } else {
 
                             } else {
 
                                 var li = document.createElement('li');
 
                                 var li = document.createElement('li');
                                 li.textContent = 'No weapon drops found';
+
                                 li.textContent = 'Acest monstru nu dropează arme.';
 
                                 li.style.color = '#FFFFFF';  
 
                                 li.style.color = '#FFFFFF';  
 
                                 lootList.appendChild(li);
 
                                 lootList.appendChild(li);

Versiunea de la data 22 august 2024 12:08

(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 weapondropsMatch = wikitext.match(/\|Weapondrops\s*=\s*([\s\S]*?)(?=\n\|)/);
                        if (weapondropsMatch) {
                            var weapondrops = weapondropsMatch[1].trim();
                            var lootItems = weapondrops.match(/\{\{Ti\|[^}]+\}\}/g);

                            if (lootItems) {
                                lootItems.forEach(function(item) {
                                    var textMatch = item.match(/\|\s*([^|}]+)\s*\}\}/);
                                    if (textMatch) {
                                        var lootText = textMatch[1].trim();
                                        if (lootText) {
                                            var li = document.createElement('li');
                                            var link = document.createElement('a');
                                            link.textContent = lootText;
                                            link.href = 'https://ro-wiki.metin2.gameforge.com/index.php/' + encodeURIComponent(lootText);
                                            link.target = '_blank'; 
                                            
                                            
                                            link.style.color = '#FFFFFF'; 
                                            link.style.textDecoration = 'none'; 
                                            
                                            
                                            li.style.marginBottom = '5px'; 
                                            
                                            li.appendChild(link);
                                            lootList.appendChild(li);
                                        }
                                    }
                                });
                            } else {
                                var li = document.createElement('li');
                                li.textContent = 'Acest monstru nu dropează arme.';
                                li.style.color = '#FFFFFF'; 
                                lootList.appendChild(li);
                            }
                        } else {
                            var li = document.createElement('li');
                            li.textContent = 'No weapon drops found';
                            li.style.color = '#FFFFFF'; 
                            lootList.appendChild(li);
                        }
                    } else {
                        console.error('Unexpected data format:', data);
                    }
                })
        }

        var items = document.querySelectorAll('#monster-list li');
        items.forEach(function(item) {
            item.addEventListener('click', function() {
                var monster = item.getAttribute('data-monster');
                showLoot(monster);
            });
        });
    });
})();