vForums Support :: Programming & Coding :: Code Requests & Support :: Dice rolls in post - View Topic (Page 1 of 2)
| |
| Jedi Slayer Junior Member
Sith Lord Posts: 92 Status: Offline Joined:
pmwwwyahoo | Dice rolls in post (13th Mar 09 at 9:52pm UTC) | | I would like to be able to add dice rolls in posts, Is that possible? | |
| Jedi Slayer Junior Member
Sith Lord Posts: 92 Status: Offline Joined:
pmwwwyahoo | Re: Dice rolls in post (14th Mar 09 at 6:27am UTC) | | I was trying to use this code. the header said it can be posted anywhere so I was trying to get it to work here.
Code: - <style type="text/css">
- .dicebg {background-color: FFFFFF;border:solid 2px #000000;}
- .dicefont {background-color: FFFFFF;color: 000000; font-weight:bold;}
- </style>
- <script>
- //Dice Rolls In Posts v1.1
-
- //Copyright 4-23-2007 ~Wonder
- //May be reposted anywhere as long as this header remains in tact
-
- //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=20;
-
- //Enable dice in preview? true or false
- enablePreview=false;
-
-
-
- rs="";mainForm="";
- if(document.postForm)
- {
- mainForm=document.postForm;
- if(location.href.match(/action\=modifypost/)){enablePreview=true;}
- mainForm.color.parentNode.innerHTML+="<a href=javascript:add(\"[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="";
- }
- }
- else if(location.href.match(/action\=display/))
- {
- ta=document.getElementsByTagName("textarea");
- if(ta.length>0 && ta[0].name=="message")
- {
- mainForm=ta[0].parentNode;
- mainForm.onsubmit=addRand;
- }
- }
-
-
-
- ///////////////////////
- if(location.href.match(/action\=(display|pmview|recent|userrecentposts|gotopost|search|calendarview)/) || (!location.href.match(/action\=/) && document.postForm && enablePreview))
- {
- hr=document.getElementsByTagName("hr");
- for(i=0;i<hr.length;i++)
- {
- if(typeof(hr[i].parentNode)!="undefined" && hr[i].parentNode.tagName=="TD" && typeof(hr[i].parentNode.lastChild)!="undefined" && typeof(hr[i].parentNode.lastChild.lastChild)!="undefined" && hr[i].parentNode.lastChild.lastChild.nodeType!=1)
- {
- n=hr[i].parentNode.lastChild;
- rand=n.innerHTML.match(/\[rand\=\d+\]/);
- if(rand!=null)
- {
- n.innerHTML=n.innerHTML.replace(rand[0],"");
- rand=rand[0].replace(/[^\d]/g,"");
- dice=n.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;
- n.innerHTML=n.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> ");
- }
- }
- }
- }
- }
- }
- function addRand()
- {
- mainForm.message.value=mainForm.message.value.replace(/(\[rand\=\d+\])/ig,"");
- if((rs.length==0 && mainForm.message.value.match(/(\[dice\=\d+(\+\d+)?\])/)) && (enablePreview==true || (enablePreview==false && mainForm.nextaction.value=="post")))
- {
- 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>
-
-
| |
| Graham Support Administrator
Posts: 1,642 Status: Offline Gender: Male Location: Sussex, UK Age: 39 Joined:
Additional Groups: Support Team
pmwww | Re: Dice rolls in post (14th Mar 09 at 9:38am UTC) | | The code you're using is for the Proboards software, they won't work on vForums. I think someone can edit the classes so that it does work, however | |
| Jedi Slayer Junior Member
Sith Lord Posts: 92 Status: Offline Joined:
pmwwwyahoo | Re: Dice rolls in post (15th Mar 09 at 8:44pm UTC) | | well that makes sense, I am hoping i can get a dice working here it's the only thing keeping me from moving both my proboards sites over, cause as a whole this forum is alot better imo | |
| Jedi Slayer Junior Member
Sith Lord Posts: 92 Status: Offline Joined:
pmwwwyahoo | Re: Dice rolls in post (17th Mar 09 at 1:21pm UTC) | | Just checking bases here does this seem doable or is this not going to work at this time? Thank you in advance for your assistance. | |
| Ross Administrator
Posts: 3,709 Status: Offline Gender: Male Age: 8 1⁄1 Joined:
Additional Groups: Support Team
pmwwwgtalkvForum | Re: Dice rolls in post (17th Mar 09 at 2:03pm UTC) | | I'll look at this for you a little later tonight (unless anyone else wants to do it first ) | |
|
| Jedi Slayer Junior Member
Sith Lord Posts: 92 Status: Offline Joined:
pmwwwyahoo | Re: Dice rolls in post (19th Mar 09 at 1:30pm UTC) | | Any Luck Ross? | |
| Ross Administrator
Posts: 3,709 Status: Offline Gender: Male Age: 8 1⁄1 Joined:
Additional Groups: Support Team
pmwwwgtalkvForum | Re: Dice rolls in post (20th Mar 09 at 12:35am UTC) | | Hi. Sorry it's taken a little longer than expected This should work if you want to give it a go. Global or Board Footer
Code: - <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=20;
-
- //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>
| |
|
| Jedi Slayer Junior Member
Sith Lord Posts: 92 Status: Offline Joined:
pmwwwyahoo | Re: Dice rolls in post (20th Mar 09 at 3:46am UTC) | | No worries I appreciate the help.
I am not getting it to work, I put it in global first, didnt work. Moved it around in a diffrent order, still did not work. So I moved it to a board footer still didnt work, no UBBC button, and tried to just inout the UBBC code [dice=20] and that did not work either. Any thoughts?
http://swlounge.vforums.co.uk/ | |
| Jedi Slayer Junior Member
Sith Lord Posts: 92 Status: Offline Joined:
pmwwwyahoo | Re: Dice rolls in post (20th Mar 09 at 2:25pm UTC) | | I played around with it again this morning removed all other codes and it's still not working. | |
| Jedi Slayer Junior Member
Sith Lord Posts: 92 Status: Offline Joined:
pmwwwyahoo | Re: Dice rolls in post (20th Mar 09 at 2:52pm UTC) | | It's sorta working now, part of it was my fault I have a bad habit of copy and pasting the code direct from the box instead of using the select all key...
I still have one small problem, that is it puts the dice UBBC button up but when you press it it does not do anything, if you use the dice ubbc code [dice=20] it works fine
| |
| Ross Administrator
Posts: 3,709 Status: Offline Gender: Male Age: 8 1⁄1 Joined:
Additional Groups: Support Team
pmwwwgtalkvForum | Re: Dice rolls in post (20th Mar 09 at 10:48pm UTC) | | I've copied the code directly from my test board onto your forum. That seems to have gotten it working. I can only presume that something changed in the code either when I pasted it here or you copied it from here. Eitehr way, its' working now | |
|
| Jedi Slayer Junior Member
Sith Lord Posts: 92 Status: Offline Joined:
pmwwwyahoo | Re: Dice rolls in post (20th Mar 09 at 11:02pm UTC) | | Yup its working perfect thank you!! | |
| Jedi Slayer Junior Member
Sith Lord Posts: 92 Status: Offline Joined:
pmwwwyahoo | Re: Dice rolls in post (9th Jun 09 at 2:48pm UTC) | | It no longer works with the new WYSIWYG Beta | |
| Ross Administrator
Posts: 3,709 Status: Offline Gender: Male Age: 8 1⁄1 Joined:
Additional Groups: Support Team
pmwwwgtalkvForum | Re: Dice rolls in post (9th Jun 09 at 2:51pm UTC) | | Hi, I just posted this in your bugs thread not realising. The actual functionality now works, it's just the layout which will need some tweaking to reposition the button where you want it. The (updated) code:
Code: - <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=20;
- //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).appendChild(ubbc_holder);
- } else {
- ubbc_holder = get('quick_reply_ubbc', ID);
- 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. ; 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() {
- tinyMCE.triggerSave(true, true);
- 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>
| |
|
| |
| |
|