Tweak dice code further. #1218

Also use `data` instead of `textContent` as it performs faster.
This commit is contained in:
Mayhem 2013-08-08 17:24:46 +02:00
parent 8c95fe1995
commit 2cbf3d909d

View File

@ -5,12 +5,7 @@ Dice =
name: 'Show Dice Roll'
cb: @node
node: ->
return if @isClone or not dicestats = @info.email?.match /dice\+(\d+)d(\d+)/
return if @isClone or not dicestats = @info.email?.match /dice[+\s](\d+)d(\d+)/
# Use the text node directly, as the <b> has two <br>.
roll = $('b', @nodes.comment).firstChild
# Stop here if it looks like this:
# Rolled 44
# and not this:
# Rolled 9, 8, 10, 3, 5 = 35
return unless rollResults = roll.textContent.match /^Rolled (\d+)$/
roll.textContent = "Rolled #{dicestats[1]}d#{dicestats[2]} and got #{rollResults[1]}"
roll.data = "Rolled #{dicestats[1]}d#{dicestats[2]} and got #{roll.data.slice 7}"