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

編集の要約なし
編集の要約なし
 
(同じ利用者による、間の5版が非表示)
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' );
        var skin = mw.config.get( 'skin' ); // 'vector' / 'vector-2022' / 'minerva' など
         if ( ns === -1 ) { // 特別ページ
 
        // 広告を出す名前空間を制限(本文とプロジェクトだけ、など)
         if ( [0, 4].indexOf( ns ) === -1 ) {
             return;
             return;
         }
         }


         // フッター要素を探す(Vector 系スキンなら #footer がほぼ必ずある)
         var clientId  = 'ca-pub-8908534172586133';  // ★あなたの client ID
         var $footer = $( '#footer' );
        var bottomSlot = '6591340801';              // ★本文下用スロット
        if ( !$footer.length ) {
         var sideSlot  = '6591340801';              // ★サイドバー用スロット(別なら変える)
 
        /* ========= スマホ版(Minerva)のみ:本文下に 1 個だけ ========= */
        if ( skin === 'minerva' ) {
 
            if ( $( '.keizaiya-ad-bottom' ).length ) {
                return; // 二重挿入防止
            }
 
            var bottomAdHtml =
                '<div class="keizaiya-ad keizaiya-ad-bottom">' +
                    '<ins class="adsbygoogle" ' +
                        'style="display:block" ' +
                        'data-ad-client="' + clientId + '" ' +
                        'data-ad-slot="' + bottomSlot + '" ' +
                        'data-ad-format="auto" ' +
                        'data-full-width-responsive="true"></ins>' +
                '</div>';
 
            var $content = $( '#mw-content-text, .mw-body-content, .content' );
            if ( $content.length ) {
                $( bottomAdHtml ).insertAfter( $content.last() );
                (adsbygoogle = window.adsbygoogle || []).push({});
            }
 
            // スマホはサイドバー無しなのでここで終了
             return;
             return;
         }
         }


         // すでに挿入済みなら二重に出さない
         /* ========= ここから PC 版(vector / vector-2022 等) ========= */
         if ( $( '#keizaiya-adsense-footer' ).length ) {
 
             return;
        // ■ 本文下広告(PC)
         if ( $( '.keizaiya-ad-bottom' ).length === 0 ) {
             var bottomAd =
                '<div class="keizaiya-ad keizaiya-ad-bottom">' +
                    '<ins class="adsbygoogle" ' +
                        'style="display:block" ' +
                        'data-ad-client="' + clientId + '" ' +
                        'data-ad-slot="' + bottomSlot + '" ' +
                        'data-ad-format="auto" ' +
                        'data-full-width-responsive="true"></ins>' +
                '</div>';
 
            var $contentPc = $( '#mw-content-text, .mw-body-content' );
            if ( $contentPc.length ) {
                $( bottomAd ).insertAfter( $contentPc.last() );
                (adsbygoogle = window.adsbygoogle || []).push({});
            }
         }
         }


         // AdSense 本体の script を読み込む(まだなら)
         // ■ サイドバー広告(PC)
         if ( !window._keizaiyaAdsenseLoaded ) {
         if ( $( '.keizaiya-ad-sidebar' ).length === 0 ) {
             var s = document.createElement( 'script' );
             var sideAd =
            s.async = true;
                '<div class="keizaiya-ad keizaiya-ad-sidebar">' +
            s.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXXXXXXXXXXXXX';
                    '<ins class="adsbygoogle" ' +
             s.crossOrigin = 'anonymous';
                        'style="display:block" ' +
             document.head.appendChild( s );
                        'data-ad-client="' + clientId + '" ' +
            window._keizaiyaAdsenseLoaded = true;
                        'data-ad-slot="' + sideSlot + '" ' +
                        'data-ad-format="auto" ' +
                        'data-full-width-responsive="true"></ins>' +
                '</div>';
 
             // Vector 旧・新どちらでも拾えそうなセレクタ
            var $sidebar = $( '#mw-panel, .vector-sidebar, .mw-sidebar' );
 
             if ( $sidebar.length ) {
                $sidebar.first().append( sideAd );
                (adsbygoogle = window.adsbygoogle || []).push({});
            }
         }
         }
    } );
} );


        // 広告用コンテナを作成してフッターの直前に挿入
        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' )
mw.loader.using( 'mediawiki.util', function () {
            .attr({
    $( function () {
                'data-ad-client': 'ca-pub-8908534172586133',
        // 現在のユーザーが所属するグループ
                'data-ad-slot':  '6591340801',
        var groups = mw.config.get( 'wgUserGroups' ) || [];
                'data-ad-format': 'auto',
                'data-full-width-responsive': 'true'
            });


         $ad.append( $ins );
         // 管理者・執筆者だけはバーを表示したい
        $ad.insertBefore( $footer );
        var isPrivileged =
            groups.indexOf( 'sysop' ) !== -1 ||
            groups.indexOf( 'writer' ) !== -1; // writer も非表示にするならこの行を消す


         // 広告をリクエスト
         if ( !isPrivileged ) {
        window.adsbygoogle = window.adsbygoogle || [];
            // ページ内の notLatestMsg をまるごと削除
         window.adsbygoogle.push({});
            $('.notLatestMsg').remove();
     } );
         }
} );
     });
});