Kumi
0777f287e3
Changed URL query parameter from 'duckmode' to 'lang=quack' to improve clarity and maintain consistency with other language parameter conventions. This update helps ensure better readability and uniformity across the application.
30 lines
908 B
JavaScript
30 lines
908 B
JavaScript
|
|
// Function to transform a word to "quack", preserving capitalization
|
|
function toQuack(word) {
|
|
if (word.length > 1 && word === word.toUpperCase()) {
|
|
return 'QUACK';
|
|
} else if (word[0] === word[0].toUpperCase()) {
|
|
return 'Quack';
|
|
} else {
|
|
return 'quack';
|
|
}
|
|
}
|
|
|
|
// Function to replace text with "quack", preserving punctuation
|
|
function translateToDuckLanguage(node) {
|
|
if (node.nodeType === Node.TEXT_NODE) {
|
|
if (node.textContent.trim()) {
|
|
node.textContent = node.textContent.replace(
|
|
/\b[a-zA-Z]+\b/g,
|
|
match => toQuack(match)
|
|
);
|
|
}
|
|
} else {
|
|
node.childNodes.forEach(translateToDuckLanguage);
|
|
}
|
|
}
|
|
|
|
// Translate if the "lang=quack" parameter is present in the URL
|
|
if (window.location.search.includes('lang=quack')) {
|
|
document.body.childNodes.forEach(translateToDuckLanguage);
|
|
}
|