自动突出显示 Google 文档中某些单词的脚本?
Script to auto highlight certain words in Google Docs?
我正在为 Google Docs 插件寻找一个简单的脚本,它将突出显示数组中的单词。我希望脚本在我键入时自动突出显示单词。这样够简单吗?
谢谢!
基于Can I color certain words in Google Document using Google Apps Script?
function highlight_words() {
var doc = DocumentApp.getActiveDocument();
var words = ['one','two','three'];
var style = { [DocumentApp.Attribute.BACKGROUND_COLOR]:'#FFFF00' };
var pgfs = doc.getParagraphs();
for (var word of words) for (var pgf of pgfs) {
var location = pgf.findText(word);
if (!location) continue;
var start = location.getStartOffset();
var end = location.getEndOffsetInclusive();
location.getElement().setAttributes(start, end, style);
}
}
我正在为 Google Docs 插件寻找一个简单的脚本,它将突出显示数组中的单词。我希望脚本在我键入时自动突出显示单词。这样够简单吗?
谢谢!
基于Can I color certain words in Google Document using Google Apps Script?
function highlight_words() {
var doc = DocumentApp.getActiveDocument();
var words = ['one','two','three'];
var style = { [DocumentApp.Attribute.BACKGROUND_COLOR]:'#FFFF00' };
var pgfs = doc.getParagraphs();
for (var word of words) for (var pgf of pgfs) {
var location = pgf.findText(word);
if (!location) continue;
var start = location.getStartOffset();
var end = location.getEndOffsetInclusive();
location.getElement().setAttributes(start, end, style);
}
}