User:Dantman/LogoHunter.js

/* */

//////////////////////// // Logo Hunter Script // ////////////////////////

var oldLogo; var plogo; var logoElm; var floatLink; var logoFloats = false; var followLink; var offX = 0; var offY = 0; var logoFollows = false; var lowerTimer; var timerTimeout; addOnloadHook(setupLogoHunter); function setupLogoHunter { var boxes = getElementsByClassName( document, '*', 'clickhere' ); for( var b = 0; b < boxes.length; b++ ) { var a = boxes[b].getElementsByTagName('a')[0]; var subdomain = a.title.replace(/^(w:)?c:/i, ''); var logo = 'http://' + subdomain + '.wikia.com/images/b/bc/Wiki.png'; boxes[b].setAttribute('onmouseover', 'javascript: huntLogo(\'' + logo + '\');'); boxes[b].setAttribute('onmouseout', 'javascript: killLogo;'); }	pLogo = document.getElementById( 'p-logo' ); logoElm = pLogo.getElementsByTagName('a')[0]; oldLogo = logoElm.style.backgroundImage; floatLink = document.createElement('a'); floatLink.id = 'logoFloat'; floatLink.style.position = 'absolute'; floatLink.style.top = '0px'; floatLink.style.right = '0px'; floatLink.style.color = 'grey'; floatLink.style.zIndex = '5'; floatLink.style.textAlign = 'right'; floatLink.style.height = '15px'; floatLink.style.width = '50%'; floatLink.setAttribute('href', 'javascript:void(0);'); floatLink.setAttribute('onclick', 'javascript: toggleLogoFloat;'); floatLink.appendChild( document.createTextNode( 'float' ) ); pLogo.appendChild( floatLink ); followLink = document.createElement('a'); followLink.id = 'logoFollow'; followLink.style.position = 'absolute'; followLink.style.top = '0px'; followLink.style.left = '0px'; followLink.style.color = 'grey'; followLink.style.zIndex = '5'; followLink.style.textAlign = 'left'; followLink.style.height = '15px'; followLink.style.width = '50%'; followLink.style.display = 'none'; followLink.setAttribute('href', 'javascript:void(0);'); followLink.setAttribute('onclick', 'javascript: logoFollowOn( event );'); followLink.appendChild( document.createTextNode( 'follow' ) ); pLogo.appendChild( followLink ); lowerTimer = document.createElement('span'); lowerTimer.id = 'lowerTimer'; lowerTimer.style.position = 'absolute'; lowerTimer.style.bottom = '0px'; lowerTimer.style.right = '0px'; lowerTimer.style.color = 'grey'; lowerTimer.style.border = '1px dotted lightgrey'; lowerTimer.style.zIndex = '5'; lowerTimer.style.textAlign = 'right'; lowerTimer.style.height = '15px'; lowerTimer.style.width = '100%'; lowerTimer.style.display = 'none'; lowerTimer.appendChild( document.createTextNode( '0' ) ); pLogo.appendChild( lowerTimer ); document.body.setAttribute('onmousemove', 'javascript: logoOnMouseMove( event );'); }

function huntLogo( url ) { logoElm.style.backgroundImage = 'url(' + url + ')'; }

function killLogo { logoElm.style.backgroundImage = oldLogo; }

function toggleLogoFloat { logoFollows = false; logoFloats = !logoFloats; if( logoFloats ) { pLogo.style.position = 'float'; floatLink.firstChild.data = 'return'; followLink.style.display = 'inline'; } else { pLogo.style.position = 'absolute'; pLogo.style.top = '0px'; pLogo.style.left = '0px'; pLogo.style.zIndex = 100; floatLink.firstChild.data = 'float'; followLink.style.display = 'none'; lowerTimer.style.display = 'none'; } }

function logoFollowOn( e ) { logoFollows = true; followLink.firstChild.data = 'noFollow'; followLink.setAttribute('onclick', 'javascript: logoFollowOff;'); var x = 0; var y = 0; if( e == undefined ) { x = event.clientX; y = event.clientY; } else { x = e.clientX; y = e.clientY; }	offX = parseInt( pLogo.style.left.replace(/[^0-9]/g,'') ) - x; offX = offX ? offX : 0; offY = parseInt( pLogo.style.top.replace(/[^0-9]/g,'') ) - y; offY = offY ? offY : 0; lowerTimer.style.display = 'inline'; lowerTimer.firstChild.data = 30; timerTimeout = setTimeout( 'logoOnSec;', 1000 ); }

function logoFollowOff { logoFollows = false; followLink.firstChild.data = 'follow'; followLink.setAttribute('onclick', 'javascript: logoFollowOn( event );'); lowerTimer.style.display = 'none'; clearTimeout( timerTimeout ); }

function logoOnMouseMove( e ) { if( logoFollows ) { var x = 0; var y = 0; if( e == undefined ) { x = event.clientX; y = event.clientY; } else { x = e.clientX; y = e.clientY; }		pLogo.style.left = ( x + offX ) + 'px'; pLogo.style.top = ( y + offY ) + 'px'; } } function logoOnSec { var t = parseInt( lowerTimer.firstChild.data ) - 1; lowerTimer.firstChild.data = t;	if( t <= 0 ) logoFollowOff; else timerTimeout = setTimeout( 'logoOnSec;', 1000 ); }

/* */