Mangler
const lookupReplacements = { // entities (like ∑ or Θ - are safer
// than just putting things inline like ∑ or ®
'a': ['A', 'Ä', '∆', 'á'],
'e': ['é', '∃'],
't': ['⊤', 'Τ'] ,
'b': ['β'],
'o': ['∅', '_o_']
}
function mangle(s) { return s.split``.map(letter => { const chars = lookupReplacements[letter]
return chars ? chars[
Math.floor(
chars.length * Math.random()
)
] : letter
}).join``
}
document.body.innerHTML = mangle('Been taking a break from making snippets... might start up again...<hr>')
document.body.innerHTML += mangle('Been taking a break from making snippets... might start up again...<hr>')
document.body.innerHTML += mangle('Been taking a break from making snippets... might start up again...<hr>')
Substitute some characters in a string with some random choices…
Pass a Class
function callMethods(evt) { const e = new evt
e.one()
e.two()
}
callMethods(class { one() { console.log('one') }
two() { console.log('two') }
})
This is so tempting for something I want to do… but too strange to use probably… maybe…
Mutation Observer
// Select the node that will be observed for mutations
const targetNode = document.getElementById('some-id');
// Options for the observer (which mutations to observe)
const config = { attributes: true, childList: true, subtree: true };
// Callback function to execute when mutations are observed
const callback = function(mutationsList, observer) { // Use traditional 'for loops' for IE 11 (goodbye IE11!!!!)
for(const mutation of mutationsList) { if (mutation.type === 'childList') { console.log('A child node has been added or removed.'); }
else if (mutation.type === 'attributes') { console.log('The ' + mutation.attributeName + ' attribute was modified.'); }
}
};
// Create an observer instance linked to the callback function
const observer = new MutationObserver(callback);
// Start observing the target node for configured mutations
observer.observe(targetNode, config);
// Later, you can stop observing
observer.disconnect();
This is pure gold if you haven’t used it… (from MDN)