EDUrocks's picture
Add files using upload-large-folder tool
77bd40d verified
Raw History Blame Contribute Delete
1.96 kB
function encrypt(plain, cipher, text) {
plain = plain + plain.toUpperCase();
cipher = cipher + cipher.toUpperCase();
var newText = '';
for(var i=0; i<text.length; i++) {
var c = text.charAt(i);
var index = plain.indexOf(c);
if(index >= 0 && index < cipher.length) {
newText += cipher.charAt(index);
} else {
newText += c;
}
}
return newText;
}
document.addEventListener('DOMContentLoaded', function() {
var plain = "abcdefghijklmnopqrstuvwxyz";
var cipher = "nopqrstuvwxyzabcdefghijklm";
function walk(node) {
if (node.nodeType === 3) { // Text node
var original = node.nodeValue;
if (original.trim().length > 0) {
// Check if parent is a script, style, or the logo
var parent = node.parentElement;
if (parent.tagName === 'SCRIPT' || parent.tagName === 'STYLE' || parent.closest('#site-logo')) {
return;
}
// Encrypt text
var encrypted = encrypt(plain, cipher, original);
// Create a wrapper span with the ROT13 font class
var span = document.createElement('span');
span.className = 'rot13-font';
span.textContent = encrypted;
// Replace the text node with the span
parent.replaceChild(span, node);
}
} else if (node.nodeType === 1 && node.nodeName !== 'SCRIPT' && node.nodeName !== 'STYLE') {
// Element node, recurse
// Avoid recursing into the logo
if (node.id === 'site-logo') return;
var children = Array.from(node.childNodes);
for (var i = 0; i < children.length; i++) {
walk(children[i]);
}
}
}
walk(document.body);
});