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].style.background = "url(" + dice_images[rand ( diceroll[i].firstChild.nodeValue )] + ")"; diceroll[i].style.width=33px; diceroll[i].style.height=33px; } } 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); // Store some random image URLs

var dice_images = new Array ; dice_images[1] = "http://images4.wikia.nocookie.net/scratchpad/images/e/e9/Dice1.gif"; dice_images[2] = "http://images1.wikia.nocookie.net/scratchpad/images/1/1a/Dice2.gif"; dice_images[3] = "http://images1.wikia.nocookie.net/scratchpad/images/f/fb/Dice3.gif"; dice_images[4] = "http://images3.wikia.nocookie.net/scratchpad/images/f/f5/Dice4.gif"; dice_images[5] = "http://images4.wikia.nocookie.net/scratchpad/images/6/6e/Dice5.gif"; dice_images[6] = "http://images1.wikia.nocookie.net/scratchpad/images/2/24/Dice6.gif";