Google Apps Script snippets ᕦʕ •ᴥ•ʔᕤ

Clear all events from a Calendar

Snippet

index.js
/**
 * On Homepage event trigger
 *
 * @param {GoogleAppsScript.Addons.EventObject} e Event Object
 * @returns {GoogleAppsScript.Card_Service.Card}
 */
function onHomepage(e) {
  return createTextCard();
}

/**
 * On Drive item selected event trigger
 *
 * @param {GoogleAppsScript.Addons.EventObject} e Event Object
 * @returns {GoogleAppsScript.Card_Service.Card}
 */
function onDriveItemsSelected(e) {
  const items = e.drive.selectedItems;
  const text = items.map((driveItem) => driveItem.title).join('\n');
  return createTextCard(text);
}

/**
 * Create Card
 *
 * @param {string} text Text
 * @param {boolean} isHomepage
 * @returns {GoogleAppsScript.Card_Service.Card}
 */
function createTextCard(text, isHomepage) {
  const message = isHomepage ? `HOMEPAGE\n${text}` : `${text}`;
  const textWidget = CardService.newTextParagraph().setText(message);
  const section = CardService.newCardSection().addWidget(textWidget);
  const card = CardService.newCardBuilder().addSection(section);
  return card.build();
}

Manifest

appsscript.json
{
  "timeZone": "Europe/Moscow",
  "dependencies": {},
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8",
  "oauthScopes": [
    "https://www.googleapis.com/auth/drive.addons.metadata.readonly"
  ],
  "addOns": {
    "common": {
      "name": "Google Apps Script Snippets",
      "logoUrl": "https://www.gstatic.com/images/icons/material/system/1x/pets_black_48dp.png",
      "homepageTrigger": {
        "runFunction": "onHomepage",
        "enabled": true
      }
    },
    "docs": {},
    "sheets": {},
    "slides": {},
    "gmail": {},
    "drive": {
      "onItemsSelectedTrigger": {
        "runFunction": "onDriveItemsSelected"
      }
    },
    "calendar": {}
  }
}

#calendar