vForums Support > Programming & Coding :: Code Requests & Support :: > Dice Rolls In Posts Code Fix Needed.
Dice Rolls In Posts Code Fix Needed. - Posted By ManGoneMad (mgm) on 6th Jul 09 at 6:45pm
With the up-grade to v2 this code has stopped working, any chance of a quick fix?
<style type="text/css">
.dicebg {background-color: FFFFFF;border:solid 2px #000000;}
.dicefont {background-color: FFFFFF;color: 000000; font-weight:bold;}
</style>
<script type="text/javascript">
//Dice Rolls In Posts v1.1
//Copyright 4-23-2007 ~Wonder
//May be reposted anywhere as long as this header remains in tact
//Modified by Ross of vForums Support for vForums compatibility
//Do you want the dice to line of horizontally(true) or vertically(false)
diceAlignment=true;
//Enter URL of the image you want to appear as the dice ubbc button
UBBCdiceImage="http://img100.imageshack.us/img100/6118/diceicon9rx.gif";
//Enter the default # of sides
defaultSides=6;
//Enable dice in preview? true or false
enablePreview=false;
rs="";
mainForm="";
if(document.post_form || document.quick_reply_form) {
if(document.post_form) {
mainForm=document.post_form;
if(location.href.match(/action\/modify/)){enablePreview=true;}
ubbc_holder = document.createElement('span');
get('ubbc_buttons', ID).firstChild.insertBefore(ubbc_holder, get('ubbc_buttons', ID).firstChild.lastChild);
} else {
ubbc_holder = get('quick_reply_ubbc', ID).firstChild.nextSibling;
mainForm=document.quick_reply_form;
}
ubbc_holder.innerHTML+="<a href=javascript:add_ubbc(\"[dice="+defaultSides+"]\",\"\")><img src=\""+UBBCdiceImage+"\" alt=\"Insert Dice Roll\" border=\"0\"></a>";
mainForm.onsubmit=addRand;
mainForm.message.value=mainForm.message.value.replace(/(\[rand\=\d+\])/ig,"");
rs=RegExp.$1; rs=(/\[rand\=/.test(rs))?rs:"";
if(location.href.match(/quote\/\d+/))
{
mainForm.message.value=mainForm.message.value.replace(/(\[dice\=\d+\])/ig,"");
rs="";
}
}
///////////////////////
if(location.href.match(/action\/(view_topic|search|recent|pm_view|post|modify|create_poll)/)) {
td=document.getElementsByTagName("td");
topic_summary = false;
for(i=0;i<td.length;i++) {
if(td.item(i).className == 'post' || topic_summary) {
// Remove from message preview
if(td.item(i).className == 'post' && location.href.match(/action\/(post|modify|create_poll)/) && !enablePreview) {
td.item(i).innerHTML=td.item(i).innerHTML.replace(/\[rand\=(\d|\w|<|>|\/|\s)+\]/gi,"");
}
rand=td.item(i).innerHTML.match(/\[rand\=(\d|\w|<|>|\/|\s)+\]/);
if(rand!=null)
{
td.item(i).innerHTML=td.item(i).innerHTML.replace(rand[0],"");
rand=rand[0].replace(/[^\d]/g,"");
dice=td.item(i).innerHTML.match(/\[dice\=\d+(\+\d+)?\]/ig);
if(dice!=null)
{
for(k=0;k<dice.length;k++)
{
numb=dice[k].match(/\d+(\+\d+)?/);
numb=numb[0].split("+");
addon=numb.length>1?parseInt(numb[1],10):0;
numb=parseInt(numb[0],10);
roll=Math.round((parseFloat(rand.substring(k,k+2)+"."+rand.substring(k+2,rand.length))/100)*(numb-1))+1+addon;
td.item(i).innerHTML=td.item(i).innerHTML.replace(dice[k],"<table "+(diceAlignment?"style=\"display:inline\"":"")+" border=0 cellpadding=0 cellspacing=0><tr><td><table class=dicebg cellpadding=1 cellspacing=0><tr><td><center><font class=dicefont size=\"+1\"><b>"+roll+"</b><br><font size=\"1\">"+numb+" sides"+(addon>0?"+"+addon:"")+"</font></font></center></td></tr></table></td></tr></table> ");
}
}
}
} else if(td.item(i).className == 'title1' && td.item(i).innerHTML.match(/>Topic Summary</i)) {
topic_summary = true;
}
}
}
function addRand() {
mainForm.message.value=mainForm.message.value.replace(/(\[rand\=\d+\])/ig,"");
if((rs.length==0 && mainForm.message.value.match(/(\[dice\=\d+(\+\d+)?\])/))) {
mainForm.message.value+="[rand="+(Math.random()+"").replace(/0\./,"")+(Math.random()+"").replace(/0\./,"")+(Math.random()+"").replace(/0\./,"")+( Math.random()+"").replace(/0\./,"")+"]";
} else {
mainForm.message.value+=rs;
}
disable(mainForm);
}
</script>
Re: Dice Rolls In Posts Code Fix Needed. - Posted By Michael (wrighty) on 6th Jul 09 at 7:00pm
Try the result in this post: http://support.virtualforums.co.uk/board/coderequest/topic/26133/action/view_topic/dice-rolls-in-post#27536
Re: Dice Rolls In Posts Code Fix Needed. - Posted By ManGoneMad (mgm) on 6th Jul 09 at 7:21pm
Nope no luck with that, Michael.
could it be that it adds an UBBC button, and now in v2, the UBBC is changed?