4chan-x/src/Miscellaneous/IDColor.coffee
Zixaphir 9d95bbea35 Merge branch 'mayhem' into v3 -- Still broken, do not merge (yet)
Conflicts:
	CHANGELOG.md
	Gruntfile.coffee
	css/burichan.css
	css/futaba.css
	css/photon.css
	css/style.css
	css/tomorrow.css
	css/yotsuba-b.css
	css/yotsuba.css
	html/General/Index-navlinks.html
	html/General/Settings-section-Rice.html
	html/General/Settings.html
	html/Posting/QR.html
	json/archives.json
	package.json
	src/Filtering/PostHiding.coffee
	src/Filtering/Recursive.coffee
	src/Filtering/ThreadHiding.coffee
	src/General/Build.coffee
	src/General/Config.coffee
	src/General/Get.coffee
	src/General/Header.coffee
	src/General/Index.coffee
	src/General/Main.coffee
	src/General/Settings.coffee
	src/General/UI.coffee
	src/General/lib/$.coffee
	src/General/lib/databoard.class
	src/General/lib/post.class
	src/General/lib/thread.class
	src/Images/ImageExpand.coffee
	src/Images/RevealSpoilers.coffee
	src/Linkification/Linkify.coffee
	src/Menu/Menu.coffee
	src/Miscellaneous/ExpandThread.coffee
	src/Miscellaneous/IDColor.coffee
	src/Miscellaneous/Keybinds.coffee
	src/Monitoring/ThreadUpdater.coffee
	src/Monitoring/Unread.coffee
	src/Posting/QR.captcha.coffee
	src/Posting/QR.coffee
	src/Posting/QR.cooldown.coffee
	src/Quotelinks/QuoteBacklink.coffee
	src/Quotelinks/QuoteCT.coffee
	src/Quotelinks/QuoteOP.coffee
	src/Quotelinks/QuoteStrikeThrough.coffee
	src/Quotelinks/QuoteYou.coffee
	src/Quotelinks/Quotify.coffee
2014-02-23 14:04:45 -07:00

42 lines
949 B
CoffeeScript
Executable File

IDColor =
init: ->
return if !Conf['Color User IDs']
@ids = {}
Post.callbacks.push
name: 'Color User IDs'
cb: @node
node: ->
return if @isClone or not uid = @info.uniqueID
span = $ '.hand', @nodes.uniqueID
return unless span and span.nodeName is 'SPAN'
rgb = IDColor.compute uid
{style} = span
style.color = rgb[3]
style.backgroundColor = "rgb(#{rgb[0]},#{rgb[1]},#{rgb[2]})"
$.addClass span, 'painted'
span.title = 'Highlight posts by this ID'
compute: (uid) ->
return IDColor.ids[uid] if IDColor.ids[uid]
hash = IDColor.hash uid
rgb = [
(hash >> 24) & 0xFF
(hash >> 16) & 0xFF
(hash >> 8) & 0xFF
]
rgb[3] = if (rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114) > 125
'#000'
else
'#fff'
@ids[uid] = rgb
hash: (uid) ->
msg = 0
i = 0
while i < 8
msg = (msg << 5) - msg + uid.charCodeAt i++
msg