function onInstall(e) {
onOpen();
}
function onOpen(e) {
try {
var ui = DocumentApp.getUi();
var menu = ui.createAddonMenu();
menu.addItem('Google Sans','setFontDocs');
menu.addToUi();
} catch(e) {
try {
var ui = SlidesApp.getUi();
var menu = ui.createAddonMenu();
menu.addItem('Google Sans','setFontSlides');
menu.addToUi();
} catch(e) {
var ui = SpreadsheetApp.getUi();
var menu = ui.createAddonMenu();
menu.addItem('Google Sans','setFontSheets');
menu.addToUi();
}
}
}
function setFontDocs() {
try {
const selection = DocumentApp.getActiveDocument().getSelection();
const element = selection.getRangeElements()[0];
element
.getElement()
.asText()
.setFontFamily(
element.getStartOffset(),
element.getEndOffsetInclusive(),
"Google Sans"
);
} catch(e) {
console.log(e);
}
}
function setFontSlides() {
try {
const selection = SlidesApp.getActivePresentation().getSelection();
selection.getTextRange().getTextStyle().setFontFamily('Google Sans');
} catch(e) {
console.log(e);
}
}
function setFontSheets() {
try {
var cell = SpreadsheetApp.getActive().getSelection().getActiveRange().setFontFamily('Google Sans');
} catch(e) {
console.log(e);
}
}