-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode
More file actions
22 lines (20 loc) · 687 Bytes
/
code
File metadata and controls
22 lines (20 loc) · 687 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
function onOpen() {
var ui = DocumentApp.getUi();
ui.createMenu('Replace')
.addItem('Character conversion (orgcolor→newcolor)', 'replaceTextColor')
.addToUi();
}
function replaceTextColor() {
const org_color = "#ffffff"; // enter old color in hex code
const replace_color = "#808080"; // enter new color in hex code
let app = DocumentApp.getUi();
let body = DocumentApp.getActiveDocument().getBody();
let obj = body.editAsText();
const text = body.getText();
for (let i = 0; i < text.length; i++) {
if (obj.getForegroundColor(i) == org_color) {
obj.setForegroundColor(i, i + 1, replace_color);
Logger.log("Change color: " + i);
}
}
}