|
Alters
Oct 31, 2012 22:36:39 GMT -8
Post by Wormopolis on Oct 31, 2012 22:36:39 GMT -8
Browsers Tested: IE, FF, and Chrome placement: global footer
This code will let you set up alternate characters for your members to post as. You will have to store all the character info in the code because ther just isnt enough room in a member;s profile to store everything. once a single line has been added for each character, they will get a drop down when they make a post that they can post as.
the post will show that character as the author, and even the name will be clickable to go to a "fake" character profile page. on that page there will be a link to recent posts by that character, as well as an optional link to a special "history" post that the member makes.
the member will see a drop down on their own normal profile showing all of their alters.
<script type="text/javascript"> <!-- // Alters // v 1.0 // by Wormopolis - www.wormocodes.com // keep header intact - do not repost // // evolved from codes // choose RPG character when posting by Ross // Post Alias by Eton
var userAlters=new Array(); //leave this line alone
function createAlter(username, altername, postperc, joined, gender, location, avatarURL,ptext,bday,history) { if (!userAlters[username]) userAlters[username]=new Array(); userAlters[username][userAlters[username].length]={ Name: altername, PostPerc: postperc, JoinDate: joined, Gender: gender, Location: location, Avatar: avatarURL, Ptext: ptext, Birthday: bday, LinkToProfileThread: history }; }
/*---------------- Assign Alters for your members here ------------------------*/ //format: createAlter('username','character name','percentage of total posts','Join Date (Month Year)','Gender','Location','URL to avatar','personal text','Birthday','Link to personalthread');
createAlter('admin','Simon','25%','Nov 2010','Male','Maine','http://upload.wikimedia.org/wikipedia/commons/thumb/9/99/OriginalSimon.jpg/200px-OriginalSimon.jpg','Remember this game?','10/10/1980','/index.cgi?board=profiles&thread=1234'); createAlter('admin','Theodore','20%','Dec 2010','Male','Colorado','http://upload.wikimedia.org/wikipedia/commons/thumb/1/19/President_Theodore_Roosevelt,_1904.jpg/220px-President_Theodore_Roosevelt,_1904.jpg','Walk softly and carry a big stick.','1/11/1923','/index.cgi?board=profiles&thread=213');
/* -----------------------------------------------------------------------------------------*/
var maxAvatarHeight="100"; var maxAvatarWidth="100";
// END USER VARIABLES // No need to edit below
if (document.postForm) { var subrow=document.postForm.subject.parentNode.parentNode; var alterhide=document.createElement('input'); alterhide.type='hidden'; alterhide.id='alterhide'; subrow.firstChild.appendChild(alterhide); if (pb_action!='modifypost') { if (userAlters[pb_username]) { var alterRow=subrow.cloneNode(true); alterRow.firstChild.firstChild.innerHTML="Alters:"; var alterdrop='<select name="alterdrop" onchange="document.getElementById(\'alterPreview\').src=this.value; document.getElementById(\'alterhide\').value=this.options[this.selectedIndex].innerHTML;" style="vertical-align:top"><option value="http://images.proboards.com/blank.gif"></option>'; for (aa=0; aa<userAlters[pb_username].length; aa++) alterdrop+='<option value="' + userAlters[pb_username][aa].Avatar + '">' + userAlters[pb_username][aa].Name + '</option>'; alterdrop+='</select><img id="alterPreview" src="http://images.proboards.com/blank.gif" height="50" width="50">'; alterRow.firstChild.nextSibling.innerHTML=alterdrop; subrow.parentNode.insertBefore(alterRow, subrow.nextSibling); } } else { if (document.postForm.message.value.match(/\[Alter:(.*?)\]/)) { document.getElementById('alterhide').value=RegExp.$1; document.postForm.message.value=document.postForm.message.value.replace(/\[Alter:(.*?)\]/,''); } } if (document.postForm.addEventListener) { document.postForm.addEventListener('submit',function(){if (document.getElementById('alterhide').value!='') document.postForm.message.value+='[Alter'+':'+document.getElementById('alterhide').value +']';},true); } else { document.postForm.attachEvent('onsubmit',function(){if (document.getElementById('alterhide').value!='') document.postForm.message.value+='[Alter'+':'+document.getElementById('alterhide').value +']';}); } }
function recomma(orig, perc) { var tmp=parseInt(parseInt(orig.replace(/\,/g,'')) * (parseInt(perc) /100))+''; nwtmp=''; while (tmp.length>3) {nwtmp=',' + tmp.substr(tmp.length-3,3); tmp=tmp.substr(0,tmp.length-3);} nwtmp=tmp+nwtmp; return nwtmp; }
function resizeAv(av) { avtmp=document.createElement('img'); avtmp.src=av.src; if (avtmp.width>maxAvatarWidth) {avtmp.height=avtmp.height*(maxAvatarWidth/avtmp.width); avtmp.width=maxAvatarWidth;} if (avtmp.height>maxAvatarHeight) {avtmp.width=avtmp.width*(maxAvatarHeight/avtmp.height); avtmp.height=maxAvatarHeight;} av.style.display=''; av.height=avtmp.height; av.width=avtmp.width; }
function calcbirthday(bdate) { if (bdate) { var bd=new Date(bdate), td=new Date(); bd=parseInt((td-bd)/(1000*60*60*24*365.2425)); return bd; } else { return "Unknown"; } }
(function() { if (pb_action.match(/display|recent|search2/)) { for (td=document.getElementsByTagName('td'), tt=0; tt<td.length; tt++) { if (td[tt].width=='80%' && td[tt].className.match(/windowbg/) && td[tt].innerHTML.match(/\[Alter(:)(.*?)\]/)) { var namekeep=RegExp.$2; td[tt].innerHTML=td[tt].innerHTML.replace(/\[Alter(:)(.*?)\]/,''); for (ital=td[tt].getElementsByTagName('i'), ii=0; ii<ital.length; ii++) { if (ital[ii].innerHTML.match(/last edit/i)) { var lelink=ital[ii].parentNode.getElementsByTagName('a')[0]; lelink.href+='&alter='+namekeep; lelink.innerHTML=namekeep; break; } } var mpcell=td[tt].previousSibling; var mpname=mpcell.getElementsByTagName('b')[0]; if (mpname) { var searchname=(mpname.firstChild.href.match(/user=(.*?)($|&)/) ? RegExp.$1 : ''); if (userAlters[searchname]) { for (ua=0; ua<userAlters[searchname].length; ua++) { if (userAlters[searchname][ua].Name==namekeep) {var foundname=userAlters[searchname][ua]; break;} } if (foundname) { mpname.firstChild.href+= '&alter=' + escape(namekeep); while (!mpname.nextSibling.nodeName.match(/center/i)) mpname.parentNode.removeChild(mpname.nextSibling); mpname.firstChild.innerHTML=foundname.Name; mpname.parentNode.insertBefore(document.createElement('br'), mpname.nextSibling); mpname.parentNode.insertBefore(document.createElement('br'), mpname.nextSibling); mpcell.getElementsByTagName('center')[0].innerHTML= '<img src="' + foundname.Avatar + '" style="display:none" onload="resizeAv(this)"><br>' + foundname.Ptext+ '<br>'; var holdforlater=mpcell.innerHTML; wtf=holdforlater.match(/Posts: (.*?)<br>/i); holdforlater=holdforlater.replace(/Posts: (.*?)<br>/i,'Posts: ' + recomma(wtf[1], foundname.PostPerc) + '<br>'); holdforlater=holdforlater.replace(/Joined: (.*?)<br>/i,'Joined: ' +foundname.JoinDate + '<br>'); holdforlater=holdforlater.replace(/Location: (.*?)<br>/i,'Location: ' +foundname.Location + '<br>'); holdforlater=holdforlater.replace(/Gender: (.*?)<br>/i,'Gender: ' +foundname.Gender + '<br>'); mpcell.innerHTML=holdforlater; } } } } } } if (pb_action.match(/viewprofile/)) { if (location.href.match(/&alter=(.*?)(&|$)/)) { var namekeep=RegExp.$1; for (td=document.getElementsByTagName('td'), tt=0; tt<td.length; tt++) { if (td[tt].width=='20%' && td[tt].className.match(/windowbg/)) { var mpcell=td[tt]; var mpname=mpcell.getElementsByTagName('b')[0]; if (mpname) { var searchname=(mpname.firstChild.href.match(/user=(.*?)($|&)/) ? RegExp.$1 : ''); if (userAlters[searchname]) { for (ua=0; ua<userAlters[searchname].length; ua++) { if (userAlters[searchname][ua].Name==namekeep) {var foundname=userAlters[searchname][ua]; break;} } if (foundname) { mpname.firstChild.href+= '&alter=' + escape(namekeep); while (!mpname.nextSibling.nodeName.match(/center/i)) mpname.parentNode.removeChild(mpname.nextSibling); var keepname=mpname.firstChild.href.split('user=')[1].split('&')[0]; mpname.firstChild.innerHTML=foundname.Name; mpname.parentNode.insertBefore(document.createElement('br'), mpname.nextSibling); mpname.parentNode.insertBefore(document.createElement('br'), mpname.nextSibling); mpcell.getElementsByTagName('center')[0].innerHTML= '<img src="' + foundname.Avatar + '" style="display:none" onload="resizeAv(this)"><br>' + foundname.Ptext+ '<br>'; var holdforlater=mpcell.innerHTML; wtf=holdforlater.match(/Posts: (.*?)<br>/i); var postChange=recomma(wtf[1], foundname.PostPerc); holdforlater=holdforlater.replace(/Posts: (.*?)<br>/i,'Posts: ' + postChange + '<br>'); holdforlater=holdforlater.replace(/Joined: (.*?)<br>/i,'Joined: ' +foundname.JoinDate + '<br>'); holdforlater=holdforlater.replace(/Location: (.*?)<br>/i,'Location: ' +foundname.Location + '<br>'); holdforlater=holdforlater.replace(/Gender: (.*?)<br>/i,'Gender: ' +foundname.Gender + '<br>'); mpcell.innerHTML=holdforlater; document.title="View Profile: " + foundname.Name; mpcell.parentNode.parentNode.getElementsByTagName('b')[0].innerHTML="View Profile: "+foundname.Name; mpcell.parentNode.parentNode.getElementsByTagName('b')[0].nextSibling.nodeValue=""; for (lnks=document.getElementsByTagName('a'), ll=0; ll<lnks.length; ll++) { if (lnks[ll].className=='nav' && !lnks[ll].href.match(/&action=/)) { lnks[ll].nextSibling.nodeValue=" :: View Profile: "+foundname.Name; break; } } mpcell.nextSibling.innerHTML=''; var boardlist=''; for (fj=document.getElementById('forumjump').options, ff=0; ff<fj.length; ff++) { if (fj[ff].value.match(/board=(.*?)(&|$)/)) boardlist+='&board-'+RegExp.$1+'=1'; } var profcell=''; profcell='<font size="2"><table width="100%" cellspacing="1" cellpadding="4" border="0"><tbody><tr><td colspan="2"><font size="2"><b>Member\'s Bio</b><hr size="1"></font></td></tr><tr><td width="25%"><font size="2">Name:</font></td><td><font size="2">' + foundname.Name + '</font></td></tr><tr><td width="25%"><font size="2">History:</font></td><td><font size="2">'+ (foundname.LinkToProfileThread ? '<a target="_blank" href="' + foundname.LinkToProfileThread + '">Thread Link</a>' : 'Not Available') + '</font></td></tr><tr><td width="25%"><font size="2">Birthday:</font></td><td><font size="2">' + foundname.Birthday +'</font></td></tr><tr><td width="25%"><font size="2">Age:</font></td><td><font size="2">' + calcbirthday(foundname.Birthday) + '</font></td></tr><tr><td width="25%"><font size="2">Gender:</font></td><td><font size="2">' + foundname.Gender +'</font></td></tr><tr><td width="25%"><font size="2">Location:</font></td><td><font size="2">' + foundname.Location + '</font></td></tr><tr><td width="25%"><font size="2">Posts:</font></td><td><font size="2">' + postChange +'</font></td></tr><tr><td width="25%"><font size="2">Date Registered:</font></td><td><font size="2">' + foundname.JoinDate + '</font></td></tr></tbody></table><hr><a href="/index.cgi?' + 'action=search2&search=[Alter=' + foundname.Name + ']&match=3&whattosearch=1&user=' + keepname + '&maxresults=100&viewtype=1&subject=1&message=1&hours=3264' + boardlist + '">Recent Threads</a></font>'; mpcell.nextSibling.innerHTML=profcell; break; } } } } } } else { var profname=(location.href.match(/user=/) ? location.href.split('user=')[1].split('&')[0] : pb_username); if (userAlters[profname]) { var alterDrop='<select id="alterdrop" onchange="location.href=this.options[this.selectedIndex].value"><option></option>'; for (ua=0; ua<userAlters[profname].length; ua++) { alterDrop+='<option value="/index.cgi?action=viewprofile&user=' + profname + '&alter=' + userAlters[profname][ua].Name + '">' + userAlters[profname][ua].Name + '</option>'; } alterDrop+='</select>'; for (td=document.getElementsByTagName('td'), tt=0; tt<td.length; tt++) { if (td[tt].width=='80%' && td[tt].className.match(/windowbg/) && td[tt].innerHTML.match(/Member's Bio/)) { var mbtable=td[tt].getElementsByTagName('table')[0]; var nwrw=mbtable.insertRow(-1); nwrw.insertCell(0); nwrw.cells[0].colSpan=2; nwrw.cells[0].innerHTML='<font size="2"><b>Alters</b><hr size="1"></font>'; var nwrw=mbtable.insertRow(-1); nwrw.insertCell(0); nwrw.cells[0].colSpan=2; nwrw.cells[0].innerHTML=alterDrop; break; } } } } } })(); //--> </script>
|
|