본문으로 이동

미디어위키:Common.js

KANOTYPE WIKI

참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.

  • 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
  • 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
  • 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
 1 /* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */
 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 });