Merge @ccd0's title fix.
Make some funny changes to IDColor
This commit is contained in:
parent
2e3a433fc0
commit
bf8fedb659
2
LICENSE
2
LICENSE
@ -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.
|
* Licensed under the MIT license.
|
||||||
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE
|
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE
|
||||||
|
|||||||
@ -25,7 +25,7 @@
|
|||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* appchan x - Version 2.9.31 - 2014-07-18
|
* appchan x - Version 2.9.31 - 2014-07-26
|
||||||
*
|
*
|
||||||
* Licensed under the MIT license.
|
* Licensed under the MIT license.
|
||||||
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE
|
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE
|
||||||
@ -13046,7 +13046,7 @@
|
|||||||
Unread.read();
|
Unread.read();
|
||||||
return Unread.update();
|
return Unread.update();
|
||||||
} else {
|
} else {
|
||||||
return Unread.addPosts(e.detail.newPosts.map(function(fullID) {
|
return Unread.addPosts([].map.call(e.detail.newPosts, function(fullID) {
|
||||||
return g.posts[fullID];
|
return g.posts[fullID];
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -15532,46 +15532,35 @@
|
|||||||
if (!Conf['Color User IDs']) {
|
if (!Conf['Color User IDs']) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.ids = {};
|
this.ids = {
|
||||||
|
Heaven: [0, 0, 0, '#fff']
|
||||||
|
};
|
||||||
return Post.callbacks.push({
|
return Post.callbacks.push({
|
||||||
name: 'Color User IDs',
|
name: 'Color User IDs',
|
||||||
cb: this.node
|
cb: this.node
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
node: function() {
|
node: function() {
|
||||||
var rgb, span, style, uid;
|
var rgb, span, uid;
|
||||||
if (this.isClone || !(uid = this.info.uniqueID)) {
|
if (this.isClone || !((uid = this.info.uniqueID) && (span = $('span.hand', this.nodes.uniqueID)))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
span = $('.hand', this.nodes.uniqueID);
|
rgb = IDColor.ids[uid] || IDColor.compute(uid);
|
||||||
if (!(span && span.nodeName === 'SPAN')) {
|
span.style.color = rgb[3];
|
||||||
return;
|
span.style.backgroundColor = "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")";
|
||||||
}
|
|
||||||
rgb = IDColor.compute(uid);
|
|
||||||
style = span.style;
|
|
||||||
style.color = rgb[3];
|
|
||||||
style.backgroundColor = "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")";
|
|
||||||
$.addClass(span, 'painted');
|
$.addClass(span, 'painted');
|
||||||
return span.title = 'Highlight posts by this ID';
|
return span.title = 'Highlight posts by this ID';
|
||||||
},
|
},
|
||||||
compute: function(uid) {
|
compute: function(uid) {
|
||||||
var hash, rgb;
|
var hash, i, rgb;
|
||||||
if (IDColor.ids[uid]) {
|
i = 1;
|
||||||
return IDColor.ids[uid];
|
hash = uid.charCodeAt(0);
|
||||||
}
|
|
||||||
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;
|
|
||||||
while (i < 8) {
|
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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
// Generated by CoffeeScript
|
// 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.
|
* Licensed under the MIT license.
|
||||||
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE
|
* https://github.com/zixaphir/appchan-x/blob/master/LICENSE
|
||||||
@ -13055,7 +13055,7 @@
|
|||||||
Unread.read();
|
Unread.read();
|
||||||
return Unread.update();
|
return Unread.update();
|
||||||
} else {
|
} else {
|
||||||
return Unread.addPosts(e.detail.newPosts.map(function(fullID) {
|
return Unread.addPosts([].map.call(e.detail.newPosts, function(fullID) {
|
||||||
return g.posts[fullID];
|
return g.posts[fullID];
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
@ -15546,46 +15546,35 @@
|
|||||||
if (!Conf['Color User IDs']) {
|
if (!Conf['Color User IDs']) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.ids = {};
|
this.ids = {
|
||||||
|
Heaven: [0, 0, 0, '#fff']
|
||||||
|
};
|
||||||
return Post.callbacks.push({
|
return Post.callbacks.push({
|
||||||
name: 'Color User IDs',
|
name: 'Color User IDs',
|
||||||
cb: this.node
|
cb: this.node
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
node: function() {
|
node: function() {
|
||||||
var rgb, span, style, uid;
|
var rgb, span, uid;
|
||||||
if (this.isClone || !(uid = this.info.uniqueID)) {
|
if (this.isClone || !((uid = this.info.uniqueID) && (span = $('span.hand', this.nodes.uniqueID)))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
span = $('.hand', this.nodes.uniqueID);
|
rgb = IDColor.ids[uid] || IDColor.compute(uid);
|
||||||
if (!(span && span.nodeName === 'SPAN')) {
|
span.style.color = rgb[3];
|
||||||
return;
|
span.style.backgroundColor = "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")";
|
||||||
}
|
|
||||||
rgb = IDColor.compute(uid);
|
|
||||||
style = span.style;
|
|
||||||
style.color = rgb[3];
|
|
||||||
style.backgroundColor = "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")";
|
|
||||||
$.addClass(span, 'painted');
|
$.addClass(span, 'painted');
|
||||||
return span.title = 'Highlight posts by this ID';
|
return span.title = 'Highlight posts by this ID';
|
||||||
},
|
},
|
||||||
compute: function(uid) {
|
compute: function(uid) {
|
||||||
var hash, rgb;
|
var hash, i, rgb;
|
||||||
if (IDColor.ids[uid]) {
|
i = 1;
|
||||||
return IDColor.ids[uid];
|
hash = uid.charCodeAt(0);
|
||||||
}
|
|
||||||
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;
|
|
||||||
while (i < 8) {
|
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;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1,41 +1,44 @@
|
|||||||
IDColor =
|
IDColor =
|
||||||
init: ->
|
init: ->
|
||||||
return if !Conf['Color User IDs']
|
return if !Conf['Color User IDs']
|
||||||
@ids = {}
|
@ids = {
|
||||||
|
Heaven: [0, 0, 0, '#fff']
|
||||||
|
}
|
||||||
|
|
||||||
Post.callbacks.push
|
Post.callbacks.push
|
||||||
name: 'Color User IDs'
|
name: 'Color User IDs'
|
||||||
cb: @node
|
cb: @node
|
||||||
|
|
||||||
node: ->
|
node: ->
|
||||||
return if @isClone or not uid = @info.uniqueID
|
return if @isClone or !((uid = @info.uniqueID) and (span = $ 'span.hand', @nodes.uniqueID))
|
||||||
span = $ '.hand', @nodes.uniqueID
|
|
||||||
return unless span and span.nodeName is 'SPAN'
|
rgb = IDColor.ids[uid] or IDColor.compute uid
|
||||||
rgb = IDColor.compute uid
|
|
||||||
{style} = span
|
# Style the damn node.
|
||||||
style.color = rgb[3]
|
span.style.color = rgb[3]
|
||||||
style.backgroundColor = "rgb(#{rgb[0]},#{rgb[1]},#{rgb[2]})"
|
span.style.backgroundColor = "rgb(#{rgb[0]},#{rgb[1]},#{rgb[2]})"
|
||||||
$.addClass span, 'painted'
|
$.addClass span, 'painted'
|
||||||
span.title = 'Highlight posts by this ID'
|
span.title = 'Highlight posts by this ID'
|
||||||
|
|
||||||
compute: (uid) ->
|
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 = [
|
rgb = [
|
||||||
(hash >> 24) & 0xFF
|
(hash >> 24) & 0xFF
|
||||||
(hash >> 16) & 0xFF
|
(hash >> 16) & 0xFF
|
||||||
(hash >> 8) & 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
|
else
|
||||||
'#fff'
|
'#fff'
|
||||||
@ids[uid] = rgb
|
|
||||||
|
|
||||||
hash: (uid) ->
|
# Cache.
|
||||||
msg = 0
|
@ids[uid] = rgb
|
||||||
i = 0
|
|
||||||
while i < 8
|
|
||||||
msg = (msg << 5) - msg + uid.charCodeAt i++
|
|
||||||
msg
|
|
||||||
@ -126,7 +126,7 @@ Unread =
|
|||||||
Unread.read()
|
Unread.read()
|
||||||
Unread.update()
|
Unread.update()
|
||||||
else
|
else
|
||||||
Unread.addPosts e.detail.newPosts.map (fullID) -> g.posts[fullID]
|
Unread.addPosts [].map.call e.detail.newPosts, (fullID) -> g.posts[fullID]
|
||||||
|
|
||||||
readSinglePost: (post) ->
|
readSinglePost: (post) ->
|
||||||
{ID} = post
|
{ID} = post
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user