jerrywhatsoeveryahoo.com / Google Calendar Scroll Disabler for Chrome

// ==UserScript==
// @name        Google Calendar Scroll Disabler for Chrome
// @version     1.0
// @grant       none
// @author     Jerry
// @license GPL-3.0-or-later; http://www.gnu.org/licenses/gpl-3.0.txt
// @include    https://calendar.google.com/*
// ==/UserScript==

// modified from: https://github.com/alter-ego/google-calendar-scroll-disabler/blob/master/code/content.js
// https://github.com/apphancer/firefox-google-calendar-scroll-disabler/blob/master/release/content-script.js
// https://openuserjs.org/scripts/nmingotti/Google_Calendar_Month_Scroll_Disable/source
// only works for Chrome not firefox (?)

// https://github.com/alter-ego/google-calendar-scroll-disabler/pull/15
// https://github.com/alter-ego/google-calendar-scroll-disabler/blob/a1eec89ba47bea70d4fe7923c04b6f45d388ed1d/code/content.js
var calendar_main_selector = 'div[role="main"]';
var body = document.querySelector('body');

var mousewheelHander = function (e) {
    if (e.target.id == 'el')
        return;
    e.preventDefault();
    e.stopPropagation();
}

var disable_scroll = function () {
    for (var live_selector of document.querySelectorAll(calendar_main_selector)) {
        // Remove the event handler before adding a new one to make sure
        // we don't have multiple event handlers registered.
        live_selector.removeEventListener('mousewheel', mousewheelHander, true);
        live_selector.addEventListener('mousewheel', mousewheelHander, true);
    }
};

var calendar_observer = new MutationObserver(function (mutations) {
    // A change on the webpage may replace the "main" div, so we need to
    // re-register the event handler.
    disable_scroll();
});
calendar_observer.observe(body, {attributes: true});

// Disable scrolling once at startup just in case no mutations occur at page load.
disable_scroll();



// the following does not work after changing months
// var calendar_grid_selector = 'div[role="grid"]';
// var body = document.querySelector('body');
// var calendar_grid = document.querySelectorAll(calendar_grid_selector);

// var disable_scroll = function () {
//     for (var live_selector of document.querySelectorAll(calendar_grid_selector)) {
//         live_selector.addEventListener('mousewheel', function (e) {
//             if (e.target.id == 'el') return;
//             e.preventDefault();
//             e.stopPropagation();
//         });
//     }
// };

// var mutation_breaks_scroll_blocker = function (mutation) {
//     if (mutation.attributeName && mutation.attributeName == 'data-viewfamily') {
//         if (body.getAttribute('data-viewfamily') == 'EVENT')
//             return true;
//     }
// };

// var calendar_observer = new MutationObserver(function (mutations) {
//     mutations.forEach(function (mutation) {
//         if (mutation_breaks_scroll_blocker(mutation)) {
//             disable_scroll();
//         }
//     });
// });

// var observe_if_calendar_available = function () {
//     if (!calendar_grid) {
//         window.setTimeout(observe_if_calendar_available, 500);
//         return;
//     }
//     calendar_observer.observe(body, {attributes: true});
// };

// disable_scroll();
// observe_if_calendar_available();