Skip to content

Instantly share code, notes, and snippets.

@mallowlabs
Created April 11, 2009 09:25
Show Gist options
  • Save mallowlabs/93515 to your computer and use it in GitHub Desktop.
Save mallowlabs/93515 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Google Calendar daytime
// @author mallowlabs
// @version 0.0.3
// @namespace http://mallowlabs.s206.xrea.com/
// @published 2008-01-10
// @modified 2009-04-11
// @license public domain
// @description : Add daytime to Google Calendar
// @include http://calendar.google.com/*
// @include http://www.google.com/calendar*
// @include http://google.com/calendar*
// ==/UserScript==
(function(document) {
var start_work = 8;
var end_work = 18;
// avoid frame
if (window.self != window.parent) return;
var w = this.unsafeWindow || window;
// -- http://userscripts.org/scripts/show/7873
var view = null;
var countVisibleDays = function() {
if (view == null) {
for (var i in w) {
var x = w[i];
if (x && typeof x.type == "number") {
view = x;
break;
}
}
}
if (view == null) return 0;
return parseInt(view.toString().match(/extent: (¥d+)/)[1]);
};
var createGray = function(parent, left, width, classname) {
var div = document.createElement("div");
div.setAttribute("class", classname);
var style = div.style;
style.height = "2em";
style.left = left + "%";
style.width = width + "%";
style.backgroundColor = "#ddd";
style.opacity = "0.4";
style.position = "absolute";
if (parent.getElementsByClassName("_gray").length == 0) {
parent.appendChild(div);
}
return div;
}
var isBusy = false;
var onAttrModified = function() {
if (isBusy) return;
setTimeout(function(){
var days = countVisibleDays();
if (days > 7) return;
isBusy = true;
var markers = document.getElementsByClassName("tg-dualmarker");
var length = markers.length;
for (var i = 0; i < length; i++) {
if (i < start_work || end_work <= i) {
createGray(markers[i], 0, 100.0, "_gray");
} else if (days != 1) {
createGray(markers[i], 0, 100.0/7.0, "");
createGray(markers[i], 100.0 * 6.0 / 7.0, 100.0/7.0, "_gray");
}
}
isBusy = false;
}, 10);
}
document.addEventListener("DOMNodeInserted", onAttrModified, false);
})(document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment