コンテンツにスキップ

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

提供: 舞山市ファンWiki
Tmyt105 (トーク) による版 2299 を取り消し
beta1
29行目: 29行目:
/* PCスキンでサブタイトルを消す処理 ここまで */
/* PCスキンでサブタイトルを消す処理 ここまで */


/* リダイレクト(笑) */
/* beta1 */
if (window.location.host === 'maiyamawiki.miraheze.org') {
    const pageTitle = mw.config.get('wgPageName')
     window.location.replace('https://wiki.tmyt105.com' + window.location.pathname + window.location.search + window.location.hash);
    const apibase = 'https://wiki.tmyt105.com/w/api.php';
}
    const updaterElement = document.getElementById('last-updater-name');
/* リダイレクト(笑) ここまで */
 
    const params = {
        action: 'query',
        prop: 'revisions',
        titles: pageTitle,
        rvlimit: 1,
        rvprop: 'user',
        format: 'json',
        origin: '*'
    };
 
    const url = new URL(apibase);
    Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));
 
     fetch(url)
        .then(response => {
            if (!response.ok) {
                throw new Error(`HTTP error! status: ${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;
            } else {
                updaterElement.textContent = 'null';
            }
        })
        .catch(error => {
            console.error('エラー:', error);
            if (updaterElement) {
                updaterElement.textContent = '[取得エラー]';
            }
        });
 
/* beta1 ここまで */


console.log("OK Common.js")
console.log("OK Common.js")

2025年11月21日 (金) 14:11時点における版

/* ここにあるすべての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スキンでサブタイトルを消す処理 ここまで */

/* beta1 */
    const pageTitle = mw.config.get('wgPageName')
    const apibase = 'https://wiki.tmyt105.com/w/api.php';
    const updaterElement = document.getElementById('last-updater-name');

    const params = {
        action: 'query',
        prop: 'revisions',
        titles: pageTitle,
        rvlimit: 1,
        rvprop: 'user',
        format: 'json',
        origin: '*'
    };

    const url = new URL(apibase);
    Object.keys(params).forEach(key => url.searchParams.append(key, params[key]));

    fetch(url)
        .then(response => {
            if (!response.ok) {
                throw new Error(`HTTP error! status: ${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;
            } else {
                updaterElement.textContent = 'null';
            }
        })
        .catch(error => {
            console.error('エラー:', error);
            if (updaterElement) {
                updaterElement.textContent = '[取得エラー]';
            }
        });

/* beta1 ここまで */

console.log("OK Common.js")