Created
March 17, 2010 11:45
-
-
Save fwenzel/335149 to your computer and use it in GitHub Desktop.
A copy of http://userscripts.org/scripts/show/37941 with some tweaks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name expertsExchange | |
// @namespace smk | |
// @description kill the stupid hiding mechanisms | |
// @include http://*.experts-exchange.com/* | |
// ==/UserScript== | |
var options={ | |
warn_noanswers: true, | |
googleBotUserAgent: 'Googlebot/2.1 (+http://www.google.com/bot.html)', | |
useGoogleReferrer: false, | |
loadingOverlay: true, | |
google404: 'http://www.google.com/!', | |
} | |
var msg_answersNotFound='Warning: answers are not present on this page'; | |
var msg_googleReferrer='<center><pre>Please wait, attempting to retrieve answers using http://www.google.com as referrer</pre></center>'; | |
function childToCenter(node){ | |
node.innerHTML='<table style="width:100%; height:100%;"><tr align="center" valign="middle"><td>'+node.innerHTML+ | |
'</td></tr></table>'; | |
} | |
function removeNode(node){if(node) node.parentNode.removeChild(node);} | |
function getClass(className,partial,num){ | |
var ret; | |
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 getAnswers(){ | |
var realAnswers; | |
try{ | |
realAnswers=getClass("answers",false,1).parentNode.parentNode.parentNode.parentNode.parentNode; | |
}catch(e){ | |
realAnswers=document.getElementById('bottomSolutionDiv'); | |
} | |
if(!realAnswers){ | |
if(GM_getValue('googleBot')==true){ | |
alert(msg_answersNotFound); | |
if(options.loadingOverlay) removeNode(document.getElementById('eeOverlay')); | |
}else{ | |
if(options.loadingOverlay){ | |
var overlay=document.createElement('div'); | |
overlay.id='eeOverlay'; | |
overlay.setAttribute('style', | |
'z-index:10000;'+ | |
'opacity:0.5;'+ | |
'background-color:#000000;'+ | |
'position:fixed; top:0px; left:0px; width:100%; height:100%; color:#FFFFFF; text-align:center; vertical-align:middle;'); | |
var overlayText=document.createElement('div'); | |
overlayText.setAttribute('style','font-size:1.5em; width:100%; height:100%;'); | |
overlayText.textContent='Loading...'; | |
childToCenter(overlayText); | |
overlay.appendChild(overlayText); | |
document.body.appendChild(overlay); | |
} | |
//get answers via Googlebot user-agent | |
GM_xmlhttpRequest({ | |
method: 'GET', | |
url: window.location.href, | |
headers: { | |
'User-Agent': options.googleBotUserAgent, | |
'Accept': '*/*', | |
}, | |
onload: function(e){ | |
if(options.loadingOverlay) removeNode(overlay); | |
GM_setValue('googleBot',true); | |
document.evaluate('//html',document,null,9,null).singleNodeValue.innerHTML=e.responseText; | |
if(cleanupEE()==false){ | |
if(options.useGoogleReferrer){ | |
//get answers by using google.com as referrer | |
//this is not allowed by GM_xmlhttpRequest, so load www.google.com | |
url=GM_getValue('url',null); | |
GM_deleteValue('url'); | |
if(url=='!' && options.warn_noanswers){ | |
alert(msg_answersNotFound); | |
}else{ | |
document.body.innerHTML=msg_googleReferrer; | |
GM_setValue('url',window.location.href); | |
window.location.href=options.google404; | |
} | |
} | |
} | |
} | |
}); | |
} | |
} | |
GM_setValue('googleBot',false); | |
return realAnswers; | |
} | |
function cleanupEE(){ | |
//add actual answers | |
var question=getClass("bcQuestion",true); | |
if(!question) return; | |
remove(); | |
var realAnswers=getAnswers(); | |
if(!realAnswers) return false; | |
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); | |
} | |
return true; | |
} | |
function remove(){ | |
//remove useless things | |
removeNode(getClass("startFreeTrial",true)); | |
removeNode(getClass("squareSignUp")); | |
removeNode(getClass("notFreePAQ",true)); | |
removeNode(getClass("freePAQ",true)); | |
removeNode(getClass("freeInProg",true)); | |
} | |
function redirectLinks(){ | |
var i,currLink,currHref; | |
var eeLinks=document.evaluate('//a[contains(@href,"/www.experts-exchange.com/") and contains(@href,"/Q_")]',document,null,7,null); | |
for(i=0;i<eeLinks.snapshotLength;i++){ | |
currLink=eeLinks.snapshotItem(i); | |
currHref=currLink.href; | |
currLink.href=options.google404+'#'+currLink; | |
currLink.addEventListener('mousedown',function(e){ | |
e.preventDefault(); | |
e.stopPropagation(); | |
GM_setValue('url',currHref); | |
},false); | |
} | |
} | |
function main(){ | |
if(options.useGoogleReferrer && window.location.href.indexOf(options.google404)==0 && document.body){ | |
var url=GM_getValue('url',null); | |
if(url!=null){ | |
document.body.innerHTML=msg_googleReferrer; | |
GM_setValue('url','!'); | |
window.location.href=url; | |
} | |
}else{ | |
if(options.useGoogleReferrer && window.location.href.indexOf('http://www.google.com')!=0) redirectLinks(); | |
cleanupEE(); | |
} | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment