Last active
December 24, 2016 01:25
-
-
Save tomviner/5747208 to your computer and use it in GitHub Desktop.
Google Calendar: Show more than 4 weeks at a time.
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
| function trigger(ename, elem){ | |
| if (!elem) { | |
| console.log("Cannot " + ename + " element missing"); | |
| } | |
| console.log("Trigger " + ename + " on " + elem); | |
| console.log(elem); | |
| var evt = document.createEvent("MouseEvents"); | |
| evt.initMouseEvent(ename, true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); | |
| elem.dispatchEvent(evt) | |
| } | |
| var start = function(){ | |
| return document.getElementsByClassName('dp-today-selected')[0] || | |
| document.getElementsByClassName('dp-onmonth')[new Date().getDate()]; | |
| }; | |
| var end = function(n){return document.getElementsByClassName('dp-cell')[n || 52]}; | |
| var custom_view = function(){return document.getElementById('topRightNavigation').children[0].children[4];}; | |
| var prev_month = function(){return document.getElementsByClassName('navBack')[0];}; | |
| var today = function(){return (document.getElementById('todayButton:1') || document.getElementById('todayButton:2')).children[0];}; | |
| var next_month = function(){return document.getElementById('dp_0_next');}; | |
| var set_range = function(months, weeks_to_remove){ | |
| days = (7 * (7 - weeks_to_remove)) + 3; | |
| // go back a couple of months | |
| trigger('click', prev_month()); | |
| trigger('click', prev_month()); | |
| // move to custom view | |
| trigger('mouseup', custom_view()); | |
| // slide range to start today | |
| trigger('click', today()); | |
| // do a double manoeuvre: click next month during a click drag over the mini calendar. | |
| // this is how we reach more than one month | |
| trigger('mousedown', start()); | |
| for (i = 0; i < months; i++) { | |
| trigger('mousedown', next_month()); | |
| } | |
| trigger('mousemove', end(days)); | |
| trigger('mouseup', end(days)); | |
| trigger('click', today()); | |
| } | |
| set_range(2, 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment