Skip to content

Instantly share code, notes, and snippets.

@gifguide2code
Created August 13, 2018 00:07
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/96032d7b9a552f885668bd6e6a4bdd04 to your computer and use it in GitHub Desktop.
Save gifguide2code/96032d7b9a552f885668bd6e6a4bdd04 to your computer and use it in GitHub Desktop.
A script for Google Docs, gently turning white text to black in the first paragraph of a document.
function myFunction() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var paragraph = body.getChild(0);
var txt = paragraph.asParagraph().getChild(0); //This returns the text in the first paragraph.
var len = txt.asText().getText().length; //This returns the number of characters in the first paragraph.
Logger.log(len);
var red = 250;
var green = 250;
var blue = 250;
var incrementVal = 250/len;
var x = 0;
var rgbHex = rgbToHex(red, green, blue);
for (var i = 0; i<len; i++) {
string = txt.asText().getText().charAt(i);
if (red>0 && string!=" ") {
rgbHex = rgbToHex(red, green, blue);
txt.asText().setForegroundColor(i,i,rgbHex);
x = x + incrementVal
if (x>1) {
red = red-1;
green = green-1;
blue = blue-1;
x = 0
};
};
};
}
function componentToHex(c) {
var hex = c.toString(16);
return hex.length == 1 ? "0" + hex : hex;
}
function rgbToHex(r, g, b) {
return "#" + componentToHex(r) + componentToHex(g) + componentToHex(b);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment