Last active
June 21, 2019 09:53
-
-
Save Kungsgeten/9e2f429ad9a4649360242a88f25b2a87 to your computer and use it in GitHub Desktop.
Colored suit symbols in Google Docs
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 replaceStringAndSetColor(body, str, replacement, color) { | |
var foundElement = body.findText(str); | |
while (foundElement != null) { | |
var foundText = foundElement.getElement().asText(); | |
var start = foundElement.getStartOffset(); | |
var end = foundElement.getEndOffsetInclusive(); | |
foundText.setForegroundColor(start, end, color); | |
foundElement = body.findText(str, foundElement); | |
} | |
body.replaceText(str, replacement); | |
} | |
function suitSymbols() { | |
var body = DocumentApp.getActiveDocument().getBody(); | |
replaceStringAndSetColor(body, "!c", "♣", "#0000ff"); | |
replaceStringAndSetColor(body, "!d", "♦", "#ffa500"); | |
replaceStringAndSetColor(body, "!h", "♥", "#ff0000"); | |
replaceStringAndSetColor(body, "!s", "♠", "#000000"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When this script is run it will replace !c !d !h and !s with colored suit symbols.