From a596691f77c4ed66d9835e73736e8cd99ba747a3 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sun, 27 Mar 2016 22:21:30 -0700 Subject: [PATCH 01/10] Upvotes. --- src/General/Config.coffee | 4 +++ src/General/Main.coffee | 1 + src/Quotelinks/Upvotes.coffee | 49 +++++++++++++++++++++++++++++++++++ src/css/style.css | 5 ++++ 4 files changed, 59 insertions(+) create mode 100644 src/Quotelinks/Upvotes.coffee diff --git a/src/General/Config.coffee b/src/General/Config.coffee index fa8f09aa6..c20d3f558 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -576,6 +576,10 @@ Config = false 'Thread conversations' ] + 'Upvotes': [ + true + 'Upvote posts.' + ] imageExpansion: 'Fit width': [ diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 7c891c09a..fe171ac48 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -410,6 +410,7 @@ Main = ['Edit Link', QR.oekaki.menu] ['Download Link', DownloadLink] ['Archive Link', ArchiveLink] + ['Upvotes', Upvotes] ['Quote Inlining', QuoteInline] ['Quote Previewing', QuotePreview] ['Quote Backlinks', QuoteBacklink] diff --git a/src/Quotelinks/Upvotes.coffee b/src/Quotelinks/Upvotes.coffee new file mode 100644 index 000000000..fa5120698 --- /dev/null +++ b/src/Quotelinks/Upvotes.coffee @@ -0,0 +1,49 @@ +Upvotes = + text: '\u305D\u3046\u3060\u306D' + count: {} + + init: -> + return unless g.VIEW is 'thread' and Conf['Upvotes'] + Post.callbacks.push + name: 'Upvotes' + cb: @node + + node: -> + return if @isFetchedQuote or @origin?.isFetchedQuote + + if @isClone + @nodes.vote = $ '.upvote', @nodes.info + $.on @nodes.vote, 'click', Upvotes.vote + return + + a = $.el 'a', + className: 'upvote' + href: 'javascript:;' + textContent: '+' + $.add @nodes.info, a + @nodes.vote = a + $.on a, 'click', Upvotes.vote + + Upvotes.count[@fullID] = 0 + + if @quotes.length is 1 and @info.comment.indexOf(Upvotes.text) >= 0 + Upvotes.increment @quotes[0] + + increment: (fullID) -> + return unless fullID of Upvotes.count + count = ++Upvotes.count[fullID] + post = g.posts[fullID] + for post in [post, post.clones...] + post.nodes.vote.textContent = "#{Upvotes.text}x#{count}" + return + + vote: -> + return unless QR.postingIsEnabled + QR.quote.call @ + {com} = QR.nodes + text = "#{Upvotes.text}\n" + pos = com.selectionStart + com.value = com.value[..pos] + text + com.value[pos...] + pos += text.length + com.setSelectionRange pos, pos + $.event 'input', null, com diff --git a/src/css/style.css b/src/css/style.css index 915086aa3..d89fdd9df 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -2084,3 +2084,8 @@ grunt.file.expand('src/Linkification/icons/*.png').map(function(file) { :root.gallery-open.fixed #header-bar:not(.autohide) #shortcuts .fa::before { visibility: hidden; } + +/* Upvotes */ +.upvote { + margin: 0 4px; +} From 67b134c20f3329334f8583148e85b9c0847a3aa4 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Mon, 28 Mar 2016 01:55:33 -0700 Subject: [PATCH 02/10] Identify context of upvote when quoting multiple posts. --- src/Quotelinks/Upvotes.coffee | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Quotelinks/Upvotes.coffee b/src/Quotelinks/Upvotes.coffee index fa5120698..5f0d2307c 100644 --- a/src/Quotelinks/Upvotes.coffee +++ b/src/Quotelinks/Upvotes.coffee @@ -4,6 +4,7 @@ Upvotes = init: -> return unless g.VIEW is 'thread' and Conf['Upvotes'] + @regexp = new RegExp "(?:^>.*\\n)+\\s*#{@text}", 'gm' Post.callbacks.push name: 'Upvotes' cb: @node @@ -26,8 +27,12 @@ Upvotes = Upvotes.count[@fullID] = 0 - if @quotes.length is 1 and @info.comment.indexOf(Upvotes.text) >= 0 - Upvotes.increment @quotes[0] + quotes = {} + for context in @info.comment.match(Upvotes.regexp) or [] + for quote in context.match(/>>\d+/g) or [] + quotes[quote[2..]] = true + for quote of quotes + Upvotes.increment "#{g.BOARD}.#{quote}" increment: (fullID) -> return unless fullID of Upvotes.count From 8f3879c9bd5d1cfc57fd5283fc961097c20c8a32 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Mon, 28 Mar 2016 02:16:23 -0700 Subject: [PATCH 03/10] ASCII-compatible upvotes. --- src/Quotelinks/Upvotes.coffee | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Quotelinks/Upvotes.coffee b/src/Quotelinks/Upvotes.coffee index 5f0d2307c..433c8454b 100644 --- a/src/Quotelinks/Upvotes.coffee +++ b/src/Quotelinks/Upvotes.coffee @@ -1,10 +1,11 @@ Upvotes = - text: '\u305D\u3046\u3060\u306D' count: {} + text: '\u305D\u3046\u3060\u306D' + regexp: /(?:^>.*\n)+\s*(?:\u305D\u3046\u3060\u306D|this)/gmi init: -> return unless g.VIEW is 'thread' and Conf['Upvotes'] - @regexp = new RegExp "(?:^>.*\\n)+\\s*#{@text}", 'gm' + @textPosted = if g.BOARD.ID is 'r9k' then 'This.' else @text Post.callbacks.push name: 'Upvotes' cb: @node @@ -46,7 +47,7 @@ Upvotes = return unless QR.postingIsEnabled QR.quote.call @ {com} = QR.nodes - text = "#{Upvotes.text}\n" + text = "#{Upvotes.textPosted}\n" pos = com.selectionStart com.value = com.value[..pos] + text + com.value[pos...] pos += text.length From 4ba66d7833ee6abf41acc722268c5e19c48e95df Mon Sep 17 00:00:00 2001 From: ccd0 Date: Mon, 28 Mar 2016 02:22:18 -0700 Subject: [PATCH 04/10] Allow upvoting from index even though we can't tally from there. --- src/Quotelinks/Upvotes.coffee | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Quotelinks/Upvotes.coffee b/src/Quotelinks/Upvotes.coffee index 433c8454b..18f8edc15 100644 --- a/src/Quotelinks/Upvotes.coffee +++ b/src/Quotelinks/Upvotes.coffee @@ -4,7 +4,7 @@ Upvotes = regexp: /(?:^>.*\n)+\s*(?:\u305D\u3046\u3060\u306D|this)/gmi init: -> - return unless g.VIEW is 'thread' and Conf['Upvotes'] + return unless g.VIEW in ['thread', 'index'] and Conf['Upvotes'] @textPosted = if g.BOARD.ID is 'r9k' then 'This.' else @text Post.callbacks.push name: 'Upvotes' @@ -26,6 +26,8 @@ Upvotes = @nodes.vote = a $.on a, 'click', Upvotes.vote + return unless g.VIEW is 'thread' + Upvotes.count[@fullID] = 0 quotes = {} From 34ca89613d780c8815b39e638e4b016ec4fc2ec2 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Mon, 28 Mar 2016 03:42:29 -0700 Subject: [PATCH 05/10] Fix 'this' false positives, add more alternatives. --- src/Quotelinks/Upvotes.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Quotelinks/Upvotes.coffee b/src/Quotelinks/Upvotes.coffee index 18f8edc15..893847c31 100644 --- a/src/Quotelinks/Upvotes.coffee +++ b/src/Quotelinks/Upvotes.coffee @@ -1,7 +1,7 @@ Upvotes = count: {} text: '\u305D\u3046\u3060\u306D' - regexp: /(?:^>.*\n)+\s*(?:\u305D\u3046\u3060\u306D|this)/gmi + regexp: /(?:^>.*\n)+\s*(?:\u305D\u3046\u3060\u306D|(?:this(?!\ )|\+1|upvote(?!\ )d?|under[\ -]?rated|\/thread)\b)/gmi init: -> return unless g.VIEW in ['thread', 'index'] and Conf['Upvotes'] From f8209a7bf42a899f8f465222a02099059b4d4e48 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Mon, 28 Mar 2016 19:12:23 -0700 Subject: [PATCH 06/10] Fix spacing between menu and upvote buttons without messing up spacing in Oneechan (menu button moved). --- src/css/style.css | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/css/style.css b/src/css/style.css index d89fdd9df..a4afebec7 100644 --- a/src/css/style.css +++ b/src/css/style.css @@ -2089,3 +2089,6 @@ grunt.file.expand('src/Linkification/icons/*.png').map(function(file) { .upvote { margin: 0 4px; } +.post .menu-button:not(:last-of-type) { + margin-right: -4px; +} From edd6f5477affc057240b8e62bef974713a8d973a Mon Sep 17 00:00:00 2001 From: ccd0 Date: Tue, 29 Mar 2016 01:34:00 -0700 Subject: [PATCH 07/10] More upvotes and make regexp more readable. --- src/Quotelinks/Upvotes.coffee | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Quotelinks/Upvotes.coffee b/src/Quotelinks/Upvotes.coffee index 893847c31..b8ad15a1a 100644 --- a/src/Quotelinks/Upvotes.coffee +++ b/src/Quotelinks/Upvotes.coffee @@ -1,7 +1,25 @@ Upvotes = count: {} text: '\u305D\u3046\u3060\u306D' - regexp: /(?:^>.*\n)+\s*(?:\u305D\u3046\u3060\u306D|(?:this(?!\ )|\+1|upvote(?!\ )d?|under[\ -]?rated|\/thread)\b)/gmi + regexp: /// + (?:^>.*\n)+\s* + (?: + \u305D\u3046\u3060\u306D + | + (?: + this(?!\ ) + |\+1 + |upvote(?!\ )d? + |under[\ -]?rated + |\/thread + |10\/10 + |(?:i\ |top\ )*(?:lol|kek)(?:'?d|\.?$) + |(?:fukken\ |fucking\ )?saved + |nice(?!\ ) + ) + \b + ) + ///gmi init: -> return unless g.VIEW in ['thread', 'index'] and Conf['Upvotes'] From 534b6f1da2b4a9fb5e008095e0ecddc440c858ab Mon Sep 17 00:00:00 2001 From: ccd0 Date: Tue, 29 Mar 2016 02:41:40 -0700 Subject: [PATCH 08/10] Upvote regexp bugfix. --- src/Quotelinks/Upvotes.coffee | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/Quotelinks/Upvotes.coffee b/src/Quotelinks/Upvotes.coffee index b8ad15a1a..d571a6d02 100644 --- a/src/Quotelinks/Upvotes.coffee +++ b/src/Quotelinks/Upvotes.coffee @@ -5,20 +5,17 @@ Upvotes = (?:^>.*\n)+\s* (?: \u305D\u3046\u3060\u306D - | - (?: - this(?!\ ) - |\+1 - |upvote(?!\ )d? - |under[\ -]?rated - |\/thread - |10\/10 - |(?:i\ |top\ )*(?:lol|kek)(?:'?d|\.?$) - |(?:fukken\ |fucking\ )?saved - |nice(?!\ ) - ) - \b + |this(?!\ ) + |\+1 + |upvote(?!\ )d? + |under[\ -]?rated + |\/thread + |10\/10 + |(?:i\ |top\ )*(?:lol|kek)(?:'?d|\.?$) + |(?:fukken\ |fucking\ )?saved + |nice(?!\ ) ) + (?=\b|\W|$) ///gmi init: -> From 8bc1b41af4b12af425502193443c8c4c42d3f9b0 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Tue, 29 Mar 2016 18:38:42 -0700 Subject: [PATCH 09/10] More upvote regexp improvements. --- src/Quotelinks/Upvotes.coffee | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/Quotelinks/Upvotes.coffee b/src/Quotelinks/Upvotes.coffee index d571a6d02..64f073fc1 100644 --- a/src/Quotelinks/Upvotes.coffee +++ b/src/Quotelinks/Upvotes.coffee @@ -2,7 +2,24 @@ Upvotes = count: {} text: '\u305D\u3046\u3060\u306D' regexp: /// - (?:^>.*\n)+\s* + (?:^>.*\n)+ + (?: + i + |top + |holy + |shit + |ay* + |oh? + |omg + |god + |jesus + |christ + |fuck + |fukken + |fucking? + |\s + |[.,-] + )* (?: \u305D\u3046\u3060\u306D |this(?!\ ) @@ -11,9 +28,10 @@ Upvotes = |under[\ -]?rated |\/thread |10\/10 - |(?:i\ |top\ )*(?:lol|kek)(?:'?d|\.?$) - |(?:fukken\ |fucking\ )?saved + |(?:lol|kek|lel|lmao|(?:ha)+)(?:'?d|[.!]?$) + |saved |nice(?!\ ) + |my\ sides ) (?=\b|\W|$) ///gmi From b4b6cf35669626e2557ca007fa3f57bcc95e1801 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Tue, 29 Mar 2016 18:54:23 -0700 Subject: [PATCH 10/10] "I had" --- src/Quotelinks/Upvotes.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Quotelinks/Upvotes.coffee b/src/Quotelinks/Upvotes.coffee index 64f073fc1..8315a5191 100644 --- a/src/Quotelinks/Upvotes.coffee +++ b/src/Quotelinks/Upvotes.coffee @@ -28,7 +28,8 @@ Upvotes = |under[\ -]?rated |\/thread |10\/10 - |(?:lol|kek|lel|lmao|(?:ha)+)(?:'?d|[.!]?$) + |(?:lol|kek|lel|lmao)(?:'?d|[.!]?$) + |(?:ha)+[.!]?$ |saved |nice(?!\ ) |my\ sides