「MediaWiki:Common.js」の版間の差分
編集の要約なし |
編集の要約なし |
||
| 15行目: | 15行目: | ||
$( function () { | $( function () { | ||
var ns = mw.config.get( 'wgNamespaceNumber' ); | var ns = mw.config.get( 'wgNamespaceNumber' ); | ||
var skin = mw.config.get( 'skin' ); // 'vector' / 'vector-2022' / 'minerva' | var skin = mw.config.get( 'skin' ); // 'vector' / 'vector-2022' / 'minerva' など | ||
// | // 広告を出す名前空間を制限(本文とプロジェクトだけ、など) | ||
if ( [0, 4].indexOf( ns ) === -1 ) { | if ( [0, 4].indexOf( ns ) === -1 ) { | ||
return; | return; | ||
} | } | ||
// | var clientId = 'ca-pub-8908534172586133'; // ★あなたの client ID | ||
var bottomSlot = '6591340801'; // ★本文下用スロット | |||
var sideSlot = '6591340801'; // ★サイドバー用スロット(別なら変える) | |||
/* ========= スマホ版(Minerva)のみ:本文下に 1 個だけ ========= */ | |||
if ( skin === 'minerva' ) { | if ( skin === 'minerva' ) { | ||
if ( $( '.keizaiya-ad-bottom' ).length ) { | if ( $( '.keizaiya-ad-bottom' ).length ) { | ||
return; | return; // 二重挿入防止 | ||
} | } | ||
| 33行目: | 37行目: | ||
'<ins class="adsbygoogle" ' + | '<ins class="adsbygoogle" ' + | ||
'style="display:block" ' + | 'style="display:block" ' + | ||
'data-ad-client=" | 'data-ad-client="' + clientId + '" ' + | ||
'data-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>'; | ||
var $content = $( '#mw-content-text, .mw-body-content, .content' ); | var $content = $( '#mw-content-text, .mw-body-content, .content' ); | ||
if ( $content.length ) { | if ( $content.length ) { | ||
$( bottomAdHtml ).insertAfter( $content.last() ); | $( bottomAdHtml ).insertAfter( $content.last() ); | ||
(adsbygoogle = window.adsbygoogle || []).push({}); | (adsbygoogle = window.adsbygoogle || []).push({}); | ||
} | } | ||
// | // スマホはサイドバー無しなのでここで終了 | ||
return; | return; | ||
} | } | ||
/ | /* ========= ここから PC 版(vector / vector-2022 等) ========= */ | ||
// | // ■ 本文下広告(PC) | ||
if ( $( '.keizaiya-ad-bottom' ).length === 0 ) { | if ( $( '.keizaiya-ad-bottom' ).length === 0 ) { | ||
var bottomAd = | var bottomAd = | ||
| 60行目: | 61行目: | ||
'<ins class="adsbygoogle" ' + | '<ins class="adsbygoogle" ' + | ||
'style="display:block" ' + | 'style="display:block" ' + | ||
'data-ad-client=" | 'data-ad-client="' + clientId + '" ' + | ||
'data-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>'; | ||
var $contentPc = $( '#mw-content-text' ); | var $contentPc = $( '#mw-content-text, .mw-body-content' ); | ||
if ( $contentPc.length ) { | if ( $contentPc.length ) { | ||
$( bottomAd ).insertAfter( $contentPc ); | $( bottomAd ).insertAfter( $contentPc.last() ); | ||
(adsbygoogle = window.adsbygoogle || []).push({}); | (adsbygoogle = window.adsbygoogle || []).push({}); | ||
} | } | ||
} | } | ||
// ■ サイドバー広告(PC) | |||
if ( $( '.keizaiya-ad-sidebar' ).length === 0 ) { | if ( $( '.keizaiya-ad-sidebar' ).length === 0 ) { | ||
var sideAd = | var sideAd = | ||
| 78行目: | 80行目: | ||
'<ins class="adsbygoogle" ' + | '<ins class="adsbygoogle" ' + | ||
'style="display:block" ' + | 'style="display:block" ' + | ||
'data-ad-client=" | 'data-ad-client="' + clientId + '" ' + | ||
'data-ad-slot=" | 'data-ad-slot="' + sideSlot + '" ' + | ||
'data-ad-format="auto"></ins>' + | 'data-ad-format="auto" ' + | ||
'data-full-width-responsive="true"></ins>' + | |||
'</div>'; | '</div>'; | ||
var $ | // Vector 旧・新どちらでも拾えそうなセレクタ | ||
if ( $ | var $sidebar = $( '#mw-panel, .vector-sidebar, .mw-sidebar' ); | ||
$( | |||
if ( $sidebar.length ) { | |||
$sidebar.first().append( sideAd ); | |||
(adsbygoogle = window.adsbygoogle || []).push({}); | (adsbygoogle = window.adsbygoogle || []).push({}); | ||
} | } | ||