MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
 
(183 intermediate revisions by the same user not shown)
Line 1: Line 1:
if(!mw.config.get('wgUserId')){
var currentUrl = window.location.href;
var commJs = currentUrl.includes('Common.js');
var commCss = currentUrl.includes('Common.css');
var vectorJs = currentUrl.includes('Vector.js');
var vectorCss = currentUrl.includes('Vector.css');
if(commJs || commCss || vectorJs || vectorCss){
window.location.href = '/index.php';
}
// 도구 메뉴들 숨김(사이드바);
$pTb = document.getElementById('p-tb');
if ($pTb) $pTb.parentElement.removeChild($pTb);
// 문서의 역사롤 봅니다. (hidden 시킴)
var $lastModifiedBar = document.querySelector('.last-modified-bar');
if($lastModifiedBar) $lastModifiedBar.parentElement.removeChild($lastModifiedBar);
//파일중복 메세지 제거
var $duplicates = document.getElementById('mw-imagepage-section-duplicates');
if($duplicates) $duplicates.parentElement.removeChild($duplicates);
// 모든 문서 목록 검색 box 삭제
var $wrapper = document.querySelector('.mw-htmlform-ooui-wrapper')
if ($wrapper) $wrapper.parentElement.removeChild($wrapper);
}
/*
else{
$searchBox = document.querySelector('.mw-htmlform-ooui-wrapper');
if($searchBox) $searchBox.style.display = 'block';
}
*/
/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */
/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */


//Google Analytics
var GoogleCdn = document.createElement('script');
GoogleCdn.src = 'https://www.googletagmanager.com/gtag/js?id=G-LTWMMR6YSB';
document.body.appendChild(GoogleCdn);
window.dataLayer = window.dataLayer || [];
function gtag() {
    dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-LTWMMR6YSB');


/* TOP 버튼 */
/* TOP 버튼 */
var topButton = document.createElement('div');
var topButton = document.createElement('div');
topButton.id = 'top-button';
topButton.id = 'top-button';
document.body.appendChild(topButton);
document.body.appendChild(topButton);
window.addEventListener('scroll', function (e) {
window.addEventListener('scroll', function (e) {
Line 24: Line 66:
     }
     }
});
});
/* 대문 섹션 토글 */
/* 대문 섹션 토글 */
if (mw.config.get('wgPageName') == '대문' || mw.config.get('wgPageName') == '대문테스트') {
if (mw.config.get('wgPageName') == '대문' || mw.config.get('wgPageName') == '대문테스트') {
Line 40: Line 81:


/*모든 문서 */
/*모든 문서 */
if (mw.config.get('wgPageName').toLowerCase() == '모든_문서_목록') {
if (mw.config.get('wgPageName').toLowerCase() == 'list_of_all_documents') {
     var list = document.querySelectorAll('.mw-allpages-body li');
     var list = document.querySelectorAll('.mw-allpages-body li');
     for (var i = 0; i < list.length; i++) {
     for (var i = 0; i < list.length; i++) {
Line 50: Line 91:
     document.querySelector('.cog-commonpages').style.display = '';
     document.querySelector('.cog-commonpages').style.display = '';
}
}
var mouseX=0;
var mouseY=0;
/* 각주 팝업창 위치 보정 DOM */
var observer = new MutationObserver(function (mutationList) {
    mutationList.forEach(function (mutation) {
        mutation.addedNodes.forEach(function (node) {
            if (node.classList && (node.classList.contains('mwe-popups')|| node.classList.contains('rt-tooltip'))) {
                requestAnimationFrame(function () {
                    var bodyLeft = document.body.getBoundingClientRect().left;
                    var left = parseInt(window.getComputedStyle(node).left);
                    node.style.left = left - bodyLeft + 'px';
                });
            }
        });
    });
});
// 감시할 대상 설정
observer.observe(document.body, {
    childList: true,
    subtree: true,
});


/* 각주 팝업창 위치 보정 */
/* 우클릭 방지  */
document.body.addEventListener(
if (mw.config.get("wgUserName") == null) {
    'DOMNodeInserted',
  window.oncontextmenu = function (e) {
    function (e) {
        if (e.target.classList && e.target.classList.contains('mwe-popups')) {
            requestAnimationFrame(function () {
                var bodyLeft = document.body.getBoundingClientRect().left;
                var left = parseInt(window.getComputedStyle(e.target).left);
                e.target.style.left = left - bodyLeft + 'px';
            });
        }
    },
    false
);
 
/* 우클릭 방지 */
window.oncontextmenu = function (e) {
     return e.preventDefault();
     return e.preventDefault();
};
  };
window.onselectstart = function (e) {
  window.onselectstart = function (e) {
     return e.preventDefault();
     return e.preventDefault();
};
  };
}


/* 존재하지 않는 문서 페이지의 '기록' 링크 삭제 */
/* 존재하지 않는 문서 페이지의 '기록' 링크 삭제 */
if (mw.config.get('wgUserId') == null && document.querySelector('.plainlinks a')) {
if (mw.config.get('wgUserId') == null && document.querySelector('.plainlinks a')) {
Line 111: Line 161:
             if (window.Kakao && $kakao) {
             if (window.Kakao && $kakao) {
                 // 사용할 앱의 JavaScript 키를 설정해 주세요.
                 // 사용할 앱의 JavaScript 키를 설정해 주세요.
                 Kakao.init('132b053079230ffc0880fd0a8155f444');
                 Kakao.init('214de4d25d41a7b837b7bbeb75631c90');
                 $kakao.children[0].style.display = 'inline';
                 $kakao.children[0].style.display = 'inline';
                 $kakao.onclick = sendScrap; // 카카오 Link 공유 API 사용
                 $kakao.onclick = sendScrap; // 카카오 Link 공유 API 사용
Line 125: Line 175:
                 $copy.addEventListener('click', function (e) {
                 $copy.addEventListener('click', function (e) {
                     copyStringToClipboard(decodeURI(location.href));
                     copyStringToClipboard(decodeURI(location.href));
                     alert('링크를 클립보드에 저장했습니다.');
                     alert('Saved the link to the clipboard.');
                     e.preventDefault();
                     e.preventDefault();
                 });
                 });
Line 160: Line 210:
     Kakao.Link.sendScrap({
     Kakao.Link.sendScrap({
         requestUrl: location.href,
         requestUrl: location.href,
         templateId: 82911,
         templateId: 91817,
         templateArgs: {
         templateArgs: {
             TITLE: og('title', '하나님의 교회 지식사전'),
             TITLE: og('title', 'Church of God Knowledge Encyclopedia'),
             DESC: og('description'),
             DESC: og('description'),
             THUMB: thumb(),
             THUMB: thumb(),
Line 243: Line 293:


             var ratio = $img.naturalWidth / $img.naturalHeight;
             var ratio = $img.naturalWidth / $img.naturalHeight;
             $elem.children[i].style.width = (ratio / totalRatio) * (totalWidth - 6 * lineMax) + 6 + 'px';
             var width = (ratio / totalRatio) * (totalWidth - 6 * lineMax) + 6;
            $elem.children[i].style.width = (width / totalWidth) * 100 + '%';
         }
         }
     }
     }
}
//넘겨주기 문서를 숨깁니다.
var redirectList = document.querySelectorAll('.mw-parser-output li.allpagesredirect')
for (var i=0; i < redirectList.length; i++){
redirectList[i].style.display = 'none';
}
// 이미지문서에서 commons 라이센스 관련 링크를 숨긴다.
var $sharedUploadNotice = document.querySelector('.sharedUploadNotice p');
if($sharedUploadNotice){
$sharedUploadNotice.parentElement.removeChild($sharedUploadNotice);
}
// origin file 영역 숨김.
var $fullMedia = document.querySelector('.fullMedia p');
if($fullMedia){
$fullMedia.parentElement.removeChild($fullMedia);
}
// 데스크탑 언어
var langDiv = document.getElementById('right-navigation');
if(langDiv){
var navHTML = '<nav id="p-cactions" class="mw-portlet mw-portlet-cactions vector-menu-dropdown-noicon vector-menu vector-menu-dropdown" aria-labelledby="p-cactions-label" role="navigation">' +
'<input type="checkbox" id="p-cactions-checkbox" role="button" aria-haspopup="true" data-event-name="ui.dropdown-p-cactions" class="vector-menu-checkbox" aria-labelledby="p-cactions-label">' +
'<label id="p-cactions-label" aria-label="" class="vector-menu-heading">' +
  '<span class="select-language"></span>' +
  '<span class="vector-menu-heading-label">Language</span>' +
'</label>' +
'<div class="vector-menu-content">' +
  '<ul class="vector-menu-content-list">' +
'<li class="mw-list-item"><a href="https://churchofgod.wiki" title="하나님의 교회 지식사전"><span>Korean</span></a></li>' +
    '<li class="mw-list-item"><a href="https://churchofgod.wiki/en" title="Church of God Knowledge Encyclopedia"><span>English</span></a></li>' +
    '<li class="mw-list-item"><a href="https://churchofgod.wiki/es" title="ChurchEnciclopedia de conocimiento de la Iglesia de Dios"><span>Spanish</span></a></li>' +
    '<li class="mw-list-item"><a href="https://churchofgod.wiki/vi" title="Từ điển tri thức Hội Thánh của Đức Chúa Trời"><span>Vietnamese</span></a></li>' +
    '<li class="mw-list-item"><a href="https://churchofgod.wiki/ne" title="नेपाली"><span>Nepali</span></a></li>' +
    '<li class="mw-list-item"><a href="https://churchofgod.wiki/pt" title="ENCICLOPÉDIA DO CONHECIMENTO DA IGREJA DE DEUS"><span>português</span></a></li>' +
  '</ul>' +
'</div>' +
'</nav>';
langDiv.insertAdjacentHTML('afterbegin', navHTML);
}
}