Fix ID colors on Tinyboard/vichan sites. #2355

This commit is contained in:
ccd0 2019-07-09 01:04:22 -07:00
parent 667495e641
commit c28532f6f4
2 changed files with 9 additions and 9 deletions

View File

@ -23,13 +23,13 @@ IDColor =
compute: (uid) ->
# Convert chars to integers, bitshift and math to create a larger integer
# Create a nice string of binary
hash = IDColor.hash uid
hash = if Site.uidColor then Site.uidColor(uid) else parseInt(uid, 16)
# Convert binary string to numerical values with bitshift and '&' truncation.
rgb = [
(hash >> 24) & 0xFF
(hash >> 16) & 0xFF
(hash >> 8) & 0xFF
hash & 0xFF
]
# Weight color luminance values, assign a font color that should be readable.
@ -40,10 +40,3 @@ IDColor =
# Cache.
@ids[uid] = rgb
hash: (uid) ->
msg = 0
i = 0
while i < 8
msg = (msg << 5) - msg + uid.charCodeAt i++
msg

View File

@ -158,3 +158,10 @@ SW.yotsuba =
sfwBoards: (sfw) ->
BoardConfig.sfwBoards(sfw)
uidColor: (uid) ->
msg = 0
i = 0
while i < 8
msg = (msg << 5) - msg + uid.charCodeAt i++
(msg >> 8) & 0xFFFFFF