A script to randomize all the character colors in a Google Doc. Use with caution.
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
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