Google Notebook Floating Nav

By ruiz Last update Mar 4, 2007 — Installed 631 times. Daily Installs: 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0
// ==UserScript==
// @name           Google Notebook Floating Nav
// @author         Martin Ruiz
// @namespace      Martin Ruiz
// @description    Google Notebook Floating Nav. For the selected notebook, you'll always see the list on headings on the left-nav -- no matter where you scroll to.  The notebook list is managed in a drop-down list.
// @include        http://www.google.com/notebook/*
// ==/UserScript==

/* 
   Author: Martin Ruiz

   Motivation:
     + I use Google notebook a lot.  My biggest peeve is that I have to scroll back to the top
       to switch to another header.

   Credits:
     + float-nav code(JSFX_FloatTopLeft) from web

   Features:

     + Re-arranges left Nav
     + Select notebook and heading float as you scroll.
     + Other notebook headings are removed and stuffed in a drop-down list.
     + Switch notebooks using the drop-down list labeled 'Choose Notebook'.

   Requirements:
     + Nothing specific

   Testing:
     + Works with Firefox 2.0 for PC with Greasemonkey
     + Please try it on your platform and let me know of any problems.

   Version History:
 
       1.0 - 03.04.2007 - Initial Release
*/

function Fire_Event(obj)
{
	var newEvt = document.createEvent("MouseEvents");
	newEvt.initEvent("click", true, true)
	document.getElementById(obj.target.value+"_1").dispatchEvent(newEvt);
//	newEvt.cancelBubble = true;
}

function Create_Notebook_List(div)
{
	var html = '<br><div id="notebook_list"><select>';
	var txt;
	var txtVal;
	var d = div.nextSibling; //skip blank

	d = d.nextSibling;

	html = html + '<option selected="">Choose Notebook...</option>';

	while (d)
	{
		txt=d.getAttribute("id");
		txtVal = d.firstChild.firstChild.firstChild.childNodes[1].firstChild.firstChild.textContent;
		html = html + '<option class="DropDownOption" value="' + txt + '"> ' + txtVal + '</option>';
		d.style.display="none";
		d=d.nextSibling;
	}
	
	html = html + '</select></div>';

	var sdiv = document.createElement("DIV");
	sdiv.innerHTML=html;

	sdiv.lastChild.firstChild.addEventListener("change",Fire_Event,false);

	return sdiv;
}

function JSFX_FloatTopLeft()
{
	var startX = 10, startY = 200;
	var px = document.layers ? "" : "px";
	var overview = document.getElementById("overview_1");

	ftlObj = overview.firstChild;

	overview.childNodes[1].style.display = "none";
	overview.parentNode.insertBefore(Create_Notebook_List(ftlObj),overview);

	if (ftlObj) {
//		ftlObj.setAttribute("STYLE","position:absolute;left:10;top:200");
		ftlObj.setAttribute("STYLE","position:absolute;top:200");
		ftlObj.sP =function(x,y){this.style.left=x+px;this.style.top=y+px;};
//		ftlObj.x  = startX;
		ftlObj.y  = startY;



	window.stayTopLeft=function()
	{
		var newObj=document.getElementById("overview_1").firstChild;
		if (newObj!=ftlObj) {
			newObj.x=ftlObj.x;
			newObj.y=ftlObj.y;
			ftlObj=newObj;
			ftlObj.setAttribute("STYLE","position:absolute;left:10;top:200");
			ftlObj.sP =function(x,y){this.style.left=x+px;this.style.top=y+px;};

			ftlObj.parentNode.childNodes[1].style.display = "none";
			ftlObj.parentNode.parentNode.insertBefore(Create_Notebook_List(ftlObj),ftlObj.parentNode);
		}

		var pY = document.body.scrollTop;
		var dY = (pY > startY) ? pY : startY;
		ftlObj.y += (dY - ftlObj.y)/8;
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout(stayTopLeft, 20);
	}

	stayTopLeft();
	}

}

//window.addEventListener("load", JSFX_FloatTopLeft, false);
window.setTimeout(JSFX_FloatTopLeft, 5000);