From 01146f85c502647c2d93967c80972611fbadcf2a Mon Sep 17 00:00:00 2001 From: noface Date: Thu, 22 Aug 2013 23:09:15 +0200 Subject: [PATCH 1/6] 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 From cb498db8df38b7a3602405f7d50b407c6de9e357 Mon Sep 17 00:00:00 2001 From: NoneGiven Date: Thu, 22 Aug 2013 19:38:58 -0400 Subject: [PATCH 2/6] Typo It just werx --- CHANGELOG.md | 2 +- src/General/Config.coffee | 2 +- src/General/Main.coffee | 2 +- src/Miscellaneous/IDColor.coffee | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c00eff26f..47bcd50eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -- **New feature**: `Color user IDs`, enabled by default +- **New feature**: `Color User IDs`, enabled by default ## 3.10.0 - *2013-08-22* diff --git a/src/General/Config.coffee b/src/General/Config.coffee index 11a94a89c..d6a194787 100644 --- a/src/General/Config.coffee +++ b/src/General/Config.coffee @@ -50,7 +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.'] + '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 cb19d8862..eee9be9ae 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -107,7 +107,7 @@ Main = initFeature 'Mark OP Quotes', QuoteOP initFeature 'Mark Cross-thread Quotes', QuoteCT initFeature 'Anonymize', Anonymize - initFeature 'Color user IDs', IDColor + 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 index 800ce9969..25ff81247 100644 --- a/src/Miscellaneous/IDColor.coffee +++ b/src/Miscellaneous/IDColor.coffee @@ -1,10 +1,10 @@ IDColor = init: -> - return if g.VIEW is 'catalog' or !Conf['Color user IDs'] + return if g.VIEW is 'catalog' or !Conf['Color User IDs'] @ids = {} Post::callbacks.push - name: 'Color user IDs' + name: 'Color User IDs' cb: @node node: -> From b394a81494bb4ddf64d77e0b42caf69eaebea870 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Fri, 23 Aug 2013 02:31:23 +0200 Subject: [PATCH 3/6] Adjust the color ID contrast threshold. Totally not arbitrary edition. --- src/Miscellaneous/IDColor.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Miscellaneous/IDColor.coffee b/src/Miscellaneous/IDColor.coffee index 25ff81247..e3ae50715 100644 --- a/src/Miscellaneous/IDColor.coffee +++ b/src/Miscellaneous/IDColor.coffee @@ -27,7 +27,7 @@ IDColor = (hash >> 16) & 0xFF (hash >> 8) & 0xFF ] - rgb.push if (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114) > 125 + rgb.push if (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114) > 170 'black' else 'white' From de82bd3e45950e5aabb1e5f561aec6f9c9c2b9f1 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Fri, 23 Aug 2013 15:34:42 +0200 Subject: [PATCH 4/6] Give CS loops a hand. --- lib/polyfill.coffee | 2 +- src/General/Main.coffee | 2 +- src/General/Post.coffee | 2 +- src/Miscellaneous/IDColor.coffee | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/polyfill.coffee b/lib/polyfill.coffee index cba68a122..0ad7c1fe8 100644 --- a/lib/polyfill.coffee +++ b/lib/polyfill.coffee @@ -22,7 +22,7 @@ Polyfill = # DataUrl to Binary code from Aeosynth's 4chan X repo l = data.length ui8a = new Uint8Array l - for i in [0...l] + for i in [0...l] by 1 ui8a[i] = data.charCodeAt i cb new Blob [ui8a], type: 'image/png' visibility: -> diff --git a/src/General/Main.coffee b/src/General/Main.coffee index eee9be9ae..afcdbe910 100644 --- a/src/General/Main.coffee +++ b/src/General/Main.coffee @@ -220,7 +220,7 @@ Main = len = nodes.length for callback in klass::callbacks # c.profile callback.name - for i in [0...len] + for i in [0...len] by 1 node = nodes[i] try callback.cb.call node diff --git a/src/General/Post.coffee b/src/General/Post.coffee index 7319235fd..c792efa81 100644 --- a/src/General/Post.coffee +++ b/src/General/Post.coffee @@ -73,7 +73,7 @@ class Post text = [] # XPathResult.ORDERED_NODE_SNAPSHOT_TYPE === 7 nodes = d.evaluate './/br|.//text()', bq, null, 7, null - for i in [0...nodes.snapshotLength] + for i in [0...nodes.snapshotLength] by 1 text.push nodes.snapshotItem(i).data or '\n' @info.comment = text.join('').trim().replace /\s+$/gm, '' diff --git a/src/Miscellaneous/IDColor.coffee b/src/Miscellaneous/IDColor.coffee index e3ae50715..def9ee3c7 100644 --- a/src/Miscellaneous/IDColor.coffee +++ b/src/Miscellaneous/IDColor.coffee @@ -35,6 +35,6 @@ IDColor = hash: (uniqueID) -> msg = 0 - for i in [0...uniqueID.length] + for i in [0...uniqueID.length] by 1 msg = (msg << 5) - msg + uniqueID.charCodeAt i msg From 638c836e59315bb473985bfb24295e9da5c0a912 Mon Sep 17 00:00:00 2001 From: ferongr Date: Fri, 23 Aug 2013 23:42:05 +0300 Subject: [PATCH 5/6] Autohide persistent QR in catalog, fix #1241 That was easier than expected --- src/Posting/QR.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Posting/QR.coffee b/src/Posting/QR.coffee index eb88f66c8..cad8ea4b4 100644 --- a/src/Posting/QR.coffee +++ b/src/Posting/QR.coffee @@ -52,7 +52,7 @@ QR = persist: -> QR.open() - QR.hide() if Conf['Auto-Hide QR'] + QR.hide() if Conf['Auto-Hide QR'] or g.VIEW is 'catalog' open: -> if QR.nodes QR.nodes.el.hidden = false From 667abe7480b04161ec10cf00fffad17accdf23a0 Mon Sep 17 00:00:00 2001 From: Mayhem Date: Sat, 24 Aug 2013 16:51:32 +0200 Subject: [PATCH 6/6] Don't nuke DataBoards when threads.json 404s, as 4chan fucks up often. --- src/General/DataBoard.coffee | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/General/DataBoard.coffee b/src/General/DataBoard.coffee index 7939f7d57..066b599c1 100644 --- a/src/General/DataBoard.coffee +++ b/src/General/DataBoard.coffee @@ -70,18 +70,15 @@ class DataBoard @save() ajaxClean: (boardID) -> $.cache "//api.4chan.org/#{boardID}/threads.json", (e) => - if e.target.status is 404 - # Deleted board. - @delete boardID - else if e.target.status is 200 - board = @data.boards[boardID] - threads = {} - for page in JSON.parse e.target.response - for thread in page.threads - if thread.no of board - threads[thread.no] = board[thread.no] - @data.boards[boardID] = threads - @deleteIfEmpty {boardID} + return if e.target.status isnt 200 + board = @data.boards[boardID] + threads = {} + for page in JSON.parse e.target.response + for thread in page.threads + if thread.no of board + threads[thread.no] = board[thread.no] + @data.boards[boardID] = threads + @deleteIfEmpty {boardID} @save() onSync: (data) =>