MediaWiki:Common.js: diferenças entre revisões
Sem resumo de edição |
Sem resumo de edição |
||
| (Há 15 revisões intermédias de 2 utilizadores que não estão a ser apresentadas) | |||
| Linha 23: | Linha 23: | ||
if($searchBox) $searchBox.style.display = 'block'; | if($searchBox) $searchBox.style.display = 'block'; | ||
} | } | ||
/* TOP 버튼 */ | /* TOP 버튼 */ | ||
| Linha 85: | Linha 73: | ||
} | } | ||
/* 각주 팝업창 위치 보정 */ | 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, | |||
}); | |||
/* 우클릭 방지 */ | /* 우클릭 방지 */ | ||
| Linha 289: | Linha 284: | ||
} | } | ||
/* 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'].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 | |||
}); | |||
gtag('event', 'page_view', { | |||
page_location: location.href, | |||
page_path: location.pathname + location.search, | |||
page_title: document.title, | |||
content_group: lang | |||
}); | |||
console.log('gtag', lang, document.title, navigator.language || navigator.userLanguage); | |||
})(); | |||
mw.loader.using(['jquery']).then(function () { | |||
// 언어 이름 매핑 : lang code → 스페인어 언어 이름 | |||
const langMap = { | |||
'ko': 'Coreano', | |||
'en': 'Inglês', | |||
'es': 'Espanhol', | |||
'vi': 'Vietnamita', | |||
'ne': 'Nepalês', | |||
'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); | |||
}); | |||
}); | |||
} | |||