Skip to content

Instantly share code, notes, and snippets.

@geminorum
Forked from ttscoff/TECensor.js
Created May 4, 2016 13:56
Show Gist options
  • Save geminorum/e2ddbfd6b7133843b9b46a121920cd77 to your computer and use it in GitHub Desktop.
Save geminorum/e2ddbfd6b7133843b9b46a121920cd77 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));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment