「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' など | |||
// | // 広告を出す名前空間を制限(本文とプロジェクトだけ、など) | ||
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 ( $( '.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=" | '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, .mw-body-content' ); | |||
var $ | if ( $contentPc.length ) { | ||
if ( $ | $( bottomAd ).insertAfter( $contentPc.last() ); | ||
$( bottomAd ).insertAfter( $ | |||
(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 = | ||
| 48行目: | 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>'; | ||
// Vector | // Vector 旧・新どちらでも拾えそうなセレクタ | ||
var $ | var $sidebar = $( '#mw-panel, .vector-sidebar, .mw-sidebar' ); | ||
if ( $ | |||
$( | 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(); | |||
} | |||
}); | |||
}); | |||