「MediaWiki:Common.js」の版間の差分
ナビゲーションに移動
検索に移動
編集の要約なし |
編集の要約なし |
||
| 1行目: | 1行目: | ||
// ===== | // === 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 () { | ||
// | |||
// 特別ページなどに出したくなければここで制御 | |||
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; | ||
} | } | ||
// | // ---- 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 ( $( ' | 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' ); | |||
var | if ( $panel.length ) { | ||
$( sideAd ).appendTo( $panel ); // 一番下に追加 | |||
(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({});
}
}
} );
} );