-
-
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.
This file contains hidden or 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