Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. function findText(item) {
  2. var background = '#' + (Math.random().toString(16) + "000000").substring(2,8)
  3.  
  4. Logger.log(item)
  5.  
  6. var searchResult
  7.  
  8. searchResult = DocumentApp.getActiveDocument().getBody().findText(item)
  9.  
  10. Logger.log(searchResult)
  11.  
  12. while (searchResult !== null) {
  13.  
  14. searchResult.getElement().asText().setBackgroundColor(searchResult.getStartOffset(), searchResult.getEndOffsetInclusive(), background)
  15.  
  16. searchResult = DocumentApp.getActiveDocument().getBody().findText(item,searchResult)
  17.  
  18. }
  19.  
  20.  
  21. }
  22.  
  23.  
  24. function highlightProblem(){
  25.  
  26. var words = ["very", "so", "totally", "really", "for", "to"]
  27.  
  28. words.forEach(findText)
  29.  
  30. }
  31.  
  32. function onOpen(){
  33. DocumentApp.getUi().createMenu('Fix your trash').addItem('Highlight_Common_Mistake', 'highlightProblem').addToUi()
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement