experts exchange

By smk Last update Nov 7, 2009 — Installed 1,860 times. Daily Installs: 5, 1, 1, 3, 3, 1, 3, 1, 1, 3, 29, 15, 22, 11, 17, 24, 6, 10, 5, 4, 7, 5, 10, 12, 9, 3, 3, 2, 9, 14, 8, 6

There are 6 previous versions of this script.

// ==UserScript==
// @name           expertsExchange
// @namespace      smk
// @description    change the format of the rather stupid hiding mechanisms
// @include        http://www.experts-exchange.com/*
// ==/UserScript==

var options={
	warn_noanswers: true,
}

var answersNotFound='Warning: answers are not present on this page';

function removeNode(node){if(node) node.parentNode.removeChild(node);}

function getClass(className,partial,num){
	if(num==null) num=0;
	if(partial) return document.evaluate('//*[contains(concat("",normalize-space(@class),""),"'+className+'")]',document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(num);
	return document.evaluate('//*[@class="'+className+'"]',document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null).snapshotItem(num);
}

function remove(){
	//add actual answers
	var question=getClass("bcQuestion",true);
	var realAnswers=getAnswers();
	if(!question) return;
	var allZones=getClass("allZones").parentNode.parentNode.parentNode.parentNode.parentNode;
	allZones.parentNode.insertBefore(realAnswers,allZones);
	//remove fake answers
	var fakeAnswers=document.evaluate('//div[contains(concat("",normalize-space(@class),""),"blurredAnswer")]',document,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null);
	for(var i=0;i<fakeAnswers.snapshotLength;i++){fakeAnswers.snapshotItem(i).style.display='none';}
	//move relatedSolutions box
	var relatedSolutions=getClass("RelatedSolutions",true);
	if(relatedSolutions){
		relatedSolutions=relatedSolutions.parentNode;
		question.appendChild(relatedSolutions);
	}
	//remove other stuff
	removeNode(getClass("startFreeTrial",true));
	removeNode(getClass("squareSignUp"));
	removeNode(getClass("notFreePAQ",true));
}

window.addEventListener('load',remove,false);

function getAnswers(){
	var realAnswers;
	try{
		realAnswers=getClass("answers",false,1).parentNode.parentNode.parentNode.parentNode.parentNode;
	}catch(e){
		realAnswers=document.getElementById('bottomSolutionDiv');
	}
	if(!realAnswers){
		alert(answersNotFound);
		return;
	}
	return realAnswers;
}