Large

Nexopia SideBar toggler v3.1

By keesc Last update Apr 6, 2010 — Installed 173 times.

There are 13 previous versions of this script.

// ==UserScript==
// @name           Nexopia SideBar toggler
// @version        3.1
// @uso:version    3
// @namespace      http://www.nexopia.com/users/kees/
// @description    Hide/unhide the side bar on Nexopia
// @author         Kees Couprie
// @include        http://www.nexopia.com/*
// @include        https://www.nexopia.com/*
// ==/UserScript== 

// Emulate GM_setValue and GM_getValue in browsers that have their own userscript support (Chrome and Opera)

if(typeof GM_setValue!='function') {
      function GM_setValue( cookieName, cookieValue, lifeTime ) {
      	if( !cookieName ) { return; }
      	if( lifeTime == "delete" ) { lifeTime = -10; } else { lifeTime = 31536000; }
      	document.cookie = escape( cookieName ) + "=" + escape( cookieValue ) +
      		";expires=" + ( new Date( ( new Date() ).getTime() + ( 1000 * lifeTime ) ) ).toGMTString() + ";path=/";
      }
      
      function GM_getValue( cookieName, oDefault ) {
      	var cookieJar = document.cookie.split( "; " );
      	for( var x = 0; x < cookieJar.length; x++ ) {
      		var oneCookie = cookieJar[x].split( "=" );
      		if( oneCookie[0] == escape( cookieName ) ) {
      			try {
      				var footm = unescape( oneCookie[1] );
      			} catch(e) { return oDefault; }
      			return footm;
      		}
      	}
      	return oDefault;
      }
	
}



// MAIN program //
// Find the sidebar
NexopiaSidebar = document.getElementById('layout_sidebar');
if (NexopiaSidebar) {
    PublicMenu = document.getElementById('menu_public');
    if(PublicMenu) {
    	  Main_Menu_Extras=PublicMenu.childNodes[0];
        //create and add the Sidebar link
    		NewElement = document.createTextNode(" | ");
        Main_Menu_Extras.appendChild(NewElement);
    		NewElement = document.createElement('a');
    		NewElement.innerHTML = 'Sidebar';
    		NewElement.setAttribute('href', 'Javascript:;');
    		NewElement.addEventListener("click", toggleSidebar, true);
    		NewElement.className="users_online"; 
        Main_Menu_Extras.appendChild(NewElement);
    }
    Content = NexopiaSidebar.parentNode.getElementsByClassName("layout_content")[0];
    ContentMarginRight = getComputedStyle(Content, '').marginRight;
    ContentNewMarginRight = getComputedStyle(Content, '').marginLeft;
    if (GM_getValue("showSidebar", "true") == "false") {
        GM_setValue("showSidebar", "true");
        toggleSidebar();
    }
}

// Toggle the entire sidebar
function toggleSidebar() {
    if (GM_getValue("showSidebar", "true") == "false") {
        GM_setValue("showSidebar", "true");
        NexopiaSidebar.style.display = "";
    } else {
        GM_setValue("showSidebar", "false");
        NexopiaSidebar.style.display = "none";
    }
    // Fix the width of the main part of the screen to match the new status.
		var tempVal = ContentMarginRight;
		ContentMarginRight = ContentNewMarginRight;
		ContentNewMarginRight = tempVal;
    Content.style.marginRight = ContentMarginRight;
    return false;
}