Skip to content

Instantly share code, notes, and snippets.

@iowillhoit
Last active January 8, 2024 20:44
Show Gist options
  • Save iowillhoit/e1c462541ba5728f7fb09275f40090ee to your computer and use it in GitHub Desktop.
Save iowillhoit/e1c462541ba5728f7fb09275f40090ee to your computer and use it in GitHub Desktop.
This bookmarklet will copy all _visible_ meetings from Google calendar for the current day.
javascript:
var header = ":in:"; /* update if desired */
var splitOn = ", ";
/*
// This bookmarklet will copy all _visible_ meetings from Google calendar for the current day.
//
// Instructions:
// Navigate to your Google Calendar tab
// Make sure you are using the "Day", "4 Days", or "Week" view
// Make sure you are on the current week (select "Today")
// Hide calendars that you don't want listed.
// Click the bookmarklet
//
// Today's events will be copied to your clipboard and also logged in Chrome's console
//
// TODO: Remove events that have been declined
//
// ---
//
// Meeting details are in the following format:
// 1:30pm to 2pm, Test meeting, Eric Willhoit, Accepted, No location, October 18, 2021
// 2:30pm to 3pm, Another meeting, Eric Willhoit, Accepted, No location, October 18, 2021
//
// To grab the meeting name, we split the details on "," and grab the second item (index[1])
// Be warned, if you use a comma in your meeting name it will split on that one instead.
//
// You can get around this by adding the start of the Calendar Name to the `splitOn` variable above.
// In this case, I would change it to ", Eric" to ensure it does not spilt a meeting name containing a comma.
// The downside of this is that it only works for a single calendar. Choose your caveat.
*/
function copyText(text) {
var node = document.createElement('textarea');
var selection = document.getSelection();
node.textContent = text;
document.body.appendChild(node);
selection.removeAllRanges();
node.select();
document.execCommand('copy');
selection.removeAllRanges();
document.body.removeChild(node);
}
var view = document.querySelector('body').getAttribute('data-viewkey');
var allViews = {
DAY: 'Day',
CUSTOM_DAYS: '4 days',
WEEK: 'Week',
MONTH: 'Month',
YEAR: 'Year',
AGENDA: 'Schedule'
};
var supportedViews = {
DAY: 'Day',
CUSTOM_DAYS: '4 days',
WEEK: 'Week'
};
if(!Object.keys(supportedViews).includes(view)) {
console.log(`The "${allViews[view]}" view is not supported. Use one of the following: "${Object.values(supportedViews).join('", "')}".`);
throw new Error('Exiting');
}
var h2;
if (view === "DAY") {
h2 = document.querySelectorAll('[id*=tsc]')[0].parentElement;
} else {
var date = new Date();
var monthDay = date.toLocaleString('default', { month: 'long', day: 'numeric' });
h2 = Array.from(document.querySelectorAll('[id*=tsc]')).find(el => el.textContent.includes(monthDay));
}
var events = h2.parentElement.querySelectorAll('div [role="button"]');
var details = Array.from(events).map(event => event.outerText.split(`${splitOn}`)[1]);
var text = `${header}\n- `;
text += details.join('\n- ');
console.log(text);
copyText(text);
@dehru
Copy link

dehru commented Oct 26, 2021

Haha. Great little time-saver. I never knew you could do this.

I forked and added details = Array.from(new Set(details)); on line 74 to remove dups, because i get a lot of duplicate events from my team calendar / personal calendar.

@iowillhoit
Copy link
Author

Ah, good idea @dehru! Would also be pretty simple to only display Accepted meetings. You would just need to check the 3rd index on the the split event (assuming splitOn is still a comma)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment