From bcbae6c84f7131e42bdcc6109621159254292d7a Mon Sep 17 00:00:00 2001 From: carboncopy Date: Fri, 19 Jul 2013 23:18:11 -0500 Subject: [PATCH 1/6] display rolled dice while on /tg/ --- src/General/Config.coffee | 1 + src/General/Main.coffee | 1 + src/Miscellaneous/Dice.coffee | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 src/Miscellaneous/Dice.coffee diff --git a/src/General/Config.coffee b/src/General/Config.coffee index f7a1e24e4..2badf110b 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -13,6 +13,7 @@ Config = 'Index Navigation': [false, 'Add buttons to navigate between threads.'] 'Reply Navigation': [false, 'Add buttons to navigate to top / bottom of thread.'] '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 a1dd45ae4..044796280 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -114,6 +114,7 @@ Main = initFeature 'Thread Watcher', ThreadWatcher initFeature 'Index Navigation', Nav initFeature 'Keybinds', Keybinds + initFeature 'Dice Checker', Dice # c.timeEnd 'All initializations' $.on d, 'AddCallback', Main.addCallback diff --git a/src/Miscellaneous/Dice.coffee b/src/Miscellaneous/Dice.coffee new file mode 100644 index 000000000..1614a6ca9 --- /dev/null +++ b/src/Miscellaneous/Dice.coffee @@ -0,0 +1,20 @@ +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' + Post::callbacks.push + name: 'Dice roller' + 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 + + From 5eabd9ce0d5f44a3ff6bba4778931a921c0fe8f2 Mon Sep 17 00:00:00 2001 From: carboncopy Date: Wed, 7 Aug 2013 15:55:57 -0500 Subject: [PATCH 2/6] updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 793177903..04a47aa59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ +- Added dice monitoring on /tg/ - Fix impossibility to create new threads when in dead threads. ### 3.5.7 - *2013-07-13* From 8c95fe1995899b7dd6c63502113149b908143cc9 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Thu, 8 Aug 2013 11:25:03 +0200 Subject: [PATCH 3/6] 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]}" From 2cbf3d909d251755924f43dcea4a44a580fc9f26 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Thu, 8 Aug 2013 17:24:46 +0200 Subject: [PATCH 4/6] Tweak dice code further. #1218 Also use `data` instead of `textContent` as it performs faster. --- src/Miscellaneous/Dice.coffee | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Miscellaneous/Dice.coffee b/src/Miscellaneous/Dice.coffee index 67559eca4..93bdb06cd 100644 --- a/src/Miscellaneous/Dice.coffee +++ b/src/Miscellaneous/Dice.coffee @@ -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 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]}" + roll.data = "Rolled #{dicestats[1]}d#{dicestats[2]} and got #{roll.data.slice 7}" From 0b55e34361c9126358c1b70ad0adbc945434deeb Mon Sep 17 00:00:00 2001 From: Mayhem Date: Fri, 9 Aug 2013 12:41:59 +0200 Subject: [PATCH 5/6] Allow fetching posts for archives that require credentials. --- json/archives.json | 1 + lib/$.coffee | 16 ++++++++-------- src/Archive/Redirect.coffee | 4 +++- src/General/Get.coffee | 18 ++++++++++++------ 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/json/archives.json b/json/archives.json index 15c52e369..95ac1a37a 100644 --- a/json/archives.json +++ b/json/archives.json @@ -103,6 +103,7 @@ "domain": "beta.foolz.us", "http": true, "https": true, + "withCredentials": true, "software": "foolfuuka", "boards": ["a", "co", "gd", "h", "jp", "m", "mlp", "q", "sp", "tg", "tv", "u", "v", "vg", "vp", "vr", "wsg"], "files": ["a", "gd", "h", "jp", "m", "q", "tg", "u", "vg", "vp", "vr", "wsg"] diff --git a/lib/$.coffee b/lib/$.coffee index 306eba722..7e25bb5f2 100644 --- a/lib/$.coffee +++ b/lib/$.coffee @@ -49,7 +49,7 @@ $.ajax = (url, options, extra={}) -> r $.cache = do -> reqs = {} - (url, cb) -> + (url, cb, options) -> if req = reqs[url] if req.readyState is 4 cb.call req, req.evt @@ -57,13 +57,13 @@ $.cache = do -> req.callbacks.push cb return rm = -> delete reqs[url] - req = $.ajax url, - onload: (e) -> - cb.call @, e for cb in @callbacks - @evt = e - delete @callbacks - onabort: rm - onerror: rm + req = $.ajax url, options + $.on req, 'load', (e) -> + cb.call @, e for cb in @callbacks + @evt = e + delete @callbacks + $.on req, 'abort', rm + $.on req, 'error', rm req.callbacks = [cb] reqs[url] = req $.cb = diff --git a/src/Archive/Redirect.coffee b/src/Archive/Redirect.coffee index edc4e621c..1da3f9f8a 100644 --- a/src/Archive/Redirect.coffee +++ b/src/Archive/Redirect.coffee @@ -74,7 +74,9 @@ Redirect = # Remove necessary HTTPS procotol in September 2013. if archive.name in ['Foolz', 'NSFW Foolz'] protocol = 'https://' - "#{protocol}#{archive.domain}/_/api/chan/post/?board=#{boardID}&num=#{postID}" + URL = new String "#{protocol}#{archive.domain}/_/api/chan/post/?board=#{boardID}&num=#{postID}" + URL.archive = archive + URL file: (archive, {boardID, filename}) -> "#{Redirect.protocol archive}#{archive.domain}/#{boardID}/full_image/#{filename}" diff --git a/src/General/Get.coffee b/src/General/Get.coffee index 5e9cfbbcf..fe2a056b0 100644 --- a/src/General/Get.coffee +++ b/src/General/Get.coffee @@ -71,8 +71,10 @@ Get = $.cache "//api.4chan.org/#{boardID}/res/#{threadID}.json", -> Get.fetchedPost @, boardID, threadID, postID, root, context else if url = Redirect.to 'post', {boardID, postID} - $.cache url, -> - Get.archivedPost @, boardID, postID, root, context + $.cache url, + -> Get.archivedPost @, boardID, postID, root, context + , + withCredentials: url.archive.withCredentials insert: (post, root, context) -> # Stop here if the container has been removed while loading. return unless root.parentNode @@ -97,8 +99,10 @@ Get = if status not in [200, 304] # The thread can die by the time we check a quote. if url = Redirect.to 'post', {boardID, postID} - $.cache url, -> - Get.archivedPost @, boardID, postID, root, context + $.cache url, + -> Get.archivedPost @, boardID, postID, root, context + , + withCredentials: url.archive.withCredentials else $.addClass root, 'warning' root.textContent = @@ -115,8 +119,10 @@ Get = if post.no > postID # The post can be deleted by the time we check a quote. if url = Redirect.to 'post', {boardID, postID} - $.cache url, -> - Get.archivedPost @, boardID, postID, root, context + $.cache url, + -> Get.archivedPost @, boardID, postID, root, context + , + withCredentials: url.archive.withCredentials else $.addClass root, 'warning' root.textContent = "Post No.#{postID} was not found." From 6f6c1be3b168c167072bed0a3ce9af9270c45919 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Fri, 9 Aug 2013 18:44:22 +0200 Subject: [PATCH 6/6] Fix #1219. --- src/Miscellaneous/Time.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Miscellaneous/Time.coffee b/src/Miscellaneous/Time.coffee index 1f57d19d1..0f054283a 100644 --- a/src/Miscellaneous/Time.coffee +++ b/src/Miscellaneous/Time.coffee @@ -56,4 +56,4 @@ Time = p: -> if @getHours() < 12 then 'AM' else 'PM' P: -> if @getHours() < 12 then 'am' else 'pm' S: -> Time.zeroPad @getSeconds() - y: -> @getFullYear() - 2000 + y: -> @getFullYear().toString()[2..]