미디어위키:Common.js: 두 판 사이의 차이
보이기
편집 요약 없음 |
편집 요약 없음 |
||
| 1번째 줄: | 1번째 줄: | ||
$(function() { | |||
$ | // 1. 광고를 표시할 HTML 요소를 정의합니다. | ||
// 광고를 | |||
var adContainer = '<div id="adsense-top-container" style="margin-bottom: 15px; text-align: center;">' + | var adContainer = '<div id="adsense-top-container" style="margin-bottom: 15px; text-align: center;">' + | ||
'<ins class="adsbygoogle" ' + | '<ins class="adsbygoogle" ' + | ||
| 11번째 줄: | 10번째 줄: | ||
'</div>'; | '</div>'; | ||
// 메인 | // 2. 메인 문서 페이지(Namespace 0)인지 확인하고, 광고 컨테이너가 아직 없는지 확인합니다. | ||
if (mw.config.get('wgNamespaceNumber') === 0) { | if (mw.config.get('wgNamespaceNumber') === 0 && $('#adsense-top-container').length === 0) { | ||
// 본문 | |||
// 3. 정의한 HTML 요소를 본문 상단에 삽입합니다. | |||
$('#mw-content-text').prepend(adContainer); | $('#mw-content-text').prepend(adContainer); | ||
// 애드센스 | // 4. 애드센스 스크립트를 <head>에 동적으로 추가합니다. (이미 있다면 추가되지 않음) | ||
(adsbygoogle = window.adsbygoogle || []).push({}); | if ($('script[src*="adsbygoogle.js"]').length === 0) { | ||
var adScript = document.createElement('script'); | |||
adScript.async = true; | |||
adScript.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8756229796915320'; | |||
adScript.crossOrigin = 'anonymous'; | |||
document.head.appendChild(adScript); | |||
} | |||
// 5. 광고를 실행시킵니다. | |||
try { | |||
(adsbygoogle = window.adsbygoogle || []).push({}); | |||
} catch (e) { | |||
console.error("AdSense push error: ", e); | |||
} | |||
} | } | ||
}); | }); | ||
2025년 6월 21일 (토) 21:53 판
$(function() {
// 1. 광고를 표시할 HTML 요소를 정의합니다.
var adContainer = '<div id="adsense-top-container" style="margin-bottom: 15px; text-align: center;">' +
'<ins class="adsbygoogle" ' +
'style="display:block" ' +
'data-ad-client="ca-pub-8756229796915320" ' +
'data-ad-slot="6238396570" ' +
'data-ad-format="auto" ' +
'data-full-width-responsive="true"></ins>' +
'</div>';
// 2. 메인 문서 페이지(Namespace 0)인지 확인하고, 광고 컨테이너가 아직 없는지 확인합니다.
if (mw.config.get('wgNamespaceNumber') === 0 && $('#adsense-top-container').length === 0) {
// 3. 정의한 HTML 요소를 본문 상단에 삽입합니다.
$('#mw-content-text').prepend(adContainer);
// 4. 애드센스 스크립트를 <head>에 동적으로 추가합니다. (이미 있다면 추가되지 않음)
if ($('script[src*="adsbygoogle.js"]').length === 0) {
var adScript = document.createElement('script');
adScript.async = true;
adScript.src = 'https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-8756229796915320';
adScript.crossOrigin = 'anonymous';
document.head.appendChild(adScript);
}
// 5. 광고를 실행시킵니다.
try {
(adsbygoogle = window.adsbygoogle || []).push({});
} catch (e) {
console.error("AdSense push error: ", e);
}
}
});