Created
February 7, 2025 03:45
-
-
Save januridp/24fef062fed93c547ff76069c06ecc9e to your computer and use it in GitHub Desktop.
Google App Script for Highlight Words
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 highlight_words() { | |
var doc = DocumentApp.getActiveDocument(); | |
var words = ['DONE','WIP']; | |
var styleDone = { [DocumentApp.Attribute.BACKGROUND_COLOR]:'#9bcb98' }; //light-green | |
var styleWIP = { [DocumentApp.Attribute.BACKGROUND_COLOR]:'#ffc182' }; //light-orange | |
var pgfs = doc.getParagraphs(); | |
for (var word of words) for (var pgf of pgfs) { | |
if (word === 'DONE') { | |
var location = pgf.findText(word); | |
if (!location) continue; | |
var start = location.getStartOffset(); | |
var end = location.getEndOffsetInclusive(); | |
location.getElement().setAttributes(start, end, styleDone); | |
} | |
if (word === 'WIP') { | |
var location = pgf.findText(word); | |
if (!location) continue; | |
var start = location.getStartOffset(); | |
var end = location.getEndOffsetInclusive(); | |
location.getElement().setAttributes(start, end, styleWIP); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment