メニューを切り替える
個人設定メニューを切り替える
個人メニューを切り替える
ログインしていません
編集を行うと、IPアドレスが公開されます。

「MediaWiki:Citizen.js」の版間の差分

MediaWikiインターフェイスページ
編集の要約なし
編集の要約なし
2行目: 2行目:
     console.log("Citizen.js loaded");
     console.log("Citizen.js loaded");


     document.addEventListener("DOMContentLoaded", function() {
     function handleNewMaps(maps) {
         var maps = document.querySelectorAll('.googlemap');
         maps.forEach(function(el, index){
        console.log("maps NodeList:", maps);
            console.log("Map element found:", el, el.dataset.coords);
         alert("maps NodeList length: " + maps.length);
         });
    }


         maps.forEach(function(el, index){
    // DOMの変化を監視
             console.log("Map element #" + index, el);
    var observer = new MutationObserver(function(mutationsList) {
            alert("Map element #" + index + " found with data-coords: " + el.dataset.coords);
         mutationsList.forEach(function(mutation) {
             mutation.addedNodes.forEach(function(node) {
                if (node.nodeType === 1 && node.matches('.googlemap')) {
                    handleNewMaps([node]);
                }
                if (node.querySelectorAll) {
                    handleNewMaps(node.querySelectorAll('.googlemap'));
                }
            });
         });
         });
     });
     });
    observer.observe(document.body, { childList: true, subtree: true });
})();
})();

2025年10月23日 (木) 20:20時点における版

(function() {
    console.log("Citizen.js loaded");

    function handleNewMaps(maps) {
        maps.forEach(function(el, index){
            console.log("Map element found:", el, el.dataset.coords);
        });
    }

    // DOMの変化を監視
    var observer = new MutationObserver(function(mutationsList) {
        mutationsList.forEach(function(mutation) {
            mutation.addedNodes.forEach(function(node) {
                if (node.nodeType === 1 && node.matches('.googlemap')) {
                    handleNewMaps([node]);
                }
                if (node.querySelectorAll) {
                    handleNewMaps(node.querySelectorAll('.googlemap'));
                }
            });
        });
    });

    observer.observe(document.body, { childList: true, subtree: true });
})();