SHARE
TWEET

Untitled

a guest Oct 10th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function main() {
  2.     onOpen()
  3. }
  4.  
  5. function onOpen() {
  6.     var doc = DocumentApp.getActiveDocument()
  7.         var body = doc.getBody()
  8.         var text = body.editAsText()
  9.         var colors = {
  10.             "Person 1: " : "#000000",
  11.             "Person 2: " : "#000000"
  12.         }
  13.     for (var person in colors) {
  14.         var textRangesArray = findAll(person, text)
  15.             for (var i = 0; i < textRangesArray.length; i++) {
  16.                 textRangesArray[i].getElement().setForegroundColor(textRangesArray[i].getStartOffset(), textRangesArray[i].getEndOffsetInclusive(), colors[person])
  17.                     textRangesArray[i].getElement().setBold(textRangesArray[i].getStartOffset(), textRangesArray[i].getEndOffsetInclusive(), true)
  18.             }
  19.     }
  20. }
  21.  
  22. function findAll(search, text) {
  23.     var instances = []
  24.         var foundElement = text.findText(search)
  25.         while (foundElement !== null) {
  26.             instances.push(foundElement)
  27.                 foundElement = text.findText(search, foundElement)
  28.         }
  29.     return instances
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top