「MediaWiki:Common.js」の版間の差分
編集の要約なし |
編集の要約なし |
||
| (同じ利用者による、間の5版が非表示) | |||
| 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' ); | var skin = mw.config.get( 'skin' ); // 'vector' / 'vector-2022' / 'minerva' など | ||
if ( ns === -1 ) { | |||
// 広告を出す名前空間を制限(本文とプロジェクトだけ、など) | |||
if ( [0, 4].indexOf( ns ) === -1 ) { | |||
return; | return; | ||
} | } | ||
// | var clientId = 'ca-pub-8908534172586133'; // ★あなたの client ID | ||
var $ | 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; | return; | ||
} | } | ||
// | /* ========= ここから PC 版(vector / vector-2022 等) ========= */ | ||
if ( $( ' | |||
// ■ 本文下広告(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({}); | |||
} | |||
} | } | ||
// | // ■ サイドバー広告(PC) | ||
if ( | if ( $( '.keizaiya-ad-sidebar' ).length === 0 ) { | ||
var | var sideAd = | ||
'<div class="keizaiya-ad keizaiya-ad-sidebar">' + | |||
'<ins class="adsbygoogle" ' + | |||
'style="display:block" ' + | |||
'data-ad-client="' + clientId + '" ' + | |||
'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({}); | |||
} | |||
} | } | ||
} ); | |||
} ); | |||
// === 承認済み版バー(最新版を閲覧)を一般閲覧者から隠す === | |||
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(); | |||
} ); | } | ||
} ); | }); | ||
}); | |||