SHOW:
|
|
- or go back to the newest paste.
1 | const addLinks = (searchPhrase, hyperlink) => { | |
2 | const document = DocumentApp.getActiveDocument(); | |
3 | const body = document.getBody(); | |
4 | let search = null; | |
5 | let count = 0; | |
6 | while (count < 1 && (search = body.findText(searchPhrase, search))) { | |
7 | const searchElement = search.getElement(); | |
8 | const startIndex = search.getStartOffset(); | |
9 | const endIndex = search.getEndOffsetInclusive(); | |
10 | searchElement.asText().setLinkUrl(startIndex, endIndex, hyperlink); | |
11 | count++; | |
12 | } | |
13 | document.saveAndClose(); | |
14 | }; | |
15 | ||
16 | addLinks("Kiton", "https://2men.it/collections/kiton/"); |