Google calendar event hider

Hide calendar events specified

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Google calendar event hider
// @namespace    https://zachsaucier.com/
// @version      0.1
// @description  Hide calendar events specified
// @author       Zach Saucier
// @match        https://calendar.google.com/calendar/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    
    var eventList = [
        "Event name"
    ];

    // The actual functionality to remove the events
    function hideEventsInList() {
        var spans = document.querySelectorAll(".cpchip span, .chip-caption span");
        
        for(var i = 0; i < spans.length; i++) {
            var span = spans[i];
            for(var j = 0; j < eventList.length; j++) {
                 if(span.innerText.indexOf(eventList[j]) > -1) {
                     var parent = span.parentNode.parentNode.parentNode.parentNode;
                     parent.parentNode.removeChild(parent);
                 }
            }
        }
    }
    hideEventsInList();

    var observeDOM = (function() {
        var MutationObserver = window.MutationObserver || window.WebKitMutationObserver,
            eventListenerSupported = window.addEventListener;

        return function(obj, callback) {
            if(MutationObserver) {
                // Define a new observer
                var obs = new MutationObserver(function(mutations, observer){
                    if(mutations[0].addedNodes.length || mutations[0].removedNodes.length )
                        callback();
                });
                // Have the observer observe foo for changes in children
                obs.observe(obj, {childList: true, subtree: true});
            }
            else if(eventListenerSupported ) {
                obj.addEventListener('DOMNodeInserted', callback, false);
                obj.addEventListener('DOMNodeRemoved', callback, false);
            }
        };
    })();

    // Observe a specific DOM element:
    observeDOM(document.body.querySelector("#mainbody"), function() { 
        hideEventsInList();
    });
})();