Post by Todge on Jun 19, 2011 15:03:28 GMT -8
This will allow your members to create a 'Buddy List', either by invitation or by simply selecting those they want, depending on how you edit the code.
The 'buddies' can be chosen from either the member's profile pages or in the members list, and your chosen buddies are listed in your profile page, or as a drop-down on the PM page, allowing you to chose those you want the PM sent to.
The code goes in your GLOBAL FOOTER, and all you need to edit is this part.
'Invite' is to set the code to send invitations and 'addlink' will allow your members to add buddies without an invitation. Set either, or both to 'y' to activate them.
The code will only work on the later browsers -- IE7 and above (I believe), FF 4.5 and above etc. and has been tested in FF, IE, Safari, Opera and Iron(Chrome).
The 'buddies' can be chosen from either the member's profile pages or in the members list, and your chosen buddies are listed in your profile page, or as a drop-down on the PM page, allowing you to chose those you want the PM sent to.
The code goes in your GLOBAL FOOTER, and all you need to edit is this part.
var invite = 'y';
var addlink = 'n';
'Invite' is to set the code to send invitations and 'addlink' will allow your members to add buddies without an invitation. Set either, or both to 'y' to activate them.
The code will only work on the later browsers -- IE7 and above (I believe), FF 4.5 and above etc. and has been tested in FF, IE, Safari, Opera and Iron(Chrome).
<table width="100%" id="buddytable" class="bordercolor" cellpadding="4" cellspacing="1" style="display: none;">
<tbody>
<tr><td id="buddytitle" class="titlebg"></td></tr>
<tr><td id="buddycontent" class="windowbg" align="center" style="font-size: 20px;"></td></tr>
</tbody>
</table>
<script type="text/javascript">
<!--
/*
PB Buddies
by Todge
Copyright © 2011
Please keep this header intact
*/
// Edit below...
var invite = 'y';
var addlink = 'n';
// edit above...
var checklist = pb_username+'Buddies';
function addBuddy(peepdisplay,peepuser)
{
peepuser = '{'+peepuser+'}';
if(!localStorage[checklist])
{
localStorage[checklist] = peepdisplay+peepuser+';';
}
else if(!localStorage[checklist].match(peepuser))
{
localStorage[checklist] += peepdisplay+peepuser+';';
}
return;
}
function updateBuddy(peepdisplay,peepuser)
{
peepuser = '{'+peepuser;
var peep2check = peepdisplay+peepuser;
if(!localStorage[checklist])
{
return;
}
var buds = localStorage[checklist];
if(buds.match(peepuser) && !buds.match(peep2check))
{
buds = buds.split(peepuser);
buds[0] = buds[0].split('};');
buds[0][buds[0].length-1] = peepdisplay;
buds[0] = buds[0].join('};');
localStorage[checklist] = buds.join(peepuser);
return;
}
return;
}
function removeBuddy(peepuser)
{
peepuser = '{'+peepuser+'};';
var buds = localStorage[checklist].split(peepuser);
buds[0] = buds[0].split('};');
buds[0][buds[0].length-1] = '';
buds[0] = buds[0].join('};');
localStorage[checklist] = buds.join('');
return;
}
function removeInvite()
{
var del = document.getElementsByTagName('input')
{
for(d=0; d<del.length; d++)
{
if(del[d].type == 'checkbox' && del[d].name.match(/delete-/))
{
var dCell = del[d].parentNode.nextSibling;
if(dCell.getElementsByTagName('img')[0].alt.match(/(Replied|Read)/) && dCell.nextSibling.innerHTML.match(/Buddy Invitation from/))
{
del[d].checked = true;
}}}}
return;
}
function clearBuddies()
{
var sure=confirm('Are you sure you want to delete all your Buddies?');
if (sure==true)
{
localStorage.removeItem(checklist);
location.reload(true);
}
return;
}
// Add invite/link to profile page...
var proCheck = new RegExp('tion=viewprofile(&user='+pb_username+')?$');
if(location.href.match(/viewprofile&user=/) && !location.href.match(proCheck))
{
var user = location.href.split(/viewprofile&user=/)[1];
var disp = document.title.split(/Profile: /)[1];
var biocell = document.getElementsByTagName('b');
for(b=0; b<biocell.length; b++)
{
if(biocell[b].innerHTML.match(/^Member's Bio -/) && window['localStorage'] !== null)
{
updateBuddy(disp,user);
user2check = '{'+user+'}';
if(addlink.match(/y/i))
{
if(!localStorage[checklist] || !localStorage[checklist].match(user2check))
{
biocell[b].appendChild(document.createTextNode(' - '));
var buddylink = document.createElement('a');
buddylink.innerHTML = 'Add As Buddy';
buddylink.href = 'javascript:addBuddy(disp,user);location.reload(true);';
biocell[b].appendChild(buddylink);
}}
if(localStorage[checklist] && localStorage[checklist].match(user2check))
{
biocell[b].appendChild(document.createTextNode(' - '));
if(addlink.match(/y/i))
{
var buddylink = document.createElement('a');
buddylink.innerHTML = 'Remove As Buddy';
buddylink.href = 'javascript:removeBuddy(user);location.reload(true);';
}
else if(invite.match(/y/i))
{
var buddylink = document.createElement('a');
var mess = disp+', I have removed you from my Buddy List. Sorry.';
buddylink.innerHTML = 'Remove As Buddy';
buddylink.href = '/index.cgi?action=pmsend&to='+user+'&subject='+pb_displayname+'{'+pb_username+'}RMB&message='+mess;
}
biocell[b].appendChild(buddylink);
}
if(invite.match(/y/i) && (!localStorage[checklist] || !localStorage[checklist].match(user2check)))
{
var mess = 'Invite:'+pb_displayname+'{'+pb_username+'}&peep='+disp;
biocell[b].appendChild(document.createTextNode(' - '));
var addlink = document.createElement('a');
addlink.innerHTML = 'Send Buddy Invitation';
addlink.href = '/index.cgi?action=pmsend&to='+user+'&subject=Buddy Invitation from '+pb_displayname+'&message='+mess;
biocell[b].appendChild(addlink);
}
}}}
// Send invite and confirm...
var forum = document.getElementsByTagName('a');
for(f=0; f<forum.length; f++)
{
if(forum[f].className == 'nav')
{
forum = forum[f].parentNode.getElementsByTagName('table')[0];
break;
}}
var buddytitle = document.getElementById('buddytitle');
var buddycontent = document.getElementById('buddycontent');
if(pb_action == 'pmsend' && document.postForm.message.value.match(/^Invite:/))
{
forum.style.display = 'none';
var peep = location.href.split('&peep=')[1].replace(/%20/g,' ');
buddytitle.innerHTML = 'Buddy Invitation';
buddycontent.innerHTML = 'Do you really want to send '+peep+' a buddy invitation?<br><br>';
buddycontent.innerHTML += '<input id="yes" type="button" value="Yes"> ';
buddycontent.innerHTML += '<input id="no" type="button" value="No">';
document.getElementById('yes').onclick = function(){document.postForm.submit();}
document.getElementById('no').onclick = function(){document.location.href = document.referrer;}
forum.parentNode.insertBefore(document.getElementById('buddytable'),forum);
document.getElementById('buddytable').style.display = '';
}
if(pb_action == 'pm' && document.referrer.match(/&message=Invite:/))
{
forum.style.display = 'none';
var peep = document.referrer.split('&peep=')[1].split('{')[0].replace(/%20/g,' ');
buddytitle.innerHTML = 'Buddy Invitation';
buddycontent.innerHTML = 'A Buddy Invitation has been sent to '+peep+'.<br>You will be notified if and when they accept.<br><br>';
buddycontent.innerHTML += '<input id="yes" type="button" value="Ok">';
document.getElementById('yes').onclick = function(){document.location.href = '/index.cgi';}
forum.parentNode.insertBefore(document.getElementById('buddytable'),forum);
document.getElementById('buddytable').style.display = '';
}
// Accept or reject buddy invititation...
if(pb_action == 'pmview' && document.title.match(/Inbox :: Buddy Invitation from /))
{
var reply = document.getElementsByTagName('a');
for(r=0; r<reply.length; r++)
{
if(reply[r].href.match(/quote=/))
{
reply = reply[r].href;
break;
}}
forum.style.display = 'none';
var peep = document.title.split('Buddy Invitation from ')[1];
buddytitle.innerHTML = 'Buddy Invitation';
buddycontent.innerHTML = peep+' has sent you a Buddy Invitation.<br><br>';
buddycontent.innerHTML += '<input id="yes" type="button" value="Accept"> ';
buddycontent.innerHTML += '<input id="later" type="button" value="Respond Later"> ';
buddycontent.innerHTML += '<input id="no" type="button" value="Reject">';
forum.parentNode.insertBefore(document.getElementById('buddytable'),forum);
document.getElementById('buddytable').style.display = '';
var user = document.getElementsByTagName('font');
for(u=0; u<user.length; u++)
{
if(user[u].innerHTML.match(/google_ad_section_start/))
{
user = user[u].innerHTML.split('Invite:')[1].split('<!-- google')[0];
break;
}}
var user = user.split('{')[1].split('}')[0];
reply += '&accept='+peep;
var reject = peep;
document.getElementById('yes').onclick = function(){addBuddy(peep,user);document.location.href = reply;}
document.getElementById('later').onclick = function(){document.location.href = '/index.cgi?action=pm';}
document.getElementById('no').onclick = function(){document.location.href = '/index.cgi?action=pm&rejected='+reject;}
}
if(pb_action == 'pmsend' && location.href.match(/&accept=/))
{
forum.style.display = 'none';
var peep = document.postForm.message.value.split('Invite:')[1].split('{')[0];
var accepted = 'Accepted: '+pb_displayname+'{'+pb_username+'}';
document.postForm.message.value += accepted;
buddytitle.innerHTML = 'Buddy Invitation';
buddycontent.innerHTML = peep+' has been added to your Buddy List<br><br>';
buddycontent.innerHTML += '<input id="yes" type="button" value="OK">';
document.getElementById('yes').onclick = function(){document.postForm.submit();}
forum.parentNode.insertBefore(document.getElementById('buddytable'),forum);
document.getElementById('buddytable').style.display = '';
}
if(pb_action == 'pm' && document.referrer.match(/&accept=/))
{
forum.style.display = 'none';
var peep = document.referrer.split('&accept=')[1].replace(/%20/g,' ');
buddytitle.innerHTML = 'Buddy Invitation';
buddycontent.innerHTML = peep+' has been informed and you will now be added to their Buddy List.<br><br>';
buddycontent.innerHTML += '<input id="yes" type="button" value="Ok">';
removeInvite();
document.getElementById('yes').onclick = function(){document.pmForm.submit();}
forum.parentNode.insertBefore(document.getElementById('buddytable'),forum);
document.getElementById('buddytable').style.display = '';
}
if(pb_action == 'pm' && location.href.match(/&rejected=/))
{
forum.style.display = 'none';
var peep = location.href.split('&rejected=')[1].replace(/%20/g,' ');
buddytitle.innerHTML = 'Buddy Rejection';
buddycontent.innerHTML = peep+' has not been added to your Buddy List,<br>and you will not be added to theirs.<br><br>';
buddycontent.innerHTML += '<input id="yes" type="button" value="Ok">';
removeInvite();
document.getElementById('yes').onclick = function(){document.pmForm.submit();}
forum.parentNode.insertBefore(document.getElementById('buddytable'),forum);
document.getElementById('buddytable').style.display = '';
}
if(pb_action == 'pmview' && document.title.match(/Inbox :: Re: Buddy Invitation from /))
{
forum.style.display = 'none';
var pp = document.getElementsByTagName('font');
for(p=0; p<pp.length; p++)
{
if(pp[p].size == '2' && pp[p].innerHTML.match(/Accepted: /))
{
var peep = pp[p].innerHTML.split('Accepted: ')[1].split('<')[0];
}}
var user = peep.split('{')[1].split('}')[0];
peep = peep.split('{')[0];
buddytitle.innerHTML = 'Buddy Invitation';
buddycontent.innerHTML = peep+' has accepted your Buddy Invitation.<br><br>';
buddycontent.innerHTML += '<input id="yes" type="button" value="OK"> ';
forum.parentNode.insertBefore(document.getElementById('buddytable'),forum);
document.getElementById('buddytable').style.display = '';
document.getElementById('yes').onclick = function(){addBuddy(peep,user);document.location.href = '/index.cgi?action=pm&invited='+peep;}
}
if(pb_action == 'pm' && location.href.match(/&invited=/))
{
forum.style.display = 'none';
var peep = location.href.split('&invited=')[1].replace(/_/g,' ');
buddytitle.innerHTML = 'Buddy Invitation';
buddycontent.innerHTML = peep+' has been added to your Buddy List.<br><br>';
buddycontent.innerHTML += '<input id="yes" type="button" value="Ok">';
removeInvite();
document.getElementById('yes').onclick = function(){document.pmForm.submit();}
forum.parentNode.insertBefore(document.getElementById('buddytable'),forum);
document.getElementById('buddytable').style.display = '';
}
// Remove buddy and confirm...
if(pb_action == 'pmsend' && document.postForm.subject.value.match(/}RMB/))
{
forum.style.display = 'none';
var peep = document.postForm.message.value.split(', I have')[0];
buddytitle.innerHTML = 'Buddy Removal';
buddycontent.innerHTML = 'Are you sure you want to remove '+peep+' from your Buddy List.<br><br>';
buddycontent.innerHTML += '<input id="yes" type="button" value="Yes"> ';
buddycontent.innerHTML += '<input id="no" type="button" value="No">';
document.getElementById('yes').onclick = function(){removeBuddy(document.postForm.to.value);document.postForm.submit();}
document.getElementById('no').onclick = function(){document.location.href = document.referrer;}
forum.parentNode.insertBefore(document.getElementById('buddytable'),forum);
document.getElementById('buddytable').style.display = '';
}
if(pb_action == 'pm' && document.referrer.match(/(}|%7D)RMB/))
{
forum.style.display = 'none';
var peep = document.referrer.split('&message=')[1].split(/,/)[0].replace(/%20/g,' ');
buddytitle.innerHTML = 'Buddy Removal';
buddycontent.innerHTML = peep+' has been removed from your Buddy List.<br><br>';
buddycontent.innerHTML += '<input id="yes" type="button" value="Ok">';
document.getElementById('yes').onclick = function(){location.href = '/index.cgi';}
forum.parentNode.insertBefore(document.getElementById('buddytable'),forum);
document.getElementById('buddytable').style.display = '';
}
if(pb_action == 'pm')
{
var del = document.getElementsByTagName('input')
{
for(d=del.length-1; d>-1; d--)
{
if(del[d].type == 'checkbox' && del[d].name.match(/delete-/))
{
var dCell = del[d].parentNode.nextSibling;
if(dCell.getElementsByTagName('img')[0].alt.match(/(New)/) && dCell.nextSibling.innerHTML.match(/}RMB/))
{
del[d].checked = true;
forum.style.display = 'none';
var peep = dCell.nextSibling.firstChild.innerHTML.split(/{([A-z]?\d?)+}RMB/)[0].split(/>/)[1];
var user = dCell.nextSibling.firstChild.innerHTML.split(peep+'{')[1].split('}')[0];
removeBuddy(user);
buddytitle.innerHTML = 'Buddy Removal';
buddycontent.innerHTML = peep+' has removed you from their Buddy List.<br><br>';
buddycontent.innerHTML += '<input id="yes" type="button" value="Ok">';
document.getElementById('yes').onclick = function(){document.pmForm.submit();}
forum.parentNode.insertBefore(document.getElementById('buddytable'),forum);
document.getElementById('buddytable').style.display = '';
break;
}}}}
}
// Add Buddy List to Profile...
if(localStorage[checklist])
{
var buddies = localStorage[checklist].split('};');
buddies = buddies.sort();
if(location.href.match(proCheck))
{
var proCell = document.getElementsByTagName('td');
for(p=0; p<proCell.length; p++)
{
if(proCell[p].colSpan == '2' && proCell[p].innerHTML.match(/Recent Activity/))
{
proCell = proCell[p].parentNode.parentNode;
break;
}}
var TR = document.createElement('tr');
var TD = document.createElement('td');
with(TD){colSpan = '2'; innerHTML = '<font size="2"><b>Buddies</b><hr size="1"></font>';}
TR.appendChild(TD);
proCell.appendChild(TR);
var TR = document.createElement('tr');
var TD1 = document.createElement('td');
var TD2 = document.createElement('td');
TD2.innerHTML = '<font size="2"><b><a href="javascript:clearBuddies()">Clear Buddy List</a></b></font>';
TR.appendChild(TD1);
TR.appendChild(TD2);
proCell.appendChild(TR);
for(b=1; b<buddies.length; b++)
{
var TR = document.createElement('tr');
var TD1 = document.createElement('td');
var TD2 = document.createElement('td');
var user = buddies[b].split('{')[1];
var peep = buddies[b].split('{')[0];
TD1.innerHTML = '<font size="2"><a href="/index.cgi?action=viewprofile&user='+user+'">'+peep+'</a></font>';
TD2.innerHTML = '<a href="/index.cgi?action=pmsend&to='+user+'">Send PM</a> |';
if(addlink.match(/y/i))
{
TD2.innerHTML += ' <a href="javascript:removeBuddy(\''+user+'\');location.reload(true);">Remove from Buddy List</a>';
}
else if(invite.match(/y/i))
{
var mess = peep+', I have removed you from my Buddy List. Sorry.';
var subj = pb_displayname+'{'+pb_username+'}RMB';
TD2.innerHTML += ' <a href="/index.cgi?action=pmsend&to='+user+'&subject='+subj+'&message='+mess+'">Remove from Buddy List</a>';
}
TD2.innerHTML = '<font size="2">'+TD2.innerHTML+'</font>';
TR.appendChild(TD1);
TR.appendChild(TD2);
proCell.appendChild(TR);
}}}
// Add links to members list...
if(pb_action == 'members')
{
var me = new RegExp(pb_username+'$');
var members = forum.getElementsByTagName('a');
for(m=0; m<members.length; m++)
{
if(members[m].href.match(/tion=viewprofile&user=/) && !members[m].href.match(me))
{
if(members[m].firstChild.nodeName == 'FONT')
{
var disp = members[m].firstChild.innerHTML;
}
else
{
var disp = members[m].innerHTML;
}
var user = members[m].href.split(/&user=/)[1];
var user2check = '{'+user+'};';
updateBuddy(disp,user);
var font = document.createElement('font');
font.size="1";
if(!localStorage[checklist] || !localStorage[checklist].match(user2check))
{
if(addlink.match(/y/i))
{
var add = document.createElement('a');
add.innerHTML = 'Add as Buddy';
add.href = 'javascript:addBuddy("'+disp+'","'+user+'");location.reload(true);';
font.appendChild(add);
members[m].parentNode.parentNode.appendChild(document.createElement('br'));
members[m].parentNode.parentNode.appendChild(font);
}
if(invite.match(/y/i))
{
if(addlink.match(/y/i))
{
font.appendChild(document.createTextNode(' | '));
}
else
{
members[m].parentNode.parentNode.appendChild(document.createElement('br'));
}
var mess = 'Invite:'+pb_displayname+'{'+pb_username+'}&peep='+disp;
var add= document.createElement('a');
add.innerHTML = 'Send Buddy Invitation';
add.href = '/index.cgi?action=pmsend&to='+user+'&subject=Buddy Invitation from '+pb_displayname+'&message='+mess;
font.appendChild(add);
members[m].parentNode.parentNode.appendChild(font);
}}
if(localStorage[checklist] && localStorage[checklist].match(user2check))
{
var add= document.createElement('a');
add.innerHTML = 'Remove As Buddy';
if(addlink.match(/y/i))
{
add.href = 'javascript:removeBuddy("'+user+'");location.reload(true);';
}
else if(invite.match(/y/i))
{
var mess = disp+', I have removed you from my Buddy List. Sorry.';
add.href = '/index.cgi?action=pmsend&to='+user+'&subject='+pb_displayname+'{'+pb_username+'}RMB&message='+mess;
}
font.appendChild(add);
members[m].parentNode.parentNode.appendChild(document.createElement('br'));
members[m].parentNode.parentNode.appendChild(font);
}
}}}
// Add buddy drop-down to PM page...
if(pb_action == 'pmsend' && document.postForm && localStorage[checklist])
{
function addBudds(bud)
{
if(document.postForm.to.value != '')
{
document.postForm.to.value += ', ';
}
document.postForm.to.value += bud;
return;
}
document.postForm.to.nextSibling.nextSibling.innerHTML = '(Separate multiple recipients with a comma.)';
buddyCell = document.postForm.to.parentNode;
var buddies = localStorage[checklist].split('};');
buddies.length = buddies.length-1;
buddies = buddies.sort();
var usernames = new Array();
var displaynames = new Array();
for(b=0; b<buddies.length; b++)
{
usernames[b] = buddies[b].split('{')[1];
displaynames[b] = buddies[b].split('{')[0];
}
var buddydrop = document.createElement('font');
var buddyContent = ' <select onChange="addBudds(this.options[this.selectedIndex].value);this.selectedIndex=0;">';
var opt = document.createElement('option');
with(opt){innerHTML = 'Buddies'; value = ''; selected = '1';}
buddydrop.appendChild(opt);
var opt = document.createElement('option');
opt.innerHTML = 'PM All';
for(b=0; b<buddies.length; b++)
{
if(b>0)
{
opt.value += ', '+usernames[b];
}
else
{
opt.value = usernames[b];
}}
buddydrop.appendChild(opt);
for(b=0; b<buddies.length; b++)
{
var opt = document.createElement('option');
with(opt){innerHTML = displaynames[b]; value = usernames[b];}
buddydrop.appendChild(opt);
}
buddydrop.innerHTML = buddyContent+buddydrop.innerHTML+'</select>';
buddyCell.insertBefore(buddydrop,document.postForm.to.nextSibling);
}
// -->
</script>