diff --git a/builds/4chan-X.js b/builds/4chan-X.js index b84eeecca..0a89a9342 100644 --- a/builds/4chan-X.js +++ b/builds/4chan-X.js @@ -102,7 +102,7 @@ * this notice is kept intact. */ (function() { - var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g, + var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, IDColor, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g, __slice = [].slice, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, @@ -126,6 +126,7 @@ 'Reply Navigation': [false, 'Add buttons to navigate to top / bottom of thread.'], 'Check for Updates': [true, 'Check for updated versions of 4chan X.'], 'Emoji': [false, 'Adds icons next to names for different emails'], + 'Color User IDs': [false, 'Assign unique colors to user IDs on boards that use them'], 'Remove Spoilers': [false, 'Remove all spoilers in text.'], 'Indicate Spoilers': [false, 'Indicate spoilers if Remove Spoilers is enabled.'] }, @@ -4337,6 +4338,57 @@ } }; + IDColor = { + init: function() { + if (!Conf['Color User IDs']) { + return; + } + return Post.prototype.callbacks.push({ + name: 'Reveal Spoilers', + cb: this.node + }); + }, + node: function(post) { + var str, uid; + + if (!(uid = $('.hand', this.nodes.uniqueID))) { + return; + } + str = this.info.uniqueID; + if (uid.nodeName === 'SPAN') { + return uid.style.cssText = IDColor.apply.call(str); + } + }, + ids: {}, + compute: function(str) { + var hash, rgb; + + hash = this.hash(str); + rgb = [(hash >> 24) & 0xFF, (hash >> 16) & 0xFF, (hash >> 8) & 0xFF]; + rgb[3] = ((rgb[0] * 0.299) + (rgb[1] * 0.587) + (rgb[2] * 0.114)) > 125; + this.ids[str] = rgb; + return rgb; + }, + apply: function() { + var rgb; + + rgb = IDColor.ids[this] || IDColor.compute(this); + return ("background-color: rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + "); color: ") + (rgb[3] ? "black;" : "white;"); + }, + hash: function(str) { + var i, j, msg; + + msg = 0; + i = 0; + j = str.length; + while (i < j) { + msg = ((msg << 5) - msg) + str.charCodeAt(i); + ++i; + } + return msg; + } + }; + Emoji = { init: function() { var css, icon, name, pos, _ref; @@ -9468,6 +9520,7 @@ 'Announcement Hiding': PSAHiding, 'Fourchan thingies': Fourchan, 'Emoji': Emoji, + 'Color User IDs': IDColor, 'Remove Spoilers': RemoveSpoilers, 'Custom CSS': CustomCSS, 'Linkify': Linkify, diff --git a/builds/4chan-X.user.js b/builds/4chan-X.user.js index 526354338..c506ce813 100644 --- a/builds/4chan-X.user.js +++ b/builds/4chan-X.user.js @@ -102,7 +102,7 @@ * this notice is kept intact. */ (function() { - var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g, + var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, IDColor, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g, __slice = [].slice, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, @@ -126,6 +126,7 @@ 'Reply Navigation': [false, 'Add buttons to navigate to top / bottom of thread.'], 'Check for Updates': [true, 'Check for updated versions of 4chan X.'], 'Emoji': [false, 'Adds icons next to names for different emails'], + 'Color User IDs': [false, 'Assign unique colors to user IDs on boards that use them'], 'Remove Spoilers': [false, 'Remove all spoilers in text.'], 'Indicate Spoilers': [false, 'Indicate spoilers if Remove Spoilers is enabled.'] }, @@ -4328,6 +4329,57 @@ } }; + IDColor = { + init: function() { + if (!Conf['Color User IDs']) { + return; + } + return Post.prototype.callbacks.push({ + name: 'Reveal Spoilers', + cb: this.node + }); + }, + node: function(post) { + var str, uid; + + if (!(uid = $('.hand', this.nodes.uniqueID))) { + return; + } + str = this.info.uniqueID; + if (uid.nodeName === 'SPAN') { + return uid.style.cssText = IDColor.apply.call(str); + } + }, + ids: {}, + compute: function(str) { + var hash, rgb; + + hash = this.hash(str); + rgb = [(hash >> 24) & 0xFF, (hash >> 16) & 0xFF, (hash >> 8) & 0xFF]; + rgb[3] = ((rgb[0] * 0.299) + (rgb[1] * 0.587) + (rgb[2] * 0.114)) > 125; + this.ids[str] = rgb; + return rgb; + }, + apply: function() { + var rgb; + + rgb = IDColor.ids[this] || IDColor.compute(this); + return ("background-color: rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + "); color: ") + (rgb[3] ? "black;" : "white;"); + }, + hash: function(str) { + var i, j, msg; + + msg = 0; + i = 0; + j = str.length; + while (i < j) { + msg = ((msg << 5) - msg) + str.charCodeAt(i); + ++i; + } + return msg; + } + }; + Emoji = { init: function() { var css, icon, name, pos, _ref; @@ -9486,6 +9538,7 @@ 'Announcement Hiding': PSAHiding, 'Fourchan thingies': Fourchan, 'Emoji': Emoji, + 'Color User IDs': IDColor, 'Remove Spoilers': RemoveSpoilers, 'Custom CSS': CustomCSS, 'Linkify': Linkify, diff --git a/builds/crx/script.js b/builds/crx/script.js index 9150c050f..3b34a77e5 100644 --- a/builds/crx/script.js +++ b/builds/crx/script.js @@ -1,5 +1,5 @@ (function() { - var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g, + var $, $$, Anonymize, ArchiveLink, Board, Build, CatalogLinks, Clone, Conf, Config, CustomCSS, DataBoard, DataBoards, DeleteLink, DownloadLink, Emoji, ExpandComment, ExpandThread, FappeTyme, Favicon, FileInfo, Filter, Fourchan, Get, Header, IDColor, ImageExpand, ImageHover, ImageReplace, Keybinds, Linkify, Main, Menu, Nav, Notification, PSAHiding, Polyfill, Post, PostHiding, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, QuoteStrikeThrough, QuoteThreading, QuoteYou, Quotify, Recursive, Redirect, RelativeDates, RemoveSpoilers, Report, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, c, d, doc, g, __slice = [].slice, __hasProp = {}.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, @@ -23,6 +23,7 @@ 'Reply Navigation': [false, 'Add buttons to navigate to top / bottom of thread.'], 'Check for Updates': [true, 'Check for updated versions of 4chan X.'], 'Emoji': [false, 'Adds icons next to names for different emails'], + 'Color User IDs': [false, 'Assign unique colors to user IDs on boards that use them'], 'Remove Spoilers': [false, 'Remove all spoilers in text.'], 'Indicate Spoilers': [false, 'Indicate spoilers if Remove Spoilers is enabled.'] }, @@ -4192,6 +4193,57 @@ } }; + IDColor = { + init: function() { + if (!Conf['Color User IDs']) { + return; + } + return Post.prototype.callbacks.push({ + name: 'Reveal Spoilers', + cb: this.node + }); + }, + node: function(post) { + var str, uid; + + if (!(uid = $('.hand', this.nodes.uniqueID))) { + return; + } + str = this.info.uniqueID; + if (uid.nodeName === 'SPAN') { + return uid.style.cssText = IDColor.apply.call(str); + } + }, + ids: {}, + compute: function(str) { + var hash, rgb; + + hash = this.hash(str); + rgb = [(hash >> 24) & 0xFF, (hash >> 16) & 0xFF, (hash >> 8) & 0xFF]; + rgb[3] = ((rgb[0] * 0.299) + (rgb[1] * 0.587) + (rgb[2] * 0.114)) > 125; + this.ids[str] = rgb; + return rgb; + }, + apply: function() { + var rgb; + + rgb = IDColor.ids[this] || IDColor.compute(this); + return ("background-color: rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + "); color: ") + (rgb[3] ? "black;" : "white;"); + }, + hash: function(str) { + var i, j, msg; + + msg = 0; + i = 0; + j = str.length; + while (i < j) { + msg = ((msg << 5) - msg) + str.charCodeAt(i); + ++i; + } + return msg; + } + }; + Emoji = { init: function() { var css, icon, name, pos, _ref; @@ -9329,6 +9381,7 @@ 'Announcement Hiding': PSAHiding, 'Fourchan thingies': Fourchan, 'Emoji': Emoji, + 'Color User IDs': IDColor, 'Remove Spoilers': RemoveSpoilers, 'Custom CSS': CustomCSS, 'Linkify': Linkify, diff --git a/src/config.coffee b/src/config.coffee index 42a19969d..3d17ac26c 100644 --- a/src/config.coffee +++ b/src/config.coffee @@ -61,6 +61,10 @@ Config = false 'Adds icons next to names for different emails' ] + 'Color User IDs': [ + false + 'Assign unique colors to user IDs on boards that use them' + ] 'Remove Spoilers': [ false 'Remove all spoilers in text.' diff --git a/src/features/misc/coloruserids.coffee b/src/features/misc/coloruserids.coffee new file mode 100644 index 000000000..fe524d74f --- /dev/null +++ b/src/features/misc/coloruserids.coffee @@ -0,0 +1,41 @@ +IDColor = + init: -> + return unless Conf['Color User IDs'] + + Post::callbacks.push + name: 'Reveal Spoilers' + cb: @node + + node: (post) -> + return unless uid = $ '.hand', @nodes.uniqueID + str = @info.uniqueID + if uid.nodeName is 'SPAN' + uid.style.cssText = IDColor.apply.call str + + ids: {} + + compute: (str) -> + hash = @hash str + + rgb = [ + (hash >> 24) & 0xFF + (hash >> 16) & 0xFF + (hash >> 8) & 0xFF + ] + rgb[3] = ((rgb[0] * 0.299) + (rgb[1] * 0.587) + (rgb[2] * 0.114)) > 125 + + @ids[str] = rgb + rgb + + apply: -> + rgb = IDColor.ids[@] or IDColor.compute @ + "background-color: rgb(#{rgb[0]},#{rgb[1]},#{rgb[2]}); color: " + if rgb[3] then "black;" else "white;" + + hash: (str) -> + msg = 0 + i = 0 + j = str.length + while i < j + msg = ((msg << 5) - msg) + str.charCodeAt i + ++i + msg \ No newline at end of file diff --git a/src/main.coffee b/src/main.coffee index ff5a69d11..d5a7fb58c 100644 --- a/src/main.coffee +++ b/src/main.coffee @@ -72,6 +72,7 @@ Main = 'Announcement Hiding': PSAHiding 'Fourchan thingies': Fourchan 'Emoji': Emoji + 'Color User IDs': IDColor 'Remove Spoilers': RemoveSpoilers 'Custom CSS': CustomCSS 'Linkify': Linkify