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

m
m
Linia 17: Linia 17:
  
  
mw.hook('wikipage.content').add(function() {
+
(function () {
    function showLoot(monster) {
+
    mw.hook('wikipage.content').add(function() {
        var lootList = document.getElementById('loot-list');
+
        function showLoot(monster) {
        if (!lootList) return;  
+
            var lootList = document.getElementById('loot-list');
        lootList.innerHTML = '';
+
            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=*';
+
            var apiUrl = 'https://ro-wiki.metin2.gameforge.com/api.php?action=parse&page=' + encodeURIComponent(monster) + '&prop=wikitext&format=json&origin=*';
  
        fetch(apiUrl)
+
            fetch(apiUrl)
            .then(function(response) {
+
                .then(function(response) {
                if (!response.ok) {
+
                    if (!response.ok) {
                    throw new Error('Network response was not ok: ' + response.statusText);
+
                        throw new Error('Network response was not ok: ' + response.statusText);
                }
+
                    }
                return response.json();
+
                    return response.json();
            })
+
                })
            .then(function(data) {
+
                .then(function(data) {
                if (data.parse && data.parse.wikitext) {
+
                    if (data.parse && data.parse.wikitext) {
                    var wikitext = data.parse.wikitext['*'];
+
                        var wikitext = data.parse.wikitext['*'];
                    var weapondropsMatch = wikitext.match(/\|Weapondrops\s*=\s*([^\n|]*)/);
+
                        var weapondropsMatch = wikitext.match(/\|Weapondrops\s*=\s*([\s\S]*?)(?=\n\|)/);
                    if (weapondropsMatch) {
+
                        if (weapondropsMatch) {
                        var weapondrops = weapondropsMatch[1].trim();
+
                            var weapondrops = weapondropsMatch[1].trim();
                        var lootItems = weapondrops.split('::');
+
                            var lootItems = weapondrops.match(/\{\{Ti\|[^}]+\}\}/g);
  
                        lootItems.forEach(function(item) {
+
                            if (lootItems) {
                            if (item.trim()) {
+
                                lootItems.forEach(function(item) {
 +
                                    var textMatch = item.match(/\|\s*([^}]+)\s*\}\}/);
 +
                                    if (textMatch) {
 +
                                        var lootText = textMatch[1].trim();
 +
                                        if (lootText) {
 +
                                            var li = document.createElement('li');
 +
                                            li.textContent = lootText;
 +
                                            lootList.appendChild(li);
 +
                                        }
 +
                                    }
 +
                                });
 +
                            } else {
 
                                 var li = document.createElement('li');
 
                                 var li = document.createElement('li');
                                 li.textContent = item.trim();
+
                                 li.textContent = 'No weapon drops found';
 
                                 lootList.appendChild(li);
 
                                 lootList.appendChild(li);
 
                             }
 
                             }
                         });
+
                         } else {
 +
                            var li = document.createElement('li');
 +
                            li.textContent = 'No weapon drops found';
 +
                            lootList.appendChild(li);
 +
                        }
 
                     } else {
 
                     } else {
                         var li = document.createElement('li');
+
                         console.error('Unexpected data format:', data);
                        li.textContent = 'No weapon drops found';
 
                        lootList.appendChild(li);
 
 
                     }
 
                     }
                 } else {
+
                 })
                    console.error('Unexpected data format:', data);
+
        }
                }
 
            })
 
    }
 
  
    var items = document.querySelectorAll('#monster-list li');
+
        var items = document.querySelectorAll('#monster-list li');
    items.forEach(function(item) {
+
        items.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);
 +
            });
 
         });
 
         });
 
     });
 
     });
});
+
})();

Versiunea de la data 22 august 2024 12:02

(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');
                                            li.textContent = lootText;
                                            lootList.appendChild(li);
                                        }
                                    }
                                });
                            } else {
                                var li = document.createElement('li');
                                li.textContent = 'No weapon drops found';
                                lootList.appendChild(li);
                            }
                        } else {
                            var li = document.createElement('li');
                            li.textContent = 'No weapon drops found';
                            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);
            });
        });
    });
})();