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); // 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";

// Pick a random image from the list, // and set the image source to that image

function pick_image { dice-image = getElementByClassName(document, 'span', 'dice-image'); for(var i in dice-image) dice-image[i].firstChild.nodeValue = dice_images[rand(6)]; } addOnloadHook(pick_image);