Google Applied Digital Skillsのウェブサイトの「編集ツールの作成」プロジェクトに取り組んでいました。編集ツールを作成していたとき、私は2つの不具合に遭遇しました。 1つは、単語 "som"が強調表示されているということです。もう一つは、「英雄」という言葉が強調表示されていることです。これは間違いなくバグのように見えます。なぜなら、 "ヒーロー"は "ヒーロー"と同じ色で強調表示されているからです。これは私が作ったエラーである場合これはGoogle Appsスクリプトのバグですか?
は誰もが知っていますかそれはグリッチですか?ここ はコードです:
function findText(item) {
//choose a random color as the background
//credit to James from https://stackoverflow.com/questions/1484506/random-color-generator
var background = '#' + (Math.random().toString(16) + "000000").substring(2, 8)
//log the item being found to make sure it is being searched for
Logger.log(item)
//shows the computer what the search result is
var searchResult
//find the search result
searchResult = DocumentApp.getActiveDocument().getBody().findText(item)
//put it in the log
Logger.log(searchResult)
//loop until item is no longer found
while (searchResult !== null) {
//change the background color for a set space, which is when item is first used.
searchResult.getElement().asText().setBackgroundColor(searchResult.getStartOffset(), searchResult.getEndOffsetInclusive(), background)
//find the text again
searchResult = DocumentApp.getActiveDocument().getBody().findText(item, searchResult)
//end of the loop
}
}
function highlightProblem() {
//array showing all values of item
var words = ["very", "Very", "totally", "Totally", "heroic", "Heroic", "really", "Really", "so ", "so. ", "so, ", "So ", "So. ", "So, ", "its", "Its", "good", "Good", "examples", "Examples", "hero ", "hero. ", "hero, ", "Hero ", "Hero. ", "Hero, "]
//find each item in the array
words.forEach(findText)
}