Skip to content

Instantly share code, notes, and snippets.

@ttscoff
Last active May 4, 2016 13:56
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ttscoff/f995e84426df3c8d3428 to your computer and use it in GitHub Desktop.
Save ttscoff/f995e84426df3c8d3428 to your computer and use it in GitHub Desktop.
A &#%$ing JavaScript snippet for TextExpander to automatically censor naughtiness with !%@#. #!@& that's cool.
// modify/duplicate the other snippets in this group, using
// the abbreviation to define words to replace with "swear" characters
function censor (input) {
var badWord = input.replace(/((er)?s?|ing)?$/, '');
return input.replace(badWord, censored(badWord));
}
function shuffleArray(inputArr) {
var array = inputArr.slice(0);
for (var i = array.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
function censored (word) {
var chars = '#@!$%*&^¡ø'.split(''),
output = '';
while (output.length < word.length) {
output += shuffleArray(chars).join('');
}
return output.substr(0,word.length).replace('$&', '$$$&');
}
TextExpander.appendOutput(censor(TextExpander.triggeringAbbreviation));
@ttscoff
Copy link
Author

ttscoff commented Oct 3, 2015

More info on my blog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment