Diferencia entre revisiones de «MediaWiki:Common.js»

Sin resumen de edición
Sin resumen de edición
 
(No se muestran 6 ediciones intermedias del mismo usuario)
Línea 288: Línea 288:
if($fullMedia){
if($fullMedia){
$fullMedia.parentElement.removeChild($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);
}
}


Línea 324: Línea 301:
var pathLang = (location.pathname.split('/')[1] || '').toLowerCase();  
var pathLang = (location.pathname.split('/')[1] || '').toLowerCase();  
var lang = (mw.config && mw.config.get('wgContentLanguage'))  
var lang = (mw.config && mw.config.get('wgContentLanguage'))  
        || (['en','es','ko'].includes(pathLang) ? pathLang : 'ko');
        || (['en','es','ko','vi','pt','ne'].includes(pathLang) ? pathLang : 'ko');
console.log('GA4', lang);
// <head>에 gtag 로더 삽입
// <head>에 gtag 로더 삽입
var s = document.createElement('script');
var s = document.createElement('script');
Línea 337: Línea 313:
gtag('js', new Date());
gtag('js', new Date());
// 🔹 자동 page_view 끄기
gtag('config', GA_ID, {
send_page_view: false
});
// page_view 설정: 언어 서브디렉터리 포함 경로를 명시
// page_view 설정: 언어 서브디렉터리 포함 경로를 명시
gtag('config', GA_ID, {
gtag('config', GA_ID, {
page_path: location.pathname + location.search
page_path: location.pathname + location.search
});
});


// 언어를 사용자 속성으로 항상 전송(보고서에서 맞춤차원으로 필터)
// 언어를 사용자 속성으로 항상 전송(보고서에서 맞춤차원으로 필터)
gtag('set', 'user_properties', { site_language: lang });
    gtag('set', 'user_properties', {
        site_language: lang,
// (선택) 콘텐츠 그룹도 언어로 고정해두면 탐색에서 편함
        browser_language: navigator.language || navigator.userLanguage
// gtag('event', 'page_view', { content_group: lang }); // 필요 시 사용
    });
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 () {
    // 언어 이름 매핑 : lang code → 영어 언어 이름
    const langMap = {
        'ko': 'Coreano',
        'en': 'Inglés',
        'es': 'Español',
        'vi': 'Vietnamita',
        'ne': 'Nepalí',
        'pt': 'Portugués'
    };
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);
    });
});