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

提供: 経済屋wiki
ナビゲーションに移動 検索に移動
編集の要約なし
編集の要約なし
1行目: 1行目:
// ===== 経済屋 Wiki 共通:フッター直前に AdSense 広告を表示 =====
// === 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 () {
mw.loader.using( 'mediawiki.util', function () {
     $( function () {
     $( function () {
         // AdSense を出したくない名前空間があればここで弾く(例:特別ページとか)
 
         // 特別ページなどに出したくなければここで制御
         var ns = mw.config.get( 'wgNamespaceNumber' );
         var ns = mw.config.get( 'wgNamespaceNumber' );
         if ( ns === -1 ) { // 特別ページ
        // 例: 本文(0)・プロジェクト(4)だけに出したい
         if ( [0, 4].indexOf( ns ) === -1 ) {
             return;
             return;
         }
         }


         // フッター要素を探す(Vector 系スキンなら #footer がほぼ必ずある)
         // ---- 1) 本文下の広告 ----
        var $footer = $( '#footer' );
        if ( $( '.keizaiya-ad-bottom' ).length === 0 ) {
        if ( !$footer.length ) {
            var bottomAd =
             return;
                '<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-adsense-footer' ).length ) {
         if ( $( '.keizaiya-ad-sidebar' ).length === 0 ) {
             return;
             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>';


        // AdSense 本体の script を読み込む(まだなら)
            // Vector レガシー想定:サイドバーは #mw-panel の中
        if ( !window._keizaiyaAdsenseLoaded ) {
             var $panel = $( '#mw-panel' );
             var s = document.createElement( 'script' );
             if ( $panel.length ) {
             s.async = true;
                $( sideAd ).appendTo( $panel );  // 一番下に追加
            s.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXXXXXXXXXXXXX';
                (adsbygoogle = window.adsbygoogle || []).push({});
            s.crossOrigin = 'anonymous';
             }
            document.head.appendChild( s );
             window._keizaiyaAdsenseLoaded = true;
         }
         }
        // 広告用コンテナを作成してフッターの直前に挿入
        var $ad = $('<div id="keizaiya-adsense-footer" class="adsense-footer" style="margin: 1.5em 0;"></div>');
        var $ins = $('<ins class="adsbygoogle"></ins>')
            .css( 'display', 'block' )
            .attr({
                'data-ad-client': 'ca-pub-8908534172586133',
                'data-ad-slot':  '6591340801',
                'data-ad-format': 'auto',
                'data-full-width-responsive': 'true'
            });
        $ad.append( $ins );
        $ad.insertBefore( $footer );
        // 広告をリクエスト
        window.adsbygoogle = window.adsbygoogle || [];
        window.adsbygoogle.push({});
     } );
     } );
} );
} );

2025年11月17日 (月) 19:23時点における版

// === 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({});
            }
        }
    } );
} );