MediaWiki:Common.js

提供: 経済屋wiki
2025年11月17日 (月) 19:23時点におけるSadora (トーク | 投稿記録)による版
ナビゲーションに移動 検索に移動

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

  • Firefox / Safari: Shift を押しながら 再読み込み をクリックするか、Ctrl-F5 または Ctrl-R を押してください (Mac では ⌘-R)
  • Google Chrome: Ctrl-Shift-R を押してください (Mac では ⌘-Shift-R)
  • Microsoft Edge: Ctrl を押しながら 最新の情報に更新 をクリックするか、Ctrl-F5 を押してください。
// === Google AdSense loader ===
if ( !window.keizaiyaAdsLoaded ) {
    window.keizaiyaAdsLoaded = true;

    var s = document.createElement( 'script' );
    s.async = true;
    // ★ここを自分の client ID に変える
    s.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8908534172586133';
    s.crossOrigin = 'anonymous';
    document.head.appendChild( s );
}

// === 本文下 & サイドバー下に広告枠を差し込む ===
mw.loader.using( 'mediawiki.util', function () {
    $( function () {

        // 特別ページなどに出したくなければここで制御
        var ns = mw.config.get( 'wgNamespaceNumber' );
        // 例: 本文(0)・プロジェクト(4)だけに出したい
        if ( [0, 4].indexOf( ns ) === -1 ) {
            return;
        }

        // ---- 1) 本文下の広告 ----
        if ( $( '.keizaiya-ad-bottom' ).length === 0 ) {
            var bottomAd =
                '<div class="keizaiya-ad keizaiya-ad-bottom">' +
                    '<ins class="adsbygoogle" ' +
                        'style="display:block" ' +
                        'data-ad-client="ca-pub-8908534172586133" ' + // ★自分の client ID
                        'data-ad-slot="6591340801" ' +                  // ★本文下用の ad-slot
                        'data-ad-format="auto" ' +
                        'data-full-width-responsive="true"></ins>' +
                '</div>';

            // 本文 (#mw-content-text) の直後に挿入
            var $content = $( '#mw-content-text' );
            if ( $content.length ) {
                $( bottomAd ).insertAfter( $content );
                (adsbygoogle = window.adsbygoogle || []).push({});
            }
        }

        // ---- 2) サイドバー下の広告 ----
        if ( $( '.keizaiya-ad-sidebar' ).length === 0 ) {
            var sideAd =
                '<div class="keizaiya-ad keizaiya-ad-sidebar">' +
                    '<ins class="adsbygoogle" ' +
                        'style="display:block" ' +
                        'data-ad-client="ca-pub-8908534172586133" ' + // ★同じ client ID
                        'data-ad-slot="6591340801" ' +                  // ★サイドバー用 ad-slot
                        'data-ad-format="auto"></ins>' +
                '</div>';

            // Vector レガシー想定:サイドバーは #mw-panel の中
            var $panel = $( '#mw-panel' );
            if ( $panel.length ) {
                $( sideAd ).appendTo( $panel );  // 一番下に追加
                (adsbygoogle = window.adsbygoogle || []).push({});
            }
        }
    } );
} );