From 8c95fe1995899b7dd6c63502113149b908143cc9 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Thu, 8 Aug 2013 11:25:03 +0200 Subject: [PATCH] Tweak Dice code. #1218 --- CHANGELOG.md | 3 ++- src/General/Config.coffee | 2 +- src/General/Main.coffee | 2 +- src/Miscellaneous/Dice.coffee | 28 ++++++++++++---------------- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04a47aa59..353dce5e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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* diff --git a/src/General/Config.coffee b/src/General/Config.coffee index 2badf110b..7cbc64d18 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -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.'] diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 044796280..92a543676 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -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 diff --git a/src/Miscellaneous/Dice.coffee b/src/Miscellaneous/Dice.coffee index 1614a6ca9..67559eca4 100644 --- a/src/Miscellaneous/Dice.coffee +++ b/src/Miscellaneous/Dice.coffee @@ -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 has two
. + 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]}"