User:A morris/global.js

// ************************************************** // Experimental javascript dice roller (A_morris) // Version 0.0.1 // ************************************************** // // Usage example: // //  6  //  Javascript disabled.

function rand ( n ) { return ( Math.floor ( Math.random  * n + 1 ) ); }

function calculateroll{ for(var i in diceroll) diceroll[i].firstChild.nodeValue = rand ( diceroll[i].firstChild.nodeValue ); } function checkdiceroller { //hide 'nodiceroller' and show 'diceroller' var nodiceroller = getElementsByClassName(document, 'span', 'nodiceroller'); for(var i in nodiceroller) nodiceroller[i].style.display = 'none' var diceroller = getElementsByClassName(document, 'span', 'diceroller'); for(var i in diceroller) diceroller[i].style.display = 'inline'

//set up global objects diceroll. diceroll = getElementsByClassName(document, 'span', 'diceroll'); //global if(diceroll.length == 0) return; calculateroll; } addOnloadHook(checkdiceroller);