Skip to content

Instantly share code, notes, and snippets.

@ndbeals
Last active May 17, 2023 14:59
Show Gist options
  • Save ndbeals/f26e6762aca9ff4b5a63bd6a02715054 to your computer and use it in GitHub Desktop.
Save ndbeals/f26e6762aca9ff4b5a63bd6a02715054 to your computer and use it in GitHub Desktop.
Userscript - Horizontal Scroll Google Calendar
// ==UserScript==
// @name Shift Scroll google calendar
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Enables holding shift + scrolling to move to previous/next day/week/month.
// @author Nathan Beals
// @updateURL https://gitlab.com/-/snippets/2543244/raw/main/calendarscroll.user.js
// @downloadURL https://gitlab.com/-/snippets/2543244/raw/main/calendarscroll.user.js
// @match https://calendar.google.com/calendar/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function() {
'use strict';
function SingleContains(selector, text) {
var elements = Array.from(document.querySelectorAll(selector));
return elements.find(el => RegExp(text).test(el.textContent))
}
function NextWeek() {
let next = SingleContains("button > i", "navigate_next")
if (next) {
next.click()
}
}
function PrevWeek() {
let prev = SingleContains("button > i", "navigate_before")
if (prev) {
prev.click()
}
}
const validPathRegex = RegExp("/day|/week|/agenda|/customday")
const basePathRegex = RegExp("^/calendar/u/0/r/?$")
document.addEventListener('wheel',(event) => {
if (event.shiftKey && (validPathRegex.test(window.location.pathname) || basePathRegex.test(window.location.pathname) )) {
if (event.deltaX > 0) { // scroll down
NextWeek()
}
else if (event.deltaX < 0) { // scroll up
PrevWeek()
}
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment