MediaWiki:Common.js

2026年1月25日 (日) 02:26時点におけるTmyt105 (トーク | 投稿記録)による版 (t2)

注意: 保存後、変更を確認するにはブラウザーのキャッシュを消去する必要がある場合があります。

  • Firefox / Safari: Shift を押しながら 再読み込み をクリックするか、Ctrl-F5 または Ctrl-R を押してください (Mac では ⌘-R)
  • Google Chrome: Ctrl-Shift-R を押してください (Mac では ⌘-Shift-R)
  • Microsoft Edge: Ctrl を押しながら 最新の情報に更新 をクリックするか、Ctrl-F5 を押してください。
/* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */

/* PCスキンでサブタイトルを消す処理 */
const targetNode = document.getElementById('contentSub');
const config = { childList: true, subtree: true };

const callback = function(mutationsList, observer) {
  for (const mutation of mutationsList) {
    if (mutation.type === 'childList') {
      const subtitleElement = document.getElementById('mw-content-subtitle');
      if (subtitleElement) {
        const childNodes = subtitleElement.childNodes;
        const lastChildNode = childNodes[childNodes.length - 1];
        if (lastChildNode && lastChildNode.nodeType === Node.TEXT_NODE) {
          lastChildNode.remove();
          observer.disconnect();
          return;
        }
      }
    }
  }
};

const observer = new MutationObserver(callback);
if (targetNode) {
  observer.observe(targetNode, config);
}

/* PCスキンでサブタイトルを消す処理 ここまで */

/* beta2 */
    const pageTitle = mw.config.get('wgPageName')
    const pageNo = mw.config.get('wgRevisionId')
    const url = `https://wiki.tmyt105.com/w/api.php?action=query&format=json&prop=revisions&formatversion=2&revids=${pageNo}&rvprop=user`;
    const updaterElement = document.getElementById('last-updater-name');

    fetch(url)
        .then(response => {
            if (!response.ok) {
                throw new Error(`HTTP${response.status}`);
            }
            return response.json();
        })
        .then(data => {
            if (!updaterElement) return;
            const pages = data.query.pages;
            const pageId = Object.keys(pages)[0];
            const pageData = pages[pageId];

            if (pageData.missing) {
                updaterElement.textContent = 'null';
                return;
            }

            const revisions = pageData.revisions;
            if (revisions && revisions.length > 0) {
                const lastUpdater = revisions[0].user;
                updaterElement.textContent = lastUpdater.charAt(0).toLowerCase() + lastUpdater.slice(1);
            } else {
                updaterElement.textContent = 'null';
            }
        })
        .catch(error => {
            console.error('エラー:', error);
            if (updaterElement) {
                updaterElement.textContent = '[取得エラー]';
            }
        });

/* beta2 ここまで */

/* スマホめにゅー */
(function() {
    function initCustomMenu() {
        var $target = $('.menu ul:first');

        if ($target.length && !$('#p-custom-accordion').length) {
           
            var html = 
                '<ul id="p-custom-accordion" class="hlist" style="border-bottom: 1px solid #eaecf0; padding-bottom: 5px;">' +
                   
                    '<li class="menu__item">' +
                        '<a href="#" id="custom-menu-toggle" class="mw-ui-icon mw-ui-icon-before mw-ui-icon-mf-expand" style="font-weight:bold;">' +
                            '<span>Wikiリンク</span>' +
                        '</a>' +
                    '</li>' +
                    '<div id="custom-menu-content" style="display:none; background-color: #f8f9fa; margin-left: 10px; border-radius: 4px;">' +
                        '<li class="menu__item"><a href="/wiki/Wiki:方針" class="mw-ui-icon mw-ui-icon-before mw-ui-icon-notice"><span>方針</span></a></li>' +
                        '<li class="menu__item"><a href="/wiki/特別:特別ページ一覧" class="mw-ui-icon mw-ui-icon-before mw-ui-icon-star"><span>特別ページ一覧</span></a></li>' +
                        '<li class="menu__item"><a href="/wiki/特別:ページ一覧" class="mw-ui-icon mw-ui-icon-before mw-ui-icon-listBullet"><span>全てのページ</span></a></li>' +
                        '<li class="menu__item"><a href="/wiki/特別:最近の更新" class="mw-ui-icon mw-ui-icon-before mw-ui-icon-recentChanges"><span>最近の更新</span></a></li>' +
                    '</div>' +
                '</ul>';

            $target.before(html);

            $('#custom-menu-toggle').on('click', function(e) {
                e.preventDefault();
                $('#custom-menu-content').slideToggle(200);
                $(this).toggleClass('mw-ui-icon-mf-expand mw-ui-icon-mf-collapse');
            });
        }
    }

    $(document).ready(initCustomMenu);
    var retry = 0;
    var timer = setInterval(function() {
        initCustomMenu();
        if (++retry > 20) clearInterval(timer);
    }, 300);
})();

console.log("OK Common.js")