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

編集の要約なし
編集の要約なし
 
(同じ利用者による、間の4版が非表示)
14行目: 14行目:
mw.loader.using( 'mediawiki.util', function () {
mw.loader.using( 'mediawiki.util', function () {
     $( function () {
     $( function () {
        var ns  = mw.config.get( 'wgNamespaceNumber' );
        var skin = mw.config.get( 'skin' ); // 'vector' / 'vector-2022' / 'minerva' など


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


         // ---- 1) 本文下の広告 ----
         var clientId  = 'ca-pub-8908534172586133';  // ★あなたの client ID
        var bottomSlot = '6591340801';              // ★本文下用スロット
        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;
        }
 
        /* ========= ここから PC 版(vector / vector-2022 等) ========= */
 
        // ■ 本文下広告(PC)
         if ( $( '.keizaiya-ad-bottom' ).length === 0 ) {
         if ( $( '.keizaiya-ad-bottom' ).length === 0 ) {
             var bottomAd =
             var bottomAd =
28行目: 61行目:
                     '<ins class="adsbygoogle" ' +
                     '<ins class="adsbygoogle" ' +
                         'style="display:block" ' +
                         'style="display:block" ' +
                         'data-ad-client="ca-pub-8908534172586133" ' + // ★自分の client ID
                         'data-ad-client="' + clientId + '" ' +
                         'data-ad-slot="6591340801" ' +                 // ★本文下用の ad-slot
                         'data-ad-slot="' + bottomSlot + '" ' +
                         'data-ad-format="auto" ' +
                         'data-ad-format="auto" ' +
                         'data-full-width-responsive="true"></ins>' +
                         'data-full-width-responsive="true"></ins>' +
                 '</div>';
                 '</div>';


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


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


             // Vector レガシー想定:サイドバーは #mw-panel の中
             // Vector 旧・新どちらでも拾えそうなセレクタ
             var $panel = $( '#mw-panel' );
             var $sidebar = $( '#mw-panel, .vector-sidebar, .mw-sidebar' );
             if ( $panel.length ) {
 
                 $( sideAd ).appendTo( $panel ); // 一番下に追加
             if ( $sidebar.length ) {
                 $sidebar.first().append( sideAd );
                 (adsbygoogle = window.adsbygoogle || []).push({});
                 (adsbygoogle = window.adsbygoogle || []).push({});
             }
             }
62行目: 96行目:
     } );
     } );
} );
} );
// === 承認済み版バー(最新版を閲覧)を一般閲覧者から隠す ===
mw.loader.using( 'mediawiki.util', function () {
    $( function () {
        // 現在のユーザーが所属するグループ
        var groups = mw.config.get( 'wgUserGroups' ) || [];
        // 管理者・執筆者だけはバーを表示したい
        var isPrivileged =
            groups.indexOf( 'sysop' ) !== -1 ||
            groups.indexOf( 'writer' ) !== -1;  // writer も非表示にするならこの行を消す
        if ( !isPrivileged ) {
            // ページ内の notLatestMsg をまるごと削除
            $('.notLatestMsg').remove();
        }
    });
});