// ==UserScript== // @name Google Calendar daytime // @author mallowlabs // @version 0.0.3 // @namespace http://mallowlabs.s206.xrea.com/ // @published 2008-01-10 // @modified 2008-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; 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; } document.addEventListener("DOMNodeInserted", onAttrModified, false); })(document);