Last active
May 4, 2016 13:56
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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
More info on my blog.