Skip to content

Instantly share code, notes, and snippets.

@gifguide2code
Created August 18, 2018 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gifguide2code/d15ef523fbc1da54b2db4f61561db3e4 to your computer and use it in GitHub Desktop.
Save gifguide2code/d15ef523fbc1da54b2db4f61561db3e4 to your computer and use it in GitHub Desktop.
A script to randomize all the character colors in a Google Doc. Use with caution.
function Multicolor() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
//This Loops Through All Paragraphs
for(var i=0; i<body.getNumChildren(); i++) {
var par = body.getChild(i);
//This Loops Through Paragraph Children
for(var y=0; y<par.getNumChildren(); y++) {
var txt = par.asParagraph().getChild(y);
var len = txt.asText().getText().length;
Logger.log(y);
//This Loops Through Text Within Each Paragraph
for(var x=0; x< len; x++) {
var randomR = Math.round((Math.random() * 255));
var randomG = Math.round((Math.random() * 255));
var randomB = Math.round((Math.random() * 255));
string = txt.asText().getText().charAt(x);
rgbHex = rgbToHex(randomR, randomG, randomB);
txt.asText().setForegroundColor(x,x,rgbHex);
};
};
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment