Skip to content

Instantly share code, notes, and snippets.

@BruceWind
Last active September 6, 2022 03:03
Show Gist options
  • Save BruceWind/94b2d0f1ad84c8aef50308af9ec82e11 to your computer and use it in GitHub Desktop.
Save BruceWind/94b2d0f1ad84c8aef50308af9ec82e11 to your computer and use it in GitHub Desktop.
A JavaScript to get events in this month from Google calendar.

Background

I use Google calendar for managing my schedule. But there is no approach to getting all events in text format. So I wrote this for obtaining events from Google Calendar.

How to use

  1. open Google Calendar within chrome.
  2. press F12 to open dev tool.
  3. click console tab.
  4. copy and paste this code below.
var list = document.querySelectorAll('div[role="gridcell"]');

const BEGIN_NO_EVS_EN = 'No events';
const BEGIN_NO_EVS_ZH = '没有活动';
console.log(list.length);
list.forEach(function(item, index) {

    if (!item.innerText.startsWith(BEGIN_NO_EVS_EN) && !item.innerText.startsWith(BEGIN_NO_EVS_ZH)) {
        let arr =  item.innerText.split('\n');
        if(arr.length>=3){
            arr.forEach(function(itemOfArr, indexOfArr) {
                let eventInfo = itemOfArr.split(', ')
                if(indexOfArr>=2 && eventInfo.length>2){
                    console.log(eventInfo[4] + '  ' +eventInfo[1]);
                }
            });
        }
    
    }
});

And then all events will show on chrome.

In addition

I must tell you that this script only supports English and Chinese set in your Google Calendar. Searching HTML doms is the way I use it. So this script may not work well in the future.

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