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

m
m
Linia 141: Linia 141:
  
 
document.addEventListener("DOMContentLoaded", function() {
 
document.addEventListener("DOMContentLoaded", function() {
  const overlays = document.querySelectorAll(".overlay-point");
+
    // Function to add overlay points dynamically
 +
    function addOverlayPoints(baseImageSelector, points) {
 +
        const container = document.querySelector(baseImageSelector);
 +
       
 +
        // Ensure the container exists
 +
        if (!container) return;
  
  overlays.forEach(function(overlay) {
+
        points.forEach(point => {
    // Retrieve custom data attributes for positioning and radius
+
            const overlayPoint = document.createElement("div");
    const x = overlay.dataset.x;
+
            overlayPoint.className = "overlay-point";
    const y = overlay.dataset.y;
+
           
    const radius = overlay.dataset.radius;
+
            // Set styles based on the point's coordinates and radius
 +
            overlayPoint.style.top = point.y + "px";
 +
            overlayPoint.style.left = point.x + "px";
 +
            overlayPoint.style.width = point.radius * 2 + "px";
 +
            overlayPoint.style.height = point.radius * 2 + "px";
  
    // Apply inline styles based on data attributes
+
            // Create the anchor tag for the link
    overlay.style.top = y + "px";
+
            const anchor = document.createElement("a");
    overlay.style.left = x + "px";
+
            anchor.href = point.link;
    overlay.style.width = radius * 2 + "px";
+
            anchor.title = point.title;
    overlay.style.height = radius * 2 + "px";
+
            anchor.innerHTML = point.label || "Link";
  });
+
 
 +
            overlayPoint.appendChild(anchor);
 +
            container.appendChild(overlayPoint);
 +
        });
 +
    }
 +
 
 +
    // Define the points (this could be pulled dynamically or set per page)
 +
    const points = [
 +
        {x: 50, y: 100, radius: 10, link: '/wiki/Polyphemos', title: 'Polyphemos', label: '1'},
 +
        {x: 150, y: 200, radius: 15, link: '/wiki/ExamplePage2', title: 'Example 2', label: '2'}
 +
    ];
 +
 
 +
    // Call the function for the desired image
 +
    addOverlayPoints('.overlay-container', points);
 
});
 
});

Versiunea de la data 26 septembrie 2024 19:09

(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() {
        var selectedMonster = null;
        var selectedCategory = 'Weapondrops'; 

        function showLoot(monster, category) {
            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 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('selected');
                if (item.getAttribute('data-monster') === selectedMonster) {
                    item.classList.add('selected');
                }
            });

            var categoryItems = document.querySelectorAll('#category-list li');
            categoryItems.forEach(function(item) {
                item.classList.remove('selected');
                if (item.getAttribute('data-category') === selectedCategory) {
                    item.classList.add('selected');
                }
            });
        }

        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');
                updateHighlighting();

                if (selectedMonster) {
                    showLoot(selectedMonster, selectedCategory);
                }
            });
        });


        if (monsterItems.length > 0) {
            selectedMonster = monsterItems[0].getAttribute('data-monster');
            showLoot(selectedMonster, selectedCategory);
            updateHighlighting(); 
        }
    });
})();

document.addEventListener("DOMContentLoaded", function() {
    // Function to add overlay points dynamically
    function addOverlayPoints(baseImageSelector, points) {
        const container = document.querySelector(baseImageSelector);
        
        // Ensure the container exists
        if (!container) return;

        points.forEach(point => {
            const overlayPoint = document.createElement("div");
            overlayPoint.className = "overlay-point";
            
            // Set styles based on the point's coordinates and radius
            overlayPoint.style.top = point.y + "px";
            overlayPoint.style.left = point.x + "px";
            overlayPoint.style.width = point.radius * 2 + "px";
            overlayPoint.style.height = point.radius * 2 + "px";

            // Create the anchor tag for the link
            const anchor = document.createElement("a");
            anchor.href = point.link;
            anchor.title = point.title;
            anchor.innerHTML = point.label || "Link";

            overlayPoint.appendChild(anchor);
            container.appendChild(overlayPoint);
        });
    }

    // Define the points (this could be pulled dynamically or set per page)
    const points = [
        {x: 50, y: 100, radius: 10, link: '/wiki/Polyphemos', title: 'Polyphemos', label: '1'},
        {x: 150, y: 200, radius: 15, link: '/wiki/ExamplePage2', title: 'Example 2', label: '2'}
    ];

    // Call the function for the desired image
    addOverlayPoints('.overlay-container', points);
});