Merge @ccd0's title fix.

Make some funny changes to IDColor
This commit is contained in:
Zixaphir 2014-07-26 18:57:41 -07:00
parent 2e3a433fc0
commit bf8fedb659
5 changed files with 58 additions and 77 deletions

View File

@ -1,5 +1,5 @@
/*
* appchan x - Version 2.9.31 - 2014-07-18
* appchan x - Version 2.9.31 - 2014-07-26
*
* Licensed under the MIT license.
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE

View File

@ -25,7 +25,7 @@
// ==/UserScript==
/*
* appchan x - Version 2.9.31 - 2014-07-18
* appchan x - Version 2.9.31 - 2014-07-26
*
* Licensed under the MIT license.
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE
@ -13046,7 +13046,7 @@
Unread.read();
return Unread.update();
} else {
return Unread.addPosts(e.detail.newPosts.map(function(fullID) {
return Unread.addPosts([].map.call(e.detail.newPosts, function(fullID) {
return g.posts[fullID];
}));
}
@ -15532,46 +15532,35 @@
if (!Conf['Color User IDs']) {
return;
}
this.ids = {};
this.ids = {
Heaven: [0, 0, 0, '#fff']
};
return Post.callbacks.push({
name: 'Color User IDs',
cb: this.node
});
},
node: function() {
var rgb, span, style, uid;
if (this.isClone || !(uid = this.info.uniqueID)) {
var rgb, span, uid;
if (this.isClone || !((uid = this.info.uniqueID) && (span = $('span.hand', this.nodes.uniqueID)))) {
return;
}
span = $('.hand', this.nodes.uniqueID);
if (!(span && span.nodeName === 'SPAN')) {
return;
}
rgb = IDColor.compute(uid);
style = span.style;
style.color = rgb[3];
style.backgroundColor = "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")";
rgb = IDColor.ids[uid] || IDColor.compute(uid);
span.style.color = rgb[3];
span.style.backgroundColor = "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")";
$.addClass(span, 'painted');
return span.title = 'Highlight posts by this ID';
},
compute: function(uid) {
var hash, rgb;
if (IDColor.ids[uid]) {
return IDColor.ids[uid];
}
hash = IDColor.hash(uid);
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 ? '#000' : '#fff';
return this.ids[uid] = rgb;
},
hash: function(uid) {
var i, msg;
msg = 0;
i = 0;
var hash, i, rgb;
i = 1;
hash = uid.charCodeAt(0);
while (i < 8) {
msg = (msg << 5) - msg + uid.charCodeAt(i++);
hash = (hash << 5) - hash + uid.charCodeAt(i++);
}
return msg;
rgb = [(hash >> 24) & 0xFF, (hash >> 16) & 0xFF, (hash >> 8) & 0xFF];
rgb.push((rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114) > 125 ? '#000' : '#fff');
return this.ids[uid] = rgb;
}
};

View File

@ -1,6 +1,6 @@
// Generated by CoffeeScript
/*
* appchan x - Version 2.9.31 - 2014-07-18
* appchan x - Version 2.9.31 - 2014-07-26
*
* Licensed under the MIT license.
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE
@ -13055,7 +13055,7 @@
Unread.read();
return Unread.update();
} else {
return Unread.addPosts(e.detail.newPosts.map(function(fullID) {
return Unread.addPosts([].map.call(e.detail.newPosts, function(fullID) {
return g.posts[fullID];
}));
}
@ -15546,46 +15546,35 @@
if (!Conf['Color User IDs']) {
return;
}
this.ids = {};
this.ids = {
Heaven: [0, 0, 0, '#fff']
};
return Post.callbacks.push({
name: 'Color User IDs',
cb: this.node
});
},
node: function() {
var rgb, span, style, uid;
if (this.isClone || !(uid = this.info.uniqueID)) {
var rgb, span, uid;
if (this.isClone || !((uid = this.info.uniqueID) && (span = $('span.hand', this.nodes.uniqueID)))) {
return;
}
span = $('.hand', this.nodes.uniqueID);
if (!(span && span.nodeName === 'SPAN')) {
return;
}
rgb = IDColor.compute(uid);
style = span.style;
style.color = rgb[3];
style.backgroundColor = "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")";
rgb = IDColor.ids[uid] || IDColor.compute(uid);
span.style.color = rgb[3];
span.style.backgroundColor = "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")";
$.addClass(span, 'painted');
return span.title = 'Highlight posts by this ID';
},
compute: function(uid) {
var hash, rgb;
if (IDColor.ids[uid]) {
return IDColor.ids[uid];
}
hash = IDColor.hash(uid);
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 ? '#000' : '#fff';
return this.ids[uid] = rgb;
},
hash: function(uid) {
var i, msg;
msg = 0;
i = 0;
var hash, i, rgb;
i = 1;
hash = uid.charCodeAt(0);
while (i < 8) {
msg = (msg << 5) - msg + uid.charCodeAt(i++);
hash = (hash << 5) - hash + uid.charCodeAt(i++);
}
return msg;
rgb = [(hash >> 24) & 0xFF, (hash >> 16) & 0xFF, (hash >> 8) & 0xFF];
rgb.push((rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114) > 125 ? '#000' : '#fff');
return this.ids[uid] = rgb;
}
};

View File

@ -1,41 +1,44 @@
IDColor =
init: ->
return if !Conf['Color User IDs']
@ids = {}
@ids = {
Heaven: [0, 0, 0, '#fff']
}
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]})"
return if @isClone or !((uid = @info.uniqueID) and (span = $ 'span.hand', @nodes.uniqueID))
rgb = IDColor.ids[uid] or IDColor.compute uid
# Style the damn node.
span.style.color = rgb[3]
span.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]
# Convert chars to integers, bitshift and math to create a larger integer
# Create a nice string of binary
i = 1
hash = uid.charCodeAt 0
hash = (hash << 5) - hash + uid.charCodeAt i++ while i < 8
hash = IDColor.hash uid
# Convert binary string to numerical values with bitshift and '&' truncation.
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'
# Weight color luminance values, assign a font color that should be readable.
rgb.push 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
# Cache.
@ids[uid] = rgb

View File

@ -126,7 +126,7 @@ Unread =
Unread.read()
Unread.update()
else
Unread.addPosts e.detail.newPosts.map (fullID) -> g.posts[fullID]
Unread.addPosts [].map.call e.detail.newPosts, (fullID) -> g.posts[fullID]
readSinglePost: (post) ->
{ID} = post