Post by Alysa Halliwell on Dec 18, 2008 0:09:52 GMT -5
This is an awesome code that allows those with multiple accounts to access them easily without multiple browsers and/or loging in and out.
support.proboards.com/index.cgi?board=codedatabase&action=display&thread=256692
full info can be seen at the link above
the code goes in global footers
support.proboards.com/index.cgi?board=codedatabase&action=display&thread=256692
full info can be seen at the link above
the code goes in global footers
<script type="text/javascript">
<!--
/* Post as Alias - Eton Bones */
function saveLogin(event){
var minutes=document.getElementsByName('minutes');
var now=new Date();
try{
minutes=parseInt(minutes[0].options[minutes[0].options.selectedIndex].value);
minutes=(minutes==-1)?35788933-now.getTime()/1000/60:minutes;
var expires=minutes*1000*60+now.getTime();
if(Boolean(document.getElementById('saveLogin').checked)==true||(user.value.length && user.value in logins))
document.cookie="litmp="+expires+";"
else
document.cookie="litemp="+expires+";"
}catch(err){
alert(err);
}finally{
return true;
}
}
function setAlias(){
document.getElementById('saveLogin').checked= (user.value.length && user.value in logins)?true:false;
}
function LoginInfo(){
this.li_past=new Date(document.lastModified).toGMTString()+";";
this.li_noAlias={count:0};
this.clearAllUsers=function(){
this.li_count=0;
document.cookie="liuser=;expires="+this.li_past;
document.cookie="litime=;expires="+this.li_past;
document.cookie="lipass=;expires="+this.li_past;
document.cookie="lidn=;expires="+this.li_past;
}
this.save=function(){
if(this.li_userCount || this.li_noAlias.count){
var users,expires,passwords,dnames;
users=expires=passwords=dnames="";
var cookieExpire=0; var session=(document.cookie.match(/\blisession=1/))?true:false
for(var k in this){
if((k.substr(0,3)!="li_" || k.match(/li_noAlias/)) && typeof(this[k])!="function"){
var na=k.match(/li_noAlias/)
if(na){
for(var j in this.li_noAlias){
if(j!="count" && !(j in this)){
users+="\n\x07"+j;
expires+="\n"+this.li_noAlias[j].expire;
if(parseInt(this.li_noAlias[j].expire)>cookieExpire)cookieExpire= parseInt(this.li_noAlias[j].expire);
passwords+="\n"+this.li_noAlias[j].password;
dnames+="\n"+this.li_noAlias[j].displayname;
}
}
}else{
users+="\n"+k;
expires+="\n"+this[k].expire;
if(parseInt(this[k].expire)>cookieExpire)cookieExpire= parseInt(this[k].expire);
passwords+="\n"+this[k].password;
dnames+="\n"+this[k].displayname;
}
}
}
cookieExpiry=new Date();cookieExpiry.setTime(cookieExpire);
document.cookie="liuser="+escape(users.replace(/^\n/,""))+((!session)?'; expires='+cookieExpiry.toGMTString():"")+";";
document.cookie="litime="+escape(expires.replace(/^\n/,""))+((!session)?'; expires='+cookieExpiry.toGMTString():"")+";";
document.cookie="lipass="+escape(passwords.replace(/^\n/,""))+((!session)?'; expires='+cookieExpiry.toGMTString():"")+";";
document.cookie="lidn="+escape(dnames.replace(/^\n/,""))+((!session)?'; expires='+cookieExpiry.toGMTString():"")+";";
}else{
this.clearAllUsers();
}
}
var usertmp=document.cookie.match(/litmp=\d+/);
var usertemp=document.cookie.match(/litemp=\d+/);
var usersdn=document.cookie.match(/lidn=[^;]+/);
var users=document.cookie.match(/liuser=[^;]+/);
var userstime=document.cookie.match(/litime=[^;]+/);
var userspass=document.cookie.match(/lipass=[^;]+/);
var now=new Date();
this.li_userCount=0;
if(users){
users=unescape(users[0]).split('=')[1].split('\n');
userstime=unescape(userstime[0]).split('=')[1].split('\n');
userspass=unescape(userspass[0]).split('=')[1].split('\n');
usersdn=unescape(usersdn[0]).split('=')[1].split('\n');
for(count=0;count<users.length;count++){
if(now.getTime() < userstime[count]){
if(users[count].indexOf("\x07")==0){
this.li_noAlias[users[count].substr(1)]= {expire:userstime[count],password:userspass[count],displayname:usersdn[count]}
this.li_noAlias.count++;
}else{
this[users[count]]= {expire:userstime[count],password:userspass[count],displayname:usersdn[count]}
this.li_userCount++;
}
}else if(pb_username!="Guest" && pb_username!=users[count]){
alert('The logon for account '+users[count]+' has expired.\nIf you wish to have that account available for posting\nyou must log back into that account');
}
}
}
if(pb_username!="Guest"){
if(usertmp){
this[pb_username]= {expire:usertmp[0].split('=')[1],password:unescape(document.cookie.match(/\bpass=[^;]+/)[0]).split('=')[1],displayname:pb_displayname}
this.li_userCount++;
document.cookie="litmp= ; expires="+this.li_past;
}else if(usertemp){
this.li_noAlias[pb_username]= {expire:usertemp[0].split('=')[1],password:unescape(document.cookie.match(/\bpass=[^;]+/)[0]).split('=')[1],displayname:pb_displayname}
this.li_noAlias.count++;
document.cookie="litemp= ; expires="+this.li_past;
}
}else if(pb_username=="Guest" ){
document.cookie="li_prev=;expires="+this.li_past;
}
this.save();
this.setUser=function(username,isAlias){
if(username==pb_username)return;
var pass,exp;
isAlias=("undefined"==typeof isAlias)?true:false;
if(!(username in this)){
if(!(username in this.li_noAlias)){
alert("Error!\nCould not find login credentials for "+username+".\nUnable to set requested login");
if(document.cookie.match("li_prev="+username)) document.cookie="li_prev=;expires="+this.li_past;
return
}else{
pass=this.li_noAlias[username].password
exp=this.li_noAlias[username].expire
}
}else{
pass=this[username].password
exp=this[username].expire
}
var xdate=new Date(); xdate.setTime(exp);
document.cookie="user="+username+"; expires="+xdate.toGMTString()+";";
document.cookie="pass="+pass+"; expires="+xdate.toGMTString()+";";
window.location.href=window.location.href.replace(/\?/,"?"+((isAlias)?"alias="+username+"&":""))
}
}
try{
var logins=new LoginInfo(); var pa_popWin=null;
var xWin=null;
if(document.loginform){
var minutes=document.getElementsByName('minutes')[0];
var user=document.getElementsByName('username')[0];
var tr=minutes.parentNode.parentNode.parentNode.parentNode.insertRow(minutes.parentNode.parentNode.rowIndex+1);
user.onchange=function(){
if((this.value in logins) && document.getElementById('saveLogin'))
document.getElementById('saveLogin').checked=true;
else
document.getElementById('saveLogin').checked=false;
}
while(tr.cells.length<3){tr.insertCell(-1);tr.lastChild.width=tr.previousSibling.cells[tr.cells.length-1].width;}
var chk=document.createElement('input');chk.type="checkbox";
chk.value=false;chk.checked=false;chk.id="saveLogin";
chk.title='Include this login in my list of aliases';chk.alt=chk.title;
chk.onclick=function(){
if(Boolean(this.checked)==false && (user.value.length && user.value in logins)){
delete logins[user.value];logins.li_userCount--;logins.save();
this.parentNode.nextSibling.firstChild.innerHTML = 'Clear aliases now['+logins.li_userCount+']';
this.parentNode.nextSibling.firstChild.style.display.style=(logins.li_userCount)?'':'none';
this.parentNode.nextSibling.firstChild.title= "Aliases: "+unescape(document.cookie.match(/\bliuser=[^;]+/)[0]).split('=')[1].split('\n').join();
}
}
tr.firstChild.nextSibling.appendChild(chk);
tr.firstChild.nextSibling.appendChild(document.createElement('span'));
tr.firstChild.nextSibling.lastChild.appendChild(document.createTextNode('Include as alias'));
chk.nextSibling.title=chk.title;chk.nextSibling.alt=chk.alt;
var cl=document.createElement('a');
cl.href="javascript:void(0)";cl.onclick=function(){logins.clearAllUsers();this.style.display='none';}
cl.appendChild(document.createTextNode('Clear aliases now['+logins.li_userCount+']'))
tr.lastChild.appendChild(cl);
tr.firstChild.nextSibling.appendChild(document.createElement('br'));
chk=document.createElement('input');chk.type="checkbox";
chk.value=false;chk.checked=(document.cookie.match(/\lisession=[^;]+/)!=null); chk.id="sessionOnly";
tr.firstChild.nextSibling.appendChild(chk);
chk.parentNode.appendChild(document.createElement('span'));
chk.parentNode.lastChild.appendChild(document.createTextNode('Clear aliases on close'));
chk.title='Clear all aliases when browser closes'; chk.alt=chk.title;
chk.nextSibling.title=chk.title;chk.nextSibling.alt=chk.alt;
chk.onclick=function(){
if(this.checked)
document.cookie="lisession=1;";
else
document.cookie="lisession=; expires="+logins.li_past;
}
if(logins.li_userCount<1){
cl.style.display="none";
}else{
cl.title="Aliases: "+unescape(document.cookie.match(/\bliuser=[^;]+/)[0]).split('=')[1].split('\n').join();
cl.title=cl.title.replace(/\07[^,]+,?/g,"")
}
addEvent(document.loginform,"submit",saveLogin)
addEvent(user,"change",setAlias)
}
if((logins.li_userCount>1 || (logins.li_userCount==1 && (pb_username in logins.li_noAlias)))){
if(document.postForm ){
var row=document.postForm.subject.parentNode.parentNode;
var newrow=row.cloneNode(true);
if(!document.postForm.guestname){
row.parentNode.insertBefore(newrow,row);
newrow.cells[0].innerHTML="<b>Post as...<\/b>";
newrow.cells[1].innerHTML="<\!-- -\->";
showAccounts(newrow.cells[1],0,document.postForm);
}
}else if(document.getElementsByName('message').length ){
var qrmsg=document.getElementsByName('message')[0];
var acct=qrmsg.form.parentNode.parentNode.parentNode;
acct=acct.parentNode.insertRow(1);
acct=acct.insertCell(-1); acct.className="windowbg";
acct.innerHTML="<b>Post as...<\/b>";
showAccounts(acct,1,qrmsg.form);
var userprevious=document.cookie.match(/li_prev=[^;]+/);
if(userprevious){
document.getElementById('accounts').focus();
}
}
}
if("undefined"==typeof(document.postForm) && !location.href.match(/\?alias=/)){
var userprevious=document.cookie.match(/li_prev=[^;]+/);
if(userprevious){
userprevious=unescape(userprevious[0].split('=')[1]);
document.cookie="li_prev=;expires="+new Date(document.lastModified).toGMTString()+";";
if(pb_username!="Guest" && pb_username!=userprevious)
doConfirm('You will now be returned to the '+userprevious+' account.\n Select OK to continue or CANCEL to remain logged in as '+pb_username,"javascript:logins.setUser(userprevious,false)");
}
}
}catch(e){
alert('Post as..'+e+'\n'+e.message);
}
function protectPost(){
document.getElementById('accounts').disabled=true;
for(var inp in document.getElementById('accounts').frm){
if(inp.tagName && ((inp.tagName.match(/input/i) && !inp.type.match(/hidden|submit/i))||inp.tagName.match(/textarea/i))){
if(inp.detachEvent){
inp.detachEvent("onpropertychange",protectPost);
}else if(inp.removeEventListener){
inp.removeEventListener("input",protectPost,false);
}
}
}
}
function showAccounts(cell,pos,frm){
var opts=document.createElement('select');
opts.id="accounts";opts.setAttribute('frm',frm);
opts.onchange=function(){
if(pb_username!="Guest")document.cookie="li_prev="+pb_username+";";
logins.setUser(this.options[this.selectedIndex].value);
}
if(!(pb_username in logins)){
opts.options[opts.options.length]=new Option("Current User",pb_username);
opts.options[opts.options.length-1].selected=true;
}
for(key in logins){
if(key.substr(0,3)!="li_" && typeof(logins[key])!="function"){
opts.options[opts.options.length]=new Option(logins[key].displayname+" (username:"+key+")",key);
if(key==pb_username) opts.options[opts.options.length-1].selected=true;
}
}
var accountInfo=document.createElement('a');
accountInfo.appendChild(document.createTextNode('more details...'));
var f=document.createElement('sub');
accountInfo.href="javascript:void(0)";accountInfo.onclick=accountDetails;
cell.appendChild(opts);
f.appendChild(document.createTextNode(' available accounts:'+logins.li_userCount+' ('));
f.appendChild(accountInfo);f.appendChild(document.createTextNode(')'));
cell.appendChild(f);
for(var count=0;count< frm.childNodes.length;count++){
var inp=frm.childNodes[count];
if(inp.tagName && ((inp.tagName.match(/input/i) && !inp.type.match(/hidden|submit/i))||inp.tagName.match(/textarea/i))){
addEvent(inp,"propertychange",protectPost,false);
addEvent(inp,"input",protectPost,false);
}
}
}
function accountDetails(){
if(pa_popWin && pa_popWin.closed) {pa_popWin=null;}
if(pa_popWin && pa_popWin.document.getElementsByTagName('table').length>2) {
pa_popWin.close();
pa_popWin=null;
}
if(pa_popWin==null ){
pa_popWin=window.open("/index.cgi?action=viewthreadposts","popWindow","directories=0,location=0,menubar=0,resizable=1, scrollbars=1,status=1,toolbar=0,top=100,left=100,width=400,height=275");
if(pa_popWin==null){
alert("This feature won't function correctly with a popup blocker active. Try disabling any popup blockers or try holding CTRL key while clicking link to bypass blocker");
return false;
}
if(document.attachEvent){
var bool=false;
do{
try{pa_popWin.document.body.getElementsByTagName('table');bool=true;}catch(e){}
}while(!bool)
}else{
pa_popWin.onload=arguments.callee;
return true;
}
}
var y="";var d=new Date();
try{
var source=pa_popWin.document.body.getElementsByTagName('table');
}catch(e){
alert('Unable to display available accounts info');
pa_popWin.close(); pa_popWin=null;
return false;
}
pa_popWin.opener.name="paaccounts"; pa_popWin.document.title="Available Accounts";
source[1].getElementsByTagName('b')[0].innerHTML="Available Accounts";
source=source[1].rows[1].cells[0];
var tdS1=document.createElement('td');
var tdS2=document.createElement('td');
for(key in logins){
if(key.substr(0,3)!="li_" && typeof(logins[key])!="function"){
d.setTime(logins[key].expire);var dname;
dname=document.createElement('a');dname.href='index.cgi?action=viewprofile&user='+key;
dname.appendChild(document.createTextNode(logins[key].displayname));
dname.setAttribute("target","paaccounts");dname.onClick='opener.focus();setTimeout("self.close()",1);';
tdS1.appendChild(document.createElement('br'));tdS2.appendChild(document.createElement('br'));
tdS1.appendChild(dname);tdS2.appendChild(document.createTextNode(timeLeft(logins[key].expire)));
}
}
var w1=tdS1.innerHTML.replace(/target=/gim,"onClick='opener.focus(); setTimeout(\042self.close()\042,1);' target=").split(/<br\/?>/i);
var w2=tdS2.innerHTML.split(/<br\/?>/i);
for(var count=0;count<w1.length;count++){
if(w1[count].match(/href=/i))
y+="<tr><td width='40%' align='right'>"+w1[count]+"</td><td width='60%' align='center'>"+w2[count]+"</td></tr>";
}
if(y.length){
z="<span align='center'><br/><br/><a href='javascript:opener.logins.clearAllUsers();";
z+="opener.location.href=opener.location.href;opener.focus();setTimeout(\042self.close()\042,1);' >Clear all saved account(s)</a></span>";
}else{
z="";
}
source.innerHTML='<center><font size="2">Total accounts:'+logins.li_userCount+'<br><table width="70%" cellspacing="0" cellpadding="3" border="0" _base_target="paaccounts"><tbody ><tr _base_target="paaccounts"><td width="40%" align="right" _base_target="paaccounts"><font size="2"><u><i>User</i></u></font></td><td width="60%" align="center" _base_target="paaccounts"><font size="2"><u><i>Account Expiration</i></u></font></td></tr>'+y+'</tbody></table></font>'+z+'</center>';
setTimeout('pa_popWin.focus()',1);
addEvent(window,"unload",cleanScreen,true);
}
function cleanScreen(){if(pa_popWin!=null)pa_popWin.close();pa_popWin=null;}
function timeLeft(m){
var years,months,weeks,days,hours,minutes,tmp3;
years=months=weeks=days=hours=minutes=0; tmp3="";
var Now=new Date();var date=new Date(); date.setTime(m);
var hour=1000*60*60; var day=hour*24;
var ms=date-Now;
if(ms<0){ms=Math.abs(ms); tmp3+="-";}
years=Math.floor(ms/(day*365)); ms-=day*365*years;
months=Math.floor(ms/(day*30)); ms-=day*30*months;
if(months==12){months=0;years++}
weeks=Math.floor(ms/(day*7)); ms-=day*7*weeks;
days=Math.floor(ms/day); ms=ms-day*days;
if(years==0 && months==0 && weeks==0 && days==0){
hours=Math.floor(ms/hour); ms=ms-hour*hours;
minutes=Math.ceil(ms/(hour/60)); ms=ms-minutes*hour/60;
if(minutes==60){minutes=0;hours++}
if(hours==24){hours=0;days++}
}
years=(years)?years+" year"+((years!=1)?"s ":' '):'';
months=(months)?months+" month"+((months!=1)?"s ":' '):'';
weeks=(weeks)?weeks+" week"+((weeks!=1)?"s ":' '):'';
days=(days)?days+" day"+((days!=1)?"s ":' '):'';
hours=(hours)?hours+" hour"+((hours!=1)?"s ":' '):'';
minutes=(minutes)?minutes+" minute"+((minutes!=1)?"s ":' '):'';
if(String(minutes+hours+days+weeks+months+years).length==0)
minutes="less than 1 minute ";
if(years.length)weeks=days=hours=minutes="";
return tmp3+years+months+weeks+days+hours+minutes;
}
function addEvent(node,evName,func,capture,remove){
capture=(capture)?capture:false;
remove=(remove)?remove:false
if(node.attachEvent){
if(remove)
node.detachEvent("on"+evName,func);
else
node.attachEvent("on"+evName,func);
}else if(node.addEventListener){
if(remove)
node.removeEventListener(evName,func,capture);
else
node.addEventListener(evName,func,capture);
}else{
if(remove)
eval("node.on"+evName+"=null");
else
eval("node.on"+evName+"=func");
}
}
//-->
</script>