MediaWiki:Common.js
注意: 保存後、変更を確認するにはブラウザーのキャッシュを消去する必要がある場合があります。
- Firefox / Safari: Shift を押しながら 再読み込み をクリックするか、Ctrl-F5 または Ctrl-R を押してください (Mac では ⌘-R)
- Google Chrome: Ctrl-Shift-R を押してください (Mac では ⌘-Shift-R)
- Microsoft Edge: Ctrl を押しながら 最新の情報に更新 をクリックするか、Ctrl-F5 を押してください。
1 /* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */
2 function injectAdSense(adClient, adSlot, targetId) {
3 let adContainer = document.createElement('ins');
4 adContainer.className = 'adsbygoogle';
5 adContainer.style.display = 'block';
6 adContainer.style.textAlign = 'center';
7 adContainer.style.marginTop = '8px';
8
9 adContainer.setAttribute('data-ad-client', adClient);
10 adContainer.setAttribute('data-ad-slot', adSlot);
11 adContainer.setAttribute('data-ad-format', 'horizontal');
12 adContainer.setAttribute('data-full-width-responsive', 'false');
13
14 let targetElement = document.getElementById(targetId);
15 if (targetElement) {
16 if (targetElement.firstElementChild) {
17 targetElement.insertBefore(adContainer, targetElement.firstElementChild);
18 } else {
19 targetElement.appendChild(adContainer);
20 }
21
22 if (window.adsbygoogle) {
23 (adsbygoogle = window.adsbygoogle || []).push({});
24 }
25 }
26 }
27
28 mw.loader.getScript('//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js')
29 .done(function() {
30 injectAdSense('ca-pub-6414722865362490', '8156714274', 'bodyContent');
31 })
32 .fail(function() {
33 console.error('Failed to load AdSense script');
34 });