Skip to content

Instantly share code, notes, and snippets.

@nikjft
Last active November 3, 2022 20:42
Show Gist options
  • Save nikjft/cc11f0e22c5dfc54aa8336ae0f8457a4 to your computer and use it in GitHub Desktop.
Save nikjft/cc11f0e22c5dfc54aa8336ae0f8457a4 to your computer and use it in GitHub Desktop.
Toggle Google Calendar event visibility by color
/*
This toggles GA event visibility based on the color of the event.
It should be injected into the JS of the site using an extension
like TamperMonkey or User JS and CSS Chrome plugin
https://chrome.google.com/webstore/detail/user-javascript-and-css/nbhcbdghjpllgmfilhnhkllmkecfmpld?hl=en
Edit the array of colors where commented to determine which events show/hide.
You can find the color using the web inspector.
*/
document.addEventListener("DOMContentLoaded", function() {
setTimeout(setUpToggles,5000);
});
function setUpToggles() {
function filterByColor(c,h) {
var events = document.querySelectorAll('div[data-eventchip]');
var i = events.length;
while(i-->0) {
if(c.includes(getComputedStyle(events[i]).backgroundColor)) {
if(h == 1) {
events[i].style.display = "block";
} else {
events[i].style.display = "none";
}
}
}
}
var b = document.createElement('button');
b.innerText = 'Hide Blocks';
b.dataset.toggleAction = 0;
b.id = 'toggleBlocks';
b.style = "border-style: solid; margin-left: 22px; width: 200px; color:rgb(26,115,232); height: 26px; border-color:rgb(218,220,224); border-width: 1px; border-radius: 4px; font-family: 'Google Sans',Roboto,Arial,sans-serif; font-size: .875rem; letter-spacing: .0107142857em; font-weight: 500; text-transform: none;background-color:#fff;";
var c = document.querySelector("#dws12b");
c.insertBefore(b,c.firstChild);
b.addEventListener('click', function() {
console.log(e);
var e = document.getElementById('toggleBlocks');
var toggleAction = e.dataset.toggleAction;
//EDIT COLORS HERE FOR WHAT COLORS TOGGLE
filterByColor(
['rgb(97, 97, 97)','rgb(213, 0, 0)','rgb(242, 179, 179)','rgb(208, 208, 208)',
'rgb(3, 155, 229)','rgb(179, 225, 247)']
,toggleAction);
if(toggleAction == 0) {
e.innerText = 'Show Blocks';
e.dataset.toggleAction = 1;
} else {
e.innerText = 'Hide Blocks';
e.dataset.toggleAction = 0;
}
} );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment