본문으로 이동

미디어위키:Common.js: 두 판 사이의 차이

김준호위키
새 문서: 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다.: $(document).ready(function() { // 광고를 넣을 컨테이너 생성 var adCont...
 
편집 요약 없음
 
(같은 사용자의 중간 판 6개는 보이지 않습니다)
1번째 줄: 1번째 줄:
/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */
$(function() {
$(document).ready(function() {
     // 1. 애드센스에서 받은 광고 단위(<ins>) 정보를 변수에 저장합니다.
     // 광고를 넣을 컨테이너 생성
     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" ' +
                       'style="display:block" ' +
                       'style="display:block" ' +
                       'data-ad-client="ca-pub-8756229796915320" ' +
                       'data-ad-client="ca-pub-8756229796915320" ' +
                       'data-ad-slot="6238396570" ' +
                       'data-ad-slot="7998241024" ' +
                       'data-ad-format="auto" ' +
                       'data-ad-format="auto" ' +
                       'data-full-width-responsive="true"></ins>' +
                       'data-full-width-responsive="true"></ins>' +
                       '</div>';
                       '</div>';


     // 메인 네임스페이스(일반 문서)에만 광고를 표시하고 싶을 때
     // 2. 메인 문서 페이지(일반 )인지, 그리고 광고 컨테이너가 아직 없는지 확인합니다.
     if (mw.config.get('wgNamespaceNumber') === 0) {
     if (mw.config.get('wgNamespaceNumber') === 0 && $('#adsense-top-container').length === 0) {
         // 본문 내용 최상단(#mw-content-text .mw-parser-output 바로 위)에 광고 컨테이너 삽입
       
         // 3. 정의한 광고 컨테이너를 본문 상단에 삽입합니다.
         $('#mw-content-text').prepend(adContainer);
         $('#mw-content-text').prepend(adContainer);


         // 애드센스 스크립트 실행
         // 4. 애드센스 기본 스크립트(adsbygoogle.js)를 페이지에 동적으로 추가합니다.
         (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. 페이지에 삽입된 광고 단위(<ins>)를 실행시켜 실제 광고를 채웁니다.
        try {
            (adsbygoogle = window.adsbygoogle || []).push({});
        } catch (e) {
            console.error("AdSense push error: ", e);
        }
     }
     }
});
});

2025년 6월 21일 (토) 22:03 기준 최신판

$(function() {
    // 1. 애드센스에서 받은 광고 단위(<ins>) 정보를 변수에 저장합니다.
    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="7998241024" ' +
                      'data-ad-format="auto" ' +
                      'data-full-width-responsive="true"></ins>' +
                      '</div>';

    // 2. 메인 문서 페이지(일반 글)인지, 그리고 광고 컨테이너가 아직 없는지 확인합니다.
    if (mw.config.get('wgNamespaceNumber') === 0 && $('#adsense-top-container').length === 0) {
        
        // 3. 정의한 광고 컨테이너를 본문 상단에 삽입합니다.
        $('#mw-content-text').prepend(adContainer);

        // 4. 애드센스 기본 스크립트(adsbygoogle.js)를 페이지에 동적으로 추가합니다.
        // 페이지에 이미 스크립트가 로드되어 있다면 중복해서 추가하지 않습니다.
        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. 페이지에 삽입된 광고 단위(<ins>)를 실행시켜 실제 광고를 채웁니다.
        try {
            (adsbygoogle = window.adsbygoogle || []).push({});
        } catch (e) {
            console.error("AdSense push error: ", e);
        }
    }
});