잔글편집 요약 없음 |
잔글편집 요약 없음 |
||
| 25번째 줄: | 25번째 줄: | ||
}); | }); | ||
function typeText(el, text, speed) { | |||
el.textContent = ''; | |||
let i = 0; | |||
const timer = setInterval(function () { | |||
el.textContent += text.charAt(i); | |||
i++; | |||
if (i >= text.length) clearInterval(timer); | |||
}, speed); | |||
} | |||
function initTyping() { | |||
var nodes = document.querySelectorAll('.mw-typing'); | |||
nodes.forEach(function (el) { | |||
// If already processed, skip | |||
if (el.dataset.typed === '1') return; | |||
const speed = parseInt(el.getAttribute('data-speed'), 10) || 40; // ms per char | |||
const original = el.textContent.trim(); | |||
// Optional: allow HTML inside by using data-text | |||
const dataText = el.getAttribute('data-text'); | |||
const text = dataText !== null ? dataText : original; | |||
// Prevent re-run | |||
el.dataset.typed = '1'; | |||
// If you want to preserve width to avoid layout shift: | |||
el.style.display = 'inline-block'; | |||
typeText(el, text, speed); | |||
}); | |||
} | |||
if (document.readyState === 'loading') { | |||
document.addEventListener('DOMContentLoaded', initTyping); | |||
} else { | |||
initTyping(); | |||
} | |||
mw.hook('wikipage.content').add(initTyping); | |||
}); | }); | ||
2026년 1월 2일 (금) 20:36 판
/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */
mw.loader.using(['mediawiki.util'], function() {
function generateRandomString(length) {
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()_+[]{}|;:,.<>?█▀▄▌▐';
var result = '';
for (var i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * characters.length));
};
return result;
};
var rsgelements = document.querySelectorAll('i[data-random-string]');
rsgelements.forEach(function(rsgelements) {
var length = parseInt(rsgelements.getAttribute('data-random-string'));
var interval = rsgelements.getAttribute('data-interval') === 'true';
var intervalTime = parseInt(rsgelements.getAttribute('data-intervaltime'));
if (interval) {
setInterval(function() {
rsgelements.textContent = generateRandomString(length);
}, intervalTime);
} else {
rsgelements.textContent = generateRandomString(length);
}
});
function typeText(el, text, speed) {
el.textContent = '';
let i = 0;
const timer = setInterval(function () {
el.textContent += text.charAt(i);
i++;
if (i >= text.length) clearInterval(timer);
}, speed);
}
function initTyping() {
var nodes = document.querySelectorAll('.mw-typing');
nodes.forEach(function (el) {
// If already processed, skip
if (el.dataset.typed === '1') return;
const speed = parseInt(el.getAttribute('data-speed'), 10) || 40; // ms per char
const original = el.textContent.trim();
// Optional: allow HTML inside by using data-text
const dataText = el.getAttribute('data-text');
const text = dataText !== null ? dataText : original;
// Prevent re-run
el.dataset.typed = '1';
// If you want to preserve width to avoid layout shift:
el.style.display = 'inline-block';
typeText(el, text, speed);
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initTyping);
} else {
initTyping();
}
mw.hook('wikipage.content').add(initTyping);
});