MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
 
(116 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);


//Google Analytics
//파일중복 메세지 제거
var GoogleCdn = document.createElement('script');
var $duplicates = document.getElementById('mw-imagepage-section-duplicates');
GoogleCdn.src = 'https://www.googletagmanager.com/gtag/js?id=G-LTWMMR6YSB';
if($duplicates) $duplicates.parentElement.removeChild($duplicates);
document.body.appendChild(GoogleCdn);
}else{
window.dataLayer = window.dataLayer || [];
$searchBox = document.querySelector('.mw-htmlform-ooui-wrapper');
function gtag() {
if($searchBox) $searchBox.style.display = 'block';
    dataLayer.push(arguments);
}
}
gtag('js', new Date());
gtag('config', 'G-LTWMMR6YSB');


/* TOP 버튼 */
/* TOP 버튼 */
Line 63: Line 75:
var mouseY=0;
var mouseY=0;
/* 각주 팝업창 위치 보정 DOM */
/* 각주 팝업창 위치 보정 DOM */
document.body.addEventListener('DOMNodeInserted', function (e) {
var observer = new MutationObserver(function (mutationList) {
    if (e.target.classList && e.target.classList.contains('rt-tooltip')) {
    mutationList.forEach(function (mutation) {
console.log('contains mouseover');
        mutation.addedNodes.forEach(function (node) {
 
            if (node.classList && (node.classList.contains('mwe-popups')|| node.classList.contains('rt-tooltip'))) {
        //var referenceId = e.target.getAttribute('href').replace('#', '');
                requestAnimationFrame(function () {
        //var popup = document.getElementById(referenceId);
                    var bodyLeft = document.body.getBoundingClientRect().left;
        var popup = e.target;
                    var left = parseInt(window.getComputedStyle(node).left);
        console.log(popup);
                    node.style.left = left - bodyLeft + 'px';
        if (popup) {
                });
             showPopupAtMousePosition(popup);
             }
         }
         });
     }
     });
});
});
 
// 감시할 대상 설정
document.body.addEventListener('mouseover', function (e) {
observer.observe(document.body, {
mouseX = e.clientX;
    childList: true,
mouseY = e.clientY;
    subtree: true,
});
});
function showPopupAtMousePosition(popup) {
console.log(mouseX, mouseY);
    var windowHeight = window.innerHeight;
    var windowWidth = window.innerWidth;
    var popupHeight = popup.clientHeight;
    var popupWidth = popup.clientWidth;
    var popupTop = mouseY + 20;
    var popupLeft = mouseX + 20;
    // 팝업이 브라우저 창 아래쪽으로 벗어나는 경우
    if ((popupTop + popupHeight) > windowHeight) {
        popupTop = windowHeight - popupHeight - 20;
    }
    // 팝업이 브라우저 창 오른쪽으로 벗어나는 경우
    if ((popupLeft + popupWidth) > windowWidth) {
        popupLeft = windowWidth - popupWidth - 20;
    }
                var bodyLeft = document.body.getBoundingClientRect().left;
                var left = parseInt(window.getComputedStyle(popup).left);
console.log(left, bodyLeft, popupLeft);
    popup.style.top = mouseX + 'px';
    popup.style.left = mouseY + 'px';
    popup.style.display = 'block';
}
/*
document.body.addEventListener(
    'DOMNodeInserted',
    function (e) {
        if (e.target.classList && e.target.classList.contains('rt-tooltip')) {
            requestAnimationFrame(function () {
                var bodyLeft = document.body.getBoundingClientRect().left;
                var left = parseInt(window.getComputedStyle(e.target).left);
                console.log(left, bodyLeft);
                e.target.style.left = left - bodyLeft + 'px';
            });
        }
    },
    false
);
*/


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


   
   
Line 312: Line 279:
     }
     }
}
}
//const bodyElem = document.querySelector('#bodyContent');
//bodyElem.classList.add("mw-body-content");


//const navigationElem = document.querySelector('.minerva-user-navigation');
//넘겨주기 문서를 숨깁니다.
//navigationElem.remove()
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);
}
/* GA4: single ID + language tagging (MediaWiki 1.42.3) */
(function () {
// 중복 로드 방지
if (window.__GA4_LOADED__) return;
window.__GA4_LOADED__ = true;
var GA_ID = 'G-YGT3D2Q9QW';
 
// 언어 결정: 가장 신뢰도 높은 wgContentLanguage, 없으면 경로 프리픽스로 보완
var pathLang = (location.pathname.split('/')[1] || '').toLowerCase();
var lang = (mw.config && mw.config.get('wgContentLanguage'))
        || (['en','es','ko','vi','pt','ne'].includes(pathLang) ? pathLang : 'ko');
// <head>에 gtag 로더 삽입
var s = document.createElement('script');
s.async = true;
s.src = 'https://www.googletagmanager.com/gtag/js?id=' + encodeURIComponent(GA_ID);
document.head.appendChild(s);
window.dataLayer = window.dataLayer || [];
function gtag(){ dataLayer.push(arguments); }
window.gtag = gtag;
gtag('js', new Date());
 
// 🔹 자동 page_view 끄기
gtag('config', GA_ID, {
send_page_view: false
});
    // 사용자 속성
    gtag('set', 'user_properties', {
        site_language: lang,
        browser_language: navigator.language || navigator.userLanguage
    });
 
    // page_view 이벤트
gtag('event', 'page_view', {
    page_location: location.href,
    page_path: location.pathname + location.search,
    page_title: document.title,
    content_group: lang
});
 
})();
mw.loader.using(['jquery']).then(function () {
    // ----------------------------
    // 1. 인터랭 텍스트 한국어 병기
    // ----------------------------
    const langMap = {
        'ko': 'Korean',
        'en': 'English',
        'es': 'Spanish',
        'vi': 'Vietnamese',
        'ne': 'Nepali',
        'pt': 'Portuguese'
    };
//다른 언어 텍스트
const languageLabel = $('#p-lang h3 .vector-menu-heading-label').text().trim();
    // 인터위키 언어 목록 선택자
    const $items = $('.vector-menu-content-list .interlanguage-link a');
 
    $items.each(function () {
        const $a = $(this);
 
        const langCode = $a.attr('lang'); // en, es, vi, ne, pt …
        const autonym = $a.find('span').text(); // English, Español, Tiếng Việt …
        const koreanName = langMap[langCode];
 
        if (!koreanName) return; // 배열에 없는 언어는 스킵
 
        // 이미 한국어 형식이 적용된 경우 중복 적용 방지
        if (autonym.includes('(')) return;
 
        // 링크 텍스트 변경: "English" → "English (영어)"
        $a.find('span').text(`${autonym} (${koreanName})`);
    });
   
    // ----------------------------
    // 2. 변환된 인터랭을 헤더로 복사
    // ----------------------------
    const $interLangList = $('#p-lang .vector-menu-content-list');
    if ($interLangList.length === 0) return;
 
    var langDiv = document.getElementById('right-navigation');
    if (!langDiv) return;
 
    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" class="vector-menu-checkbox" aria-labelledby="p-cactions-label">' +
            '<label id="p-cactions-label" class="vector-menu-heading">' +
                '<span class="select-language"></span>' +
                '<span class="vector-menu-heading-label">'+languageLabel+'</span>' +
            '</label>' +
            '<div class="vector-menu-content">' +
                '<ul class="vector-menu-content-list" id="header-lang-list"></ul>' +
            '</div>' +
        '</nav>';
 
    langDiv.insertAdjacentHTML('afterbegin', navHTML);
    const $headerList = $('#header-lang-list');
 
    // 변환된 인터랭 li 를 그대로 복사
    $interLangList.find('li.interlanguage-link').each(function () {
        const $a = $(this).find('a');
        const href = $a.attr('href');
        const title = $a.attr('title') || '';
        const text = $a.find('span').text();
 
        const newLi =
            '<li class="mw-list-item">' +
                '<a href="' + href + '" title="' + title + '">' +
                    '<span>' + text + '</span>' +
                '</a>' +
            '</li>';
 
        $headerList.append(newLi);
    });   
});