codeguy123
Apr 17th, 2023
245
0
Never
This is comment for paste Internal link script
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Replace with this code:
  2.  
  3. const addLinks = (searchPhrase, hyperlink) => {
  4. if (!searchPhrase) {
  5. return;
  6. }
  7.  
  8. const document = DocumentApp.getActiveDocument();
  9. const body = document.getBody();
  10. let search = null;
  11. let count = 0;
  12.  
  13. while (count < 1) {
  14. search = body.findText(searchPhrase, search ? search : null);
  15. if (!search) {
  16. break;
  17. }
  18. const searchElement = search.getElement();
  19. const startIndex = search.getStartOffset();
  20. const endIndex = search.getEndOffsetInclusive();
  21. searchElement.asText().setLinkUrl(startIndex, endIndex, hyperlink);
  22. count++;
  23. }
  24.  
  25. document.saveAndClose();
  26. };
  27.  
Advertisement
Add Comment
Please, Sign In to add comment