잔글편집 요약 없음 |
잔글편집 요약 없음 |
||
| 25번째 줄: | 25번째 줄: | ||
}); | }); | ||
class DeleterReplacer { | |||
constructor(element) { | |||
this.element = element; | |||
this.originalString = element.getAttribute('string-deleter-replacer') || element.textContent.trim(); | |||
this.finalString = element.getAttribute('result') || '[Removed]'; | |||
step++; | this.delay = parseInt(element.getAttribute('delete-delay')) || 50; | ||
if (step <= maxSteps) { | this.deleteSpeed = parseInt(element.getAttribute('delete-speed')) || 5; | ||
this.currentString = this.originalString; | |||
this.step = 0; | |||
for ( | this.maxSteps = Math.ceil(this.originalString.length / this.deleteSpeed) + 3; | ||
if (currentString.charAt(i) !== '█') { | this.intervalId = null; | ||
this.element.textContent = this.originalString; | |||
this.start(); | |||
} | |||
transformStep() { | |||
this.step++; | |||
if (this.step <= this.maxSteps) { | |||
const charsToReplace = Math.min(this.deleteSpeed, this.currentString.length); | |||
let indices = []; | |||
for (let i = 0; i < this.currentString.length; i++) { | |||
if (this.currentString.charAt(i) !== '█') { | |||
indices.push(i); | indices.push(i); | ||
}; | }; | ||
}; | }; | ||
for ( | for (let i = 0; i < charsToReplace && indices.length > 0; i++) { | ||
const randomIndex = Math.floor(Math.random() * indices.length); | |||
const charIndex = indices[randomIndex]; | |||
currentString = currentString.substring(0, charIndex) + '█' + currentString.substring(charIndex + 1); | this.currentString = this.currentString.substring(0, charIndex) + '█' + this.currentString.substring(charIndex + 1); | ||
indices.splice(randomIndex, 1); | indices.splice(randomIndex, 1); | ||
}; | }; | ||
if (currentString.replace(/█/g, '').length < 5) { | if (this.currentString.replace(/█/g, '').length < 5) { | ||
currentString = currentString.replace(/[^█]/g, '█'); | this.currentString = this.currentString.replace(/[^█]/g, '█'); | ||
}; | }; | ||
element.textContent = currentString; | this.element.textContent = this.currentString; | ||
} else if (step === maxSteps + 1) { | } else if (this.step === this.maxSteps + 1) { | ||
element.textContent = finalString.substring(0, 3) || ''; | this.element.textContent = this.finalString.substring(0, 3) || ''; | ||
} else if (step === maxSteps + 2) { | } else if (this.step === this.maxSteps + 2) { | ||
element.textContent = finalString; | this.element.textContent = this.finalString; | ||
clearInterval(intervalId); | clearInterval(this.intervalId); | ||
}; | }; | ||
}, delay); | }; | ||
start() { | |||
this.intervalId = setInterval(() => this.transformStep(), this.delay); | |||
}; | |||
}; | }; | ||
$(function() { | |||
const sdrElements = document.querySelectorAll('i[string-deleter-replacer]'); | |||
sdrElements.forEach(element => { | |||
new DeleterReplacer(element); | |||
}); | |||
}; | |||
}); | }); | ||
}); | }); | ||
2025년 11월 16일 (일) 15:54 판
/* 이 자바스크립트 설정은 모든 문서, 모든 사용자에게 적용됩니다. */
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);
}
});
class DeleterReplacer {
constructor(element) {
this.element = element;
this.originalString = element.getAttribute('string-deleter-replacer') || element.textContent.trim();
this.finalString = element.getAttribute('result') || '[Removed]';
this.delay = parseInt(element.getAttribute('delete-delay')) || 50;
this.deleteSpeed = parseInt(element.getAttribute('delete-speed')) || 5;
this.currentString = this.originalString;
this.step = 0;
this.maxSteps = Math.ceil(this.originalString.length / this.deleteSpeed) + 3;
this.intervalId = null;
this.element.textContent = this.originalString;
this.start();
}
transformStep() {
this.step++;
if (this.step <= this.maxSteps) {
const charsToReplace = Math.min(this.deleteSpeed, this.currentString.length);
let indices = [];
for (let i = 0; i < this.currentString.length; i++) {
if (this.currentString.charAt(i) !== '█') {
indices.push(i);
};
};
for (let i = 0; i < charsToReplace && indices.length > 0; i++) {
const randomIndex = Math.floor(Math.random() * indices.length);
const charIndex = indices[randomIndex];
this.currentString = this.currentString.substring(0, charIndex) + '█' + this.currentString.substring(charIndex + 1);
indices.splice(randomIndex, 1);
};
if (this.currentString.replace(/█/g, '').length < 5) {
this.currentString = this.currentString.replace(/[^█]/g, '█');
};
this.element.textContent = this.currentString;
} else if (this.step === this.maxSteps + 1) {
this.element.textContent = this.finalString.substring(0, 3) || '';
} else if (this.step === this.maxSteps + 2) {
this.element.textContent = this.finalString;
clearInterval(this.intervalId);
};
};
start() {
this.intervalId = setInterval(() => this.transformStep(), this.delay);
};
};
$(function() {
const sdrElements = document.querySelectorAll('i[string-deleter-replacer]');
sdrElements.forEach(element => {
new DeleterReplacer(element);
});
});
});