Forked from iowillhoit/get-google-calendar-events.js
Last active
October 26, 2021 20:32
-
-
Save dehru/cf43217e820d3d2975f99fec03e1c818 to your computer and use it in GitHub Desktop.
This bookmarklet will create our team slack :in: message from your google calender day view in the browser's console output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.querySelectorAll('[aria-label="View switcher menu"]')[0].innerText; | |
var supportedViews = ["Day", "4 days", "Week"]; | |
if(!supportedViews.includes(view)) { | |
console.log(`The "${view}" view is not supported. Use one of the following: "${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]); | |
details = Array.from(new Set(details)); | |
var text = `${header}\n- `; | |
text += details.join('\n- '); | |
console.log(text); | |
copyText(text); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment