Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function onOpen() {
- DocumentApp.getUi()
- .createMenu('Utilities')
- .addItem('Auto-Replace', 'replaceSuits')
- .addToUi();
- };
- function replaceSuits() {
- var body = DocumentApp.getActiveDocument().getBody();
- var text = body.editAsText();
- var found = body.findText("♥");
- while (found) {
- var elem = found.getElement();
- if (found.isPartial()) {
- var start = found.getStartOffset();
- var end = found.getEndOffsetInclusive();
- elem.setForegroundColor(start, end, "#ff0000");
- }
- else {
- elem.setForegroundColor("#ff0000");
- }
- found = body.findText("♥", found);
- }
- found = body.findText("♦");
- while (found) {
- var elem = found.getElement();
- if (found.isPartial()) {
- var start = found.getStartOffset();
- var end = found.getEndOffsetInclusive();
- elem.setForegroundColor(start, end, "#ff8100");
- }
- else {
- elem.setForegroundColor("##ff8100");
- }
- found = body.findText("♦", found);
- }
- found = body.findText("♣");
- while (found) {
- var elem = found.getElement();
- if (found.isPartial()) {
- var start = found.getStartOffset();
- var end = found.getEndOffsetInclusive();
- elem.setForegroundColor(start, end, "#00b700");
- }
- else {
- elem.setForegroundColor("#00b700");
- }
- found = body.findText("♣", found);
- }
- found = body.findText("♠");
- while (found) {
- var elem = found.getElement();
- if (found.isPartial()) {
- var start = found.getStartOffset();
- var end = found.getEndOffsetInclusive();
- elem.setForegroundColor(start, end, "#0000ff");
- }
- else {
- elem.setForegroundColor("#0000ff");
- }
- found = body.findText("♠", found);
- }
- };
Add Comment
Please, Sign In to add comment