|
Post by Wormopolis on Mar 26, 2011 15:13:42 GMT -8
browsers tested: IE and FF placement: board or global footer
this code will store the OP author of each thread it finds and places a card you can edit above all the thread pages for that thread. It stores username and avatar, and has special variables you can edit for guest avatars, member default avatars, and guest intros.
the newTable variable at the top is the HTML you can edit to customize how the card looks. notice the embedded placeholders for username/avatar/titlestuff.
this requires an element in the global/board headers with id="OPclone" for the card to be inserted. I used a center tag for my testing to keep it aligned with the forum.
<script type="text/javascript"> <!-- // OP Info clone in table v1.1 // requires element with id="OPclone" // by Wormopolis - www.wormocodes.com // request by Auburn
// use cookie to store thread ids var numberOfThreadsToStore=10;
var titleStuff="Brought this thread to you"; var guestAvatar=''; //enter a URL here if you want an image to appear for guest created threads var guestIntro='A Guest named '; var defaultMemberAvatar=''; //enter a URL here if you want a default image when a member has no avatar
// This is the HTML for the table to appear above the posts. put $USERNAME where you want the username to appear, // $AVATAR where you want the avatar to appear, and $TITLESTUFF where you want it to appear
var newTable='<table width="100%" class="bordercolor"><tr><td align="center" vAlign="middle" width="30%" class="windowbg2">$USERNAME<br>$AVATAR</td><td class="windowbg" vAlign="middle">$TITLESTUFF</td></tr></table>';
// no need to edit below
if (pb_action=='display') { var firstPage=(!location.href.match(/page=/) || location.href.match(/page=1($|&)/)); var threadkeep=(location.href.match(/thread=(.*?)(&|$)/) ? RegExp.$1 : ''); for (tds=document.getElementsByTagName('td'), tt=0; tt<tds.length; tt++) { if (tds[tt].width=='20%' && tds[tt].className.match(/windowbg/) && tds[tt].vAlign=='top' ) { // locate first MP and extract author and avatar if present var authname=tds[tt].getElementsByTagName('a')[1].nextSibling; var authUname=(authname.nodeName.match(/b/i) ? authname.firstChild.href.split(/user=/)[1] : 'Guest'); var authDname=(authname.nodeName.match(/b/i) ? authname.firstChild.innerHTML : authname.nodeValue); var authAvatar=(authname.nodeName.match(/b/i) && tds[tt].getElementsByTagName('center')[0].firstChild.nodeName.match(/img/i) ? tds[tt].getElementsByTagName('center')[0].firstChild.src : ''); // cookie structure: threadid_uname+dname+[avurl], var olstrng='', found=-1; if (document.cookie.match(/OPhedder=(.*?)(;|$)/)) { var tmpArray=unescape(RegExp.$1).split(','); for (aa=0; aa<tmpArray.length; aa++) { var holdtmp=tmpArray[aa].split('_')[0]; if (holdtmp==threadkeep) found=aa; } // backdoor replace - put purgehedder into URL sting if (location.href.match(/purgehedder/)) { tmpArray.splice(found,1); found=-1;} if (found<0 && tmpArray.length>numberOfThreadsToStore) tmpArray.splice(0,1); olstrng=tmpArray.join(','); } if (found<0 && firstPage) { olstrng+=','+threadkeep+ '_' +authUname+ '+' +authDname+ '+[' +authAvatar+ ']'; olstrng=escape(olstrng); var expD=new Date(); expD.setFullYear(expD.getFullYear()+1); document.cookie='OPhedder='+olstrng+'; expires='+expD; } else { authUname=tmpArray[found].split('_')[1].split('+')[0]; authDname=tmpArray[found].split('_')[1].split('+')[1].split('+[')[0]; authAvatar=tmpArray[found].split('+[')[1].split(']')[0]; } // build Card var profLink=(authUname=='Guest' ? guestIntro+authDname : '<a href="/index.cgi?action=viewprofile&user=' +authUname+ '">' +authDname+ '</a>'); var nwAvImg=(authUname=='Guest' ? (guestAvatar ? '<img height="100" width="100" src="' +guestAvatar+ '">' : '') : (authAvatar ? '<img height="100" width="100" src="' +authAvatar+ '">' : (defaultMemberAvatar ? '<img height="100" width="100" src="' +defaultMemberAvatar + '">' : ''))); var holder=document.createElement('div'); holder.innerHTML=newTable.replace('$USERNAME',profLink).replace('$AVATAR',nwAvImg).replace('$TITLESTUFF',titleStuff); if (document.getElementById('OPclone') && (firstPage || found>=0)) { document.getElementById('OPclone').appendChild(holder); document.getElementById('OPclone').style.display=''; } break; } } }
// --> </script>
if you look at some threads in the "testing something" board you will see what the default looks like.
|
|