Event Merge for Google Calendar™ (by @imightbeAmy)

Script that visually merges the same event on multiple Google Calendars into one event.

当前为 2018-02-17 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Event Merge for Google Calendar™ (by @imightbeAmy)
// @namespace   gcal-multical-event-merge
// @include     https://www.google.com/calendar/*
// @include     http://www.google.com/calendar/*
// @include     https://calendar.google.com/*
// @include     http://calendar.google.com/*
// @require     https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @version     1
// @grant       none
// @description Script that visually merges the same event on multiple Google Calendars into one event.
// ==/UserScript==

'use strict';

const merge = () => {
  const stripesGradient = (colors) => {
	  let gradient = "repeating-linear-gradient( 45deg,";
	  let pos = 0;

	  colors.forEach(color => {
	    gradient += color + " " + pos + "px,";
	    pos += 10;
	    gradient += color + " " + pos + "px,";
	  });
	  gradient = gradient.slice(0, -1);
	  gradient += ")";
	  return gradient;
	};

  const grids = document.querySelectorAll("[role=\"main\"] [role=\"grid\"] > [role=\"presentation\"]");
  const mainCalender = Array.from(grids).find(grid => typeof grid.dataset.isColumnViewContext === "undefined");

  const eventSets = {};
  const days = mainCalender.querySelectorAll("[role=\"gridcell\"]");
  days.forEach((day, index) => {
    const events = Array.from(day.querySelectorAll("[role=\"button\"]"));
    events.forEach(event => {
      let eventKey = event.querySelector("div:nth-child(2)").textContent.replace(/\\s+/g,"");
      eventKey = index + eventKey;
      eventSets[eventKey] = eventSets[eventKey] || [];
      eventSets[eventKey].push(event);
    });
  });

  Object.values(eventSets)
    .filter(events => events.length > 1)
    .forEach(events => {
      const colors = events.map(event => event.style.backgroundColor || event.style.borderColor);
      const gradient = stripesGradient(colors);

      const eventToKeep = events.shift();
      eventToKeep.style.backgroundImage = gradient;

      let width = Number(events[0].style.width.replace(/%/g, ""));
      if (!isNaN(width)) {
        width = width * (events.length + 1);
        width = Math.min(width, 100);
        eventToKeep.style.width = width + "%";
      }

      events.forEach(event => {
        event.style.visibility = "hidden";
      });
    });
}

chrome.runtime.sendMessage({}, function(response) {
  if (response.enabled) {
    $(document).ready(merge);
  }
});