미디어위키:Gadget-Vector.js
식물 vs 좀비 위키
참고: 설정을 저장한 후에 바뀐 점을 확인하기 위해서는 브라우저의 캐시를 새로 고쳐야 합니다.
- 파이어폭스 / 사파리: Shift 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5 또는 Ctrl-R을 입력 (Mac에서는 ⌘-R)
- 구글 크롬: Ctrl-Shift-R키를 입력 (Mac에서는 ⌘-Shift-R)
- 엣지: Ctrl 키를 누르면서 새로 고침을 클릭하거나, Ctrl-F5를 입력.
(function () {
'use strict';
var SPIN_CLASS = 'pvz-watch-spinning';
var WATCHED_CLASS = 'pvz-watch-watched';
var NOT_WATCHED_CLASS = 'pvz-watch-not-watched';
var SPIN_TIME = 360;
var cleanupTimer = 0;
function getContainer() {
return document.querySelector(
'#ca-watch, #ca-unwatch, li.mw-watchlink, a.mw-watchlink'
);
}
function getLink(container) {
if (!container) {
return null;
}
return container.matches('a') ? container : container.querySelector('a');
}
function applyState(isWatched) {
var container = getContainer();
if (!container) {
return;
}
container.classList.toggle(WATCHED_CLASS, !!isWatched);
container.classList.toggle(NOT_WATCHED_CLASS, !isWatched);
}
function syncFromMarkup() {
var container = getContainer();
var link = getLink(container);
var href;
if (!container || !link) {
return;
}
href = link.getAttribute('href') || '';
applyState(
container.id === 'ca-unwatch' ||
href.indexOf('action=unwatch') !== -1
);
}
function spin() {
var container = getContainer();
if (!container) {
return;
}
window.clearTimeout(cleanupTimer);
container.classList.remove(SPIN_CLASS);
void container.offsetWidth;
container.classList.add(SPIN_CLASS);
cleanupTimer = window.setTimeout(function () {
container.classList.remove(SPIN_CLASS);
}, SPIN_TIME + 40);
}
function handleClick(event) {
var link = event.target.closest(
'#ca-watch > a, #ca-unwatch > a, li.mw-watchlink > a, a.mw-watchlink'
);
if (link) {
spin();
}
}
function shortenHistoryLabel() {
var historyLink = document.querySelector('#ca-history > a');
if (!historyLink) {
return;
}
Array.prototype.forEach.call(historyLink.childNodes, function (node) {
if (node.nodeType === Node.TEXT_NODE) {
node.nodeValue = node.nodeValue.replace(/역사 보기/g, '역사');
}
});
if (historyLink.textContent.trim() === '역사 보기') {
historyLink.textContent = '역사';
}
historyLink.setAttribute('title', '역사');
}
function init() {
var observer;
shortenHistoryLabel();
syncFromMarkup();
document.addEventListener('click', handleClick, true);
observer = new MutationObserver(function () {
shortenHistoryLabel();
syncFromMarkup();
});
observer.observe(document.body, {
subtree: true,
childList: true,
attributes: true,
attributeFilter: ['id', 'href']
});
if (window.mw && mw.hook) {
mw.hook('wikipage.watchlistChange').add(function (isWatched) {
applyState(isWatched);
spin();
});
}
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init, { once: true });
} else {
init();
}
}());
(function () {
'use strict';
function installContentSearch() {
var content = document.querySelector('.skin-vector-legacy #content');
var form = document.querySelector('#searchform');
var wrapper;
if (!content || !form) {
return;
}
wrapper = document.getElementById('pvz-content-search');
if (!wrapper) {
wrapper = document.createElement('div');
wrapper.id = 'pvz-content-search';
wrapper.setAttribute('role', 'search');
wrapper.setAttribute('aria-label', '사이트 검색');
content.insertBefore(wrapper, content.firstChild);
}
if (form.parentNode !== wrapper) {
wrapper.appendChild(form);
}
document.documentElement.classList.add('pvz-content-search-ready');
}
function initContentSearch() {
var observer;
installContentSearch();
observer = new MutationObserver(function () {
installContentSearch();
});
observer.observe(document.body, {
childList: true,
subtree: true
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initContentSearch, { once: true });
} else {
initContentSearch();
}
}());
