Snippets Collections
/**
 * 
 * 
 * This Google Script will delete everything in your Gmail account.
 * It removes email messages, filters, labels and reset all your settings
 * 
 * Written by Amit Agarwal (amit@labnol.org)
 

         88                                                           
         88                                                           
         88                                                           
 ,adPPYb,88 ,adPPYYba, 8b,dPPYba,   ,adPPYb,d8  ,adPPYba, 8b,dPPYba,  
a8"    `Y88 ""     `Y8 88P'   `"8a a8"    `Y88 a8P_____88 88P'   "Y8  
8b       88 ,adPPPPP88 88       88 8b       88 8PP""""""" 88          
"8a,   ,d88 88,    ,88 88       88 "8a,   ,d88 "8b,   ,aa 88          
 `"8bbdP"Y8 `"8bbdP"Y8 88       88  `"YbbdP"Y8  `"Ybbd8"' 88          
                                    aa,    ,88                        
                                     "Y8bbdP"                         
 
 
 * Proceed with great caution since the process is irreversible
 * 
 * This software comes with ABSOLUTELY NO WARRANTY. 
 * This is free software, and you are welcome to modify and redistribute it 
 *
 * This permission notice shall be included in all copies of the Software.
 *
 *
 */


/**
 * Remove all labels in Gmail
 */
const deleteGmailLabels_ = ()  => {
  GmailApp.getUserLabels().forEach((label) => {
    label.deleteLabel();
  });
};

/**
 * Remove all Gmail Filters
 */
const deleteGmailFilters_ = ()  => {
  const { filter: gmailFilters } = Gmail.Users.Settings.Filters.list('me');
  gmailFilters.forEach(({ id }) => {
    Gmail.Users.Settings.Filters.remove('me', id);
  });
};

/**
 * Remove all Gmail Draft messages
 */
const deleteGmailDrafts_ = ()  => {
  GmailApp.getDrafts().forEach((draft) => {
    draft.deleteDraft();
  });
};

/**
 * Reset Gmail Settings
 */
const resetGmailSettings_ = ()  => {
  // Disable Out-of-office
  Gmail.Users.Settings.updateVacation({ enableAutoReply: false }, 'me');

  // Delete Gmail Signatures
  const { sendAs } = Gmail.Users.Settings.SendAs.list('me');
  sendAs.forEach(({ sendAsEmail }) => {
    Gmail.Users.Settings.SendAs.update({ signature: '' }, 'me', sendAsEmail);
  });

  // Disable IMAP
  Gmail.Users.Settings.updateImap({ enabled: false }, 'me');

  // Disable POP
  Gmail.Users.Settings.updatePop({ accessWindow: 'disabled' }, 'me');

  // Disable Auto Forwarding
  const { forwardingAddresses } = Gmail.Users.Settings.ForwardingAddresses.list('me');
  forwardingAddresses.forEach(({ forwardingEmail }) => {
    Gmail.Users.Settings.ForwardingAddresses.remove('me', forwardingEmail);
  });
};

const startTime = Date.now();
const isTimeLeft_ = ()  => {
  const ONE_SECOND = 1000;
  const MAX_EXECUTION_TIME = ONE_SECOND * 60 * 5;
  return MAX_EXECUTION_TIME > Date.now() - startTime;
};

/**
 * Move all Gmail threads to trash folder
 */
const deleteGmailThreads_ = ()  => {
  let threads = [];
  do {
    threads = GmailApp.search('in:all', 0, 100);
    if (threads.length > 0) {
      GmailApp.moveThreadsToTrash(threads);
      Utilities.sleep(1000);
    }
  } while (threads.length && isTimeLeft_());
};

/**
 * Move all Spam email messages to the Gmail Recyle bin
 */
const deleteSpamEmails_ = ()  => {
  let threads = [];
  do {
    threads = GmailApp.getSpamThreads(0, 10);
    if (threads.length > 0) {
      GmailApp.moveThreadsToTrash(threads);
      Utilities.sleep(1000);
    }
  } while (threads.length && isTimeLeft_());
};

/**
 * Permanetly empty the Trash folder
 */
const emptyGmailTrash_ = ()  => {
  let threads = [];
  do {
    threads = GmailApp.getTrashThreads(0, 100);
    threads.forEach((thread) => {
      Gmail.Users.Threads.remove('me', thread.getId());
    });
  } while (threads.length && isTimeLeft_());
};

/**
 * Factory Reset your Gmail Account
 * Replace NO with YES and run this function
 * */
const factoryResetGmail = ()  => {
  const FACTORY_RESET = 'NO';
  if (FACTORY_RESET === 'YES') {
    resetGmailSettings_();
    deleteGmailLabels_();
    deleteGmailFilters_();
    deleteGmailDrafts_();
    deleteGmailThreads_();
    deleteSpamEmails_();
    emptyGmailTrash_();
  }
};

function getDirection() {

  

  // DECLARE SHEET

  var ss = SpreadsheetApp.getActiveSpreadsheet();

  var mapSheet = ss.getSheetByName("MAP");

  

  var start = mapSheet.getRange('B1').getValue();

  var end = mapSheet.getRange('B2').getValue();

  

  var directions = Maps.newDirectionFinder()

    .setOrigin(start)

    .setDestination(end)

    .setMode(Maps.DirectionFinder.Mode.DRIVING)

    .getDirections();

  

  //Logger.log(directions.routes[0].legs[0].duration.text);

 

  //CLEAR QUESTION AND ANSWER

  mapSheet.getRange('A6:D500').clear();

  

  //NEXT ROW ON MAP SHEET

  var nextRow = mapSheet.getLastRow() + 1;

 

  for (var i = 0; i < directions.routes[0].legs.length; i++) 

  {

    var endAddress = directions.routes[0].legs[i].end_address;

    var startAddress = directions.routes[0].legs[i].start_address;

    var distance = directions.routes[0].legs[i].distance.text;

    var duration = directions.routes[0].legs[i].duration.text;

    

    mapSheet.getRange(nextRow,1).setValue(startAddress);

    mapSheet.getRange(nextRow,2).setValue(endAddress);

    mapSheet.getRange(nextRow,3).setValue(distance);

    mapSheet.getRange(nextRow,4).setValue(duration);

    

    nextRow++;

 

  }

}

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension