File size: 1,963 Bytes
77bd40d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | 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);
}); |