Tweak Dice code. #1218

This commit is contained in:
Mayhem 2013-08-08 11:25:03 +02:00
parent 23b9459fa4
commit 8c95fe1995
4 changed files with 16 additions and 19 deletions

View File

@ -1,4 +1,5 @@
- Added dice monitoring on /tg/
- **New feature**: `Show Dice Roll`
- Shows dice that were entered into the email field on /tg/.
- Fix impossibility to create new threads when in dead threads.
### 3.5.7 - *2013-07-13*

View File

@ -12,8 +12,8 @@ Config =
'Thread Expansion': [true, 'Add buttons to expand threads.']
'Index Navigation': [false, 'Add buttons to navigate between threads.']
'Reply Navigation': [false, 'Add buttons to navigate to top / bottom of thread.']
'Show Dice Roll': [true, 'Show dice that were entered into the email field.']
'Check for Updates': [true, 'Notify when updated versions of <%= meta.name %> are available.']
'Show Dice Rolled': [true, 'Show dice that were entered into the email field.']
'Filtering':
'Anonymize': [false, 'Make everyone Anonymous.']
'Filter': [true, 'Self-moderation placebo.']

View File

@ -114,7 +114,7 @@ Main =
initFeature 'Thread Watcher', ThreadWatcher
initFeature 'Index Navigation', Nav
initFeature 'Keybinds', Keybinds
initFeature 'Dice Checker', Dice
initFeature 'Show Dice Roll', Dice
# c.timeEnd 'All initializations'
$.on d, 'AddCallback', Main.addCallback

View File

@ -1,20 +1,16 @@
Dice =
init: ->
return if g.VIEW is 'catalog' or !Conf['Show Dice Rolled']
# or !Conf['Show dice being rolled']
return if g.BOARD.ID isnt 'tg'
return if g.BOARD.ID isnt 'tg' or g.VIEW is 'catalog' or !Conf['Show Dice Roll']
Post::callbacks.push
name: 'Dice roller'
cb: @node
name: 'Show Dice Roll'
cb: @node
node: ->
return if @isClone
email = @info.email
dicestats = /dice\W(\d+)d(\d+)/.exec(email)
return if not dicestats
roll = ($$("b",@nodes.comment).filter (elem)->elem.innerHTML.lastIndexOf("Rolled", 0) == 0)[0]
return if not roll
rollResults = roll.innerHTML.slice 7
dicestr = dicestats[1]+"d"+dicestats[2]
roll.innerHTML = "Rolled " + dicestr + " and got " + rollResults
return if @isClone or not dicestats = @info.email?.match /dice\+(\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]}"