Colorize GCal:monthly timed events

Colored background for Google Calendar timed events in month view

  1. // ==UserScript==
  2. // @name Colorize GCal:monthly timed events
  3. // @description Colored background for Google Calendar timed events in month view
  4. // @include https://calendar.google.com/*
  5. // @version 1.1
  6. // @author wOxxOm
  7. // @namespace wOxxOm.scripts
  8. // @license MIT License
  9. // @run-at document-start
  10. // @require https://greatest.deepsurf.us/scripts/12228/code/setMutationHandler.js
  11. // @require https://cdnjs.cloudflare.com/ajax/libs/tinycolor/1.4.1/tinycolor.min.js
  12. // ==/UserScript==
  13.  
  14. setMutationHandler(document,
  15. 'span.goog-inline-block[style*="background-color:"],' +
  16. '.st-c-pos .rb-n[style*="background-color:"],' +
  17. '.st-c-pos .te[style*="color:"]',
  18. function(nodes) {
  19. nodes.forEach(function(n) {
  20. var bg = n.style.backgroundColor;
  21. var fg = n.style.color;
  22. n.style.color = n.style.backgroundColor = '';
  23.  
  24. var appointment = n.className.indexOf('goog-inline-block')>=0 ? n.parentNode : n;
  25. var color = appointment.style.backgroundColor = bg || fg;
  26. var isDark = tinycolor(color).getBrightness() < 150; // brightness range is 0-255
  27. appointment.style.color = isDark ? 'white' : 'black';
  28.  
  29. if (isDark && n.classList.contains('rb-n')) {
  30. n.style.fontWeight = 'bold';
  31. var v = n.querySelector('.rem-ic'); if (v) v.style.filter = 'invert(1)';
  32. v = n.querySelector('.rb-ni'); if (v) v.style.color = 'white';
  33. }
  34.  
  35. if (n.style.border)
  36. n.style.border = '';
  37. });
  38. return true;
  39. });