From 01146f85c502647c2d93967c80972611fbadcf2a Mon Sep 17 00:00:00 2001 From: noface Date: Thu, 22 Aug 2013 23:09:15 +0200 Subject: [PATCH] Close #1255. --- CHANGELOG.md | 2 ++ css/style.css | 9 +++++++ src/General/Config.coffee | 1 + src/General/Main.coffee | 1 + src/Miscellaneous/IDColor.coffee | 40 ++++++++++++++++++++++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 src/Miscellaneous/IDColor.coffee diff --git a/CHANGELOG.md b/CHANGELOG.md index 7fa81c571..c00eff26f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +- **New feature**: `Color user IDs`, enabled by default + ## 3.10.0 - *2013-08-22* - **New feature**: `Linkify` and `Clean Links`, enabled by default diff --git a/css/style.css b/css/style.css index 67c936a26..63ad3c85a 100644 --- a/css/style.css +++ b/css/style.css @@ -959,3 +959,12 @@ a.hide-announcement { .entry input { margin: 0; } + +/* colored uid */ + +.posteruid.painted { + padding: 0 5px; + border-radius: 1em; + font-size: 0.8em; + cursor: pointer; +} diff --git a/src/General/Config.coffee b/src/General/Config.coffee index 24fa40faf..11a94a89c 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -50,6 +50,7 @@ Config = 'Thread Excerpt': [true, 'Show an excerpt of the thread in the tab title.'] 'Thread Stats': [true, 'Display reply, image, and page count.'] 'Thread Watcher': [true, 'Bookmark threads.'] + 'Color user IDs': [true, 'Assign unique colors to user IDs on boards that use them.'] 'Posting': 'Quick Reply': [true, 'All-in-one form to reply, create threads, automate dumping and more.'] 'Persistent QR': [false, 'The Quick reply won\'t disappear after posting.'] diff --git a/src/General/Main.coffee b/src/General/Main.coffee index 23f35d9b5..cb19d8862 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -107,6 +107,7 @@ Main = initFeature 'Mark OP Quotes', QuoteOP initFeature 'Mark Cross-thread Quotes', QuoteCT initFeature 'Anonymize', Anonymize + initFeature 'Color user IDs', IDColor initFeature 'Time Formatting', Time initFeature 'Relative Post Dates', RelativeDates initFeature 'File Info Formatting', FileInfo diff --git a/src/Miscellaneous/IDColor.coffee b/src/Miscellaneous/IDColor.coffee new file mode 100644 index 000000000..800ce9969 --- /dev/null +++ b/src/Miscellaneous/IDColor.coffee @@ -0,0 +1,40 @@ +IDColor = + init: -> + return if g.VIEW is 'catalog' or !Conf['Color user IDs'] + @ids = {} + + Post::callbacks.push + name: 'Color user IDs' + cb: @node + + node: -> + return if @isClone or !(uid = @info.uniqueID) + rgb = IDColor.compute uid + span = @nodes.uniqueID + {style} = span + style.color = rgb[3] + style.backgroundColor = "rgb(#{rgb[0]},#{rgb[1]},#{rgb[2]})" + $.addClass span, 'painted' + span.textContent = uid + span.title = 'Highlight posts by this ID' + + compute: (uniqueID) -> + if uniqueID of IDColor.ids + return IDColor.ids[uniqueID] + hash = @hash uniqueID + rgb = [ + (hash >> 24) & 0xFF + (hash >> 16) & 0xFF + (hash >> 8) & 0xFF + ] + rgb.push if (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114) > 125 + 'black' + else + 'white' + @ids[uniqueID] = rgb + + hash: (uniqueID) -> + msg = 0 + for i in [0...uniqueID.length] + msg = (msg << 5) - msg + uniqueID.charCodeAt i + msg