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

편집 요약 없음
편집 요약 없음
 
(같은 사용자의 중간 판 87개는 보이지 않습니다)
1번째 줄: 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);   
}
//Naver Analytics
//Naver Analytics
var NaverCdn = document.createElement('script');
var NaverCdn = document.createElement('script');
44번째 줄: 71번째 줄:
     window.location.href = 'https://churchofgod.wiki/%ED%95%98%EB%82%98%EB%8B%98%EC%9D%98_%EA%B5%90%ED%9A%8C_%EC%A7%80%EC%8B%9D%EC%82%AC%EC%A0%84';
     window.location.href = 'https://churchofgod.wiki/%ED%95%98%EB%82%98%EB%8B%98%EC%9D%98_%EA%B5%90%ED%9A%8C_%EC%A7%80%EC%8B%9D%EC%82%AC%EC%A0%84';
}
}
if (mw.config.get('wgPageName') == '하나님의_교회_지식사전') {
if (mw.config.get('wgPageName') == '하나님의_교회_지식사전') {
     var titles = document.querySelectorAll('.cog-box-title');
     var titles = document.querySelectorAll('.cog-box-title');
70번째 줄: 98번째 줄:


/* 각주 팝업창 위치 보정 */
/* 각주 팝업창 위치 보정 */
document.body.addEventListener(
// MutationObserver를 사용하여 DOM 변경 사항 감지
    'DOMNodeInserted',
var observer = new MutationObserver(function (mutationList){
    function (e) {
mutationList.forEach(function(mutation){
        if (e.target.classList && e.target.classList.contains('mwe-popups')) {
        mutation.addedNodes.forEach(function (node) {
            requestAnimationFrame(function () {
if (node.classList && node.classList.contains('mwe-popups')) {
                var bodyLeft = document.body.getBoundingClientRect().left;
requestAnimationFrame(function () {
                var left = parseInt(window.getComputedStyle(e.target).left);
var bodyLeft = document.body.getBoundingClientRect().left;
                e.target.style.left = left - bodyLeft + 'px';
            var left = parseInt(window.getComputedStyle(node).left);
            });
            node.style.left = left - bodyLeft + 'px';
         }
        });
    },
        }       
    false
         })
);
})
})
// 감시할 대상 설정
observer.observe(document.body, {
childList:true,
subtree:true
})


/* 우클릭 방지 */
/* 우클릭 방지 */
window.oncontextmenu = function (e) {
if (mw.config.get('wgUserName') == null) {
    return e.preventDefault();
window.oncontextmenu = function (e) {
};
    return e.preventDefault();
window.onselectstart = function (e) {
};
    return e.preventDefault();
window.onselectstart = function (e) {
};
    return e.preventDefault();
};
}
 


/* 존재하지 않는 문서 페이지의 '기록' 링크 삭제 */
/* 존재하지 않는 문서 페이지의 '기록' 링크 삭제 */
129번째 줄: 166번째 줄:
             if (window.Kakao && $kakao) {
             if (window.Kakao && $kakao) {
                 // 사용할 앱의 JavaScript 키를 설정해 주세요.
                 // 사용할 앱의 JavaScript 키를 설정해 주세요.
                 Kakao.init('5bbf33cb4d93dd3d2100996872cf8e44');
                 Kakao.init('132b053079230ffc0880fd0a8155f444');
                 $kakao.children[0].style.display = 'inline';
                 $kakao.children[0].style.display = 'inline';
                 $kakao.onclick = function () {
                 $kakao.onclick = sendScrap; // 카카오 Link 공유 API 사용
                    // 카카오 Link 공유 API 사용
                    Kakao.Link.sendScrap({
                        requestUrl: location.href,
                    });
                };
                 window.initKakaoLink = true;
                 window.initKakaoLink = true;
             } else retry = true;
             } else retry = true;
177번째 줄: 209번째 줄:
     document.execCommand('copy');
     document.execCommand('copy');
     document.body.removeChild(el);
     document.body.removeChild(el);
}
function sendScrap() {
    // 카카오 Link 공유 API 사용
    Kakao.Link.sendScrap({
        requestUrl: location.href,
        templateId: 82911,
        templateArgs: {
            TITLE: og('title', '하나님의 교회 지식사전'),
            DESC: og('description'),
            THUMB: thumb(),
            PAGE: path(),
        },
    });
    function og(name, defaultVal) {
        var $meta = document.querySelector('meta[property="og:' + name + '"]');
        if ($meta) return $meta.getAttribute('content');
        else return defaultVal ? defaultVal : '';
    }
    function thumb() {
        var img = og('image');
        if (!img) {
            var $img = document.querySelector('img[src]');
            if ($img) {
                img = $img.src;
            }
        }
        if (img.indexOf('http') != 0) img = location.origin + (img[0] == '/' ? img : '/' + img);
        return img;
    }
    function path() {
        if (location.pathname[0] == '/') return location.pathname.substring(1) + location.search;
        else return location.pathname + location.search;
    }
}
// 앨범 레이아웃 보정
updateAllAlbum();
window.addEventListener('load', updateAllAlbum);
window.addEventListener('resize', updateAllAlbum);
function updateAllAlbum() {
    var $albums = document.querySelectorAll('.custom-album');
    for (var i = 0; i < $albums.length; i++) {
        updateAlbum($albums[i]);
    }
}
function updateAlbum($elem) {
    var lineMax = 3;
    for (var i = 0; i < $elem.classList.length; i++) {
        if ($elem.classList[i].indexOf('line-max-') == 0) {
            lineMax = Number($elem.classList[i].replace('line-max-', ''));
        }
    }
    var totalWidth = $elem.clientWidth;
    if ($elem.children.length > 0) {
        for (var i = $elem.children.length - 1; i >= 0; i--) {
            if (!$elem.children[i].classList.contains('albumitem')) {
                $elem.children[i].remove();
                continue;
            }
            $elem.children[i].style.width = '';
            $elem.children[i].style.height = '';
        }
        if (window.innerWidth < 720) return;
        var lineTotalRatio = [];
        for (var i = 0; i < $elem.children.length; i++) {
            var lineIdx = Math.floor(i / lineMax);
            var $img = $elem.children[i].querySelector('img');
            if (!$img || $img.naturalWidth == 0) continue;
            if (lineTotalRatio[lineIdx] == undefined) {
                lineTotalRatio[lineIdx] = 0;
            }
            lineTotalRatio[lineIdx] += $img.naturalWidth / $img.naturalHeight;
        }
        for (var i = 0; i < $elem.children.length; i++) {
            var totalRatio = lineTotalRatio[Math.floor(i / lineMax)];
            var $img = $elem.children[i].querySelector('img');
            if (!$img || $img.naturalWidth == 0) continue;
            var ratio = $img.naturalWidth / $img.naturalHeight;
            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';
}
window.addEventListener('load', function () {
    if (mw.user.getId() == 0) {
        var $tb = document.querySelector('.mw-portlet-tb');
        if ($tb) $tb.parentElement.removeChild($tb);
    }
});
// 데스크탑 언어
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://watv.kr/en" title="Church of God Knowledge Encyclopedia"><span>English (영어)</span></a></li>' +
    '<li class="mw-list-item"><a href="https://watv.kr/es" title="ChurchEnciclopedia de conocimiento de la Iglesia de Dios"><span>Spanish</span></a></li>' +
    '<li class="mw-list-item"><a href="https://watv.kr/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://watv.kr/ne" title="नेपाली"><span>Nepali</span></a></li>' +
    '<li class="mw-list-item"><a href="https://watv.kr/pt" title="ENCICLOPÉDIA DO CONHECIMENTO DA IGREJA DE DEUS"><span>português</span></a></li>' +
  '</ul>' +
'</div>' +
'</nav>';
langDiv.insertAdjacentHTML('afterbegin', navHTML);
}
}