Update Dice, Fourchan, and IDColor

This commit is contained in:
Zixaphir 2015-01-09 20:05:44 -07:00
parent 32e5eba15d
commit 2a94bb7150
5 changed files with 146 additions and 63 deletions

View File

@ -14675,7 +14675,8 @@
Dice = { Dice = {
init: function() { init: function() {
if (g.BOARD.ID !== 'tg' || !Conf['Show Dice Roll']) { var _ref;
if (!(((_ref = g.VIEW) === 'index' || _ref === 'thread') && g.BOARD.ID === 'tg' && Conf['Show Dice Roll'])) {
return; return;
} }
return Post.callbacks.push({ return Post.callbacks.push({
@ -15077,22 +15078,32 @@
Fourchan = { Fourchan = {
init: function() { init: function() {
var board; var id, _ref;
board = g.BOARD.ID; if ((_ref = g.VIEW) !== 'index' && _ref !== 'thread') {
if (board === 'g') { return;
$.globalEval("window.addEventListener('prettyprint', function(e) {\n window.dispatchEvent(new CustomEvent('prettyprint:cb', {\n detail: prettyPrintOne(e.detail)\n }));\n}, false);"); }
id = g.BOARD.ID;
if (id === 'g') {
$.globalEval('window.addEventListener(\'prettyprint\', function(e) {\n window.dispatchEvent(new CustomEvent(\'prettyprint:cb\', {\n detail: prettyPrintOne(e.detail)\n }));\n}, false);');
Post.callbacks.push({ Post.callbacks.push({
name: 'Parse /g/ code', name: 'Parse /g/ code',
cb: this.code cb: this.code
}); });
} }
if (board === 'sci') { if (id === 'sci') {
$.globalEval("window.addEventListener('jsmath', function(e) {\n if (jsMath.loaded) {\n // process one post\n jsMath.ProcessBeforeShowing(document.getElementById(e.detail));\n } else {\n // load jsMath and process whole document\n jsMath.Autoload.Script.Push('ProcessBeforeShowing', [null]);\n jsMath.Autoload.LoadJsMath();\n }\n}, false);"); $.globalEval('window.addEventListener(\'jsmath\', function(e) {\n if (!jsMath) return;\n // process one post\n jsMath.ProcessBeforeShowing(e.target);\n } else if (jsMath.Autoload && jsMath.Autoload.checked) {\n // load jsMath and process whole document\n jsMath.Autoload.Script.Push(\'ProcessBeforeShowing\', [null]);\n jsMath.Autoload.LoadJsMath();\n }\n}, false);');
return Post.callbacks.push({ Post.callbacks.push({
name: 'Parse /sci/ math',
cb: this.math
});
CatalogThread.callbacks.push({
name: 'Parse /sci/ math', name: 'Parse /sci/ math',
cb: this.math cb: this.math
}); });
} }
return Main.ready(function() {
return $.globalEval('(function() {\n window.clickable_ids = false;\n var nodes = document.querySelectorAll(\'.posteruid, .capcode\');\n for (var i = 0; i < nodes.length; i++) {\n nodes[i].removeEventListener("click", window.idClick, false);\n }\n window.removeEventListener("message", Report.onMessage, false);\n})();');
});
}, },
code: function() { code: function() {
var apply, pre, _i, _len, _ref; var apply, pre, _i, _len, _ref;
@ -15100,7 +15111,8 @@
return; return;
} }
apply = function(e) { apply = function(e) {
return pre.innerHTML = e.detail; pre.innerHTML = e.detail;
return $.addClass(pre, 'prettyprinted');
}; };
$.on(window, 'prettyprint:cb', apply); $.on(window, 'prettyprint:cb', apply);
_ref = $$('.prettyprint:not(.prettyprinted)', this.nodes.comment); _ref = $$('.prettyprint:not(.prettyprinted)', this.nodes.comment);
@ -15111,16 +15123,25 @@
$.off(window, 'prettyprint:cb', apply); $.off(window, 'prettyprint:cb', apply);
}, },
math: function() { math: function() {
if (this.isClone || !$('.math', this.nodes.comment)) { if ((this.isClone && doc.contains(this.origin.nodes.root)) || !$('.math', this.nodes.comment)) {
return; return;
} }
return $.event('jsmath', this.nodes.post.id, window); return $.asap(((function(_this) {
return function() {
return doc.contains(_this.nodes.comment);
};
})(this)), (function(_this) {
return function() {
return $.event('jsmath', null, _this.nodes.comment);
};
})(this));
} }
}; };
IDColor = { IDColor = {
init: function() { init: function() {
if (!Conf['Color User IDs']) { var _ref;
if (!(((_ref = g.VIEW) === 'index' || _ref === 'thread') && Conf['Color User IDs'])) {
return; return;
} }
this.ids = { this.ids = {
@ -15132,26 +15153,32 @@
}); });
}, },
node: function() { node: function() {
var rgb, span, uid; var rgb, span, style, uid;
if (this.isClone || !((uid = this.info.uniqueID) && (span = $('span.hand', this.nodes.uniqueID)))) { if (this.isClone || !((uid = this.info.uniqueID) && (span = $('span.hand', this.nodes.uniqueID)))) {
return; return;
} }
rgb = IDColor.ids[uid] || IDColor.compute(uid); rgb = IDColor.ids[uid] || IDColor.compute(uid);
span.style.color = rgb[3]; style = span.style;
span.style.backgroundColor = "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")"; 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, i, rgb; var hash, rgb;
i = 1; hash = IDColor.hash(uid);
hash = uid.charCodeAt(0);
while (i < 8) {
hash = (hash << 5) - hash + uid.charCodeAt(i++);
}
rgb = [(hash >> 24) & 0xFF, (hash >> 16) & 0xFF, (hash >> 8) & 0xFF]; 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'); rgb.push((rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114) > 125 ? '#000' : '#fff');
return this.ids[uid] = rgb; return this.ids[uid] = rgb;
},
hash: function(uid) {
var i, msg;
msg = 0;
i = 0;
while (i < 8) {
msg = (msg << 5) - msg + uid.charCodeAt(i++);
}
return msg;
} }
}; };

View File

@ -14696,7 +14696,8 @@
Dice = { Dice = {
init: function() { init: function() {
if (g.BOARD.ID !== 'tg' || !Conf['Show Dice Roll']) { var _ref;
if (!(((_ref = g.VIEW) === 'index' || _ref === 'thread') && g.BOARD.ID === 'tg' && Conf['Show Dice Roll'])) {
return; return;
} }
return Post.callbacks.push({ return Post.callbacks.push({
@ -15098,22 +15099,32 @@
Fourchan = { Fourchan = {
init: function() { init: function() {
var board; var id, _ref;
board = g.BOARD.ID; if ((_ref = g.VIEW) !== 'index' && _ref !== 'thread') {
if (board === 'g') { return;
$.globalEval("window.addEventListener('prettyprint', function(e) {\n window.dispatchEvent(new CustomEvent('prettyprint:cb', {\n detail: prettyPrintOne(e.detail)\n }));\n}, false);"); }
id = g.BOARD.ID;
if (id === 'g') {
$.globalEval('window.addEventListener(\'prettyprint\', function(e) {\n window.dispatchEvent(new CustomEvent(\'prettyprint:cb\', {\n detail: prettyPrintOne(e.detail)\n }));\n}, false);');
Post.callbacks.push({ Post.callbacks.push({
name: 'Parse /g/ code', name: 'Parse /g/ code',
cb: this.code cb: this.code
}); });
} }
if (board === 'sci') { if (id === 'sci') {
$.globalEval("window.addEventListener('jsmath', function(e) {\n if (jsMath.loaded) {\n // process one post\n jsMath.ProcessBeforeShowing(document.getElementById(e.detail));\n } else {\n // load jsMath and process whole document\n jsMath.Autoload.Script.Push('ProcessBeforeShowing', [null]);\n jsMath.Autoload.LoadJsMath();\n }\n}, false);"); $.globalEval('window.addEventListener(\'jsmath\', function(e) {\n if (!jsMath) return;\n // process one post\n jsMath.ProcessBeforeShowing(e.target);\n } else if (jsMath.Autoload && jsMath.Autoload.checked) {\n // load jsMath and process whole document\n jsMath.Autoload.Script.Push(\'ProcessBeforeShowing\', [null]);\n jsMath.Autoload.LoadJsMath();\n }\n}, false);');
return Post.callbacks.push({ Post.callbacks.push({
name: 'Parse /sci/ math',
cb: this.math
});
CatalogThread.callbacks.push({
name: 'Parse /sci/ math', name: 'Parse /sci/ math',
cb: this.math cb: this.math
}); });
} }
return Main.ready(function() {
return $.globalEval('(function() {\n window.clickable_ids = false;\n var nodes = document.querySelectorAll(\'.posteruid, .capcode\');\n for (var i = 0; i < nodes.length; i++) {\n nodes[i].removeEventListener("click", window.idClick, false);\n }\n window.removeEventListener("message", Report.onMessage, false);\n})();');
});
}, },
code: function() { code: function() {
var apply, pre, _i, _len, _ref; var apply, pre, _i, _len, _ref;
@ -15121,7 +15132,8 @@
return; return;
} }
apply = function(e) { apply = function(e) {
return pre.innerHTML = e.detail; pre.innerHTML = e.detail;
return $.addClass(pre, 'prettyprinted');
}; };
$.on(window, 'prettyprint:cb', apply); $.on(window, 'prettyprint:cb', apply);
_ref = $$('.prettyprint:not(.prettyprinted)', this.nodes.comment); _ref = $$('.prettyprint:not(.prettyprinted)', this.nodes.comment);
@ -15132,16 +15144,25 @@
$.off(window, 'prettyprint:cb', apply); $.off(window, 'prettyprint:cb', apply);
}, },
math: function() { math: function() {
if (this.isClone || !$('.math', this.nodes.comment)) { if ((this.isClone && doc.contains(this.origin.nodes.root)) || !$('.math', this.nodes.comment)) {
return; return;
} }
return $.event('jsmath', this.nodes.post.id, window); return $.asap(((function(_this) {
return function() {
return doc.contains(_this.nodes.comment);
};
})(this)), (function(_this) {
return function() {
return $.event('jsmath', null, _this.nodes.comment);
};
})(this));
} }
}; };
IDColor = { IDColor = {
init: function() { init: function() {
if (!Conf['Color User IDs']) { var _ref;
if (!(((_ref = g.VIEW) === 'index' || _ref === 'thread') && Conf['Color User IDs'])) {
return; return;
} }
this.ids = { this.ids = {
@ -15153,26 +15174,32 @@
}); });
}, },
node: function() { node: function() {
var rgb, span, uid; var rgb, span, style, uid;
if (this.isClone || !((uid = this.info.uniqueID) && (span = $('span.hand', this.nodes.uniqueID)))) { if (this.isClone || !((uid = this.info.uniqueID) && (span = $('span.hand', this.nodes.uniqueID)))) {
return; return;
} }
rgb = IDColor.ids[uid] || IDColor.compute(uid); rgb = IDColor.ids[uid] || IDColor.compute(uid);
span.style.color = rgb[3]; style = span.style;
span.style.backgroundColor = "rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + ")"; 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, i, rgb; var hash, rgb;
i = 1; hash = IDColor.hash(uid);
hash = uid.charCodeAt(0);
while (i < 8) {
hash = (hash << 5) - hash + uid.charCodeAt(i++);
}
rgb = [(hash >> 24) & 0xFF, (hash >> 16) & 0xFF, (hash >> 8) & 0xFF]; 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'); rgb.push((rgb[0] * 0.299 + rgb[1] * 0.587 + rgb[2] * 0.114) > 125 ? '#000' : '#fff');
return this.ids[uid] = rgb; return this.ids[uid] = rgb;
},
hash: function(uid) {
var i, msg;
msg = 0;
i = 0;
while (i < 8) {
msg = (msg << 5) - msg + uid.charCodeAt(i++);
}
return msg;
} }
}; };

View File

@ -1,6 +1,6 @@
Dice = Dice =
init: -> init: ->
return if g.BOARD.ID isnt 'tg' or !Conf['Show Dice Roll'] return unless g.VIEW in ['index', 'thread'] and g.BOARD.ID is 'tg' and Conf['Show Dice Roll']
Post.callbacks.push Post.callbacks.push
name: 'Show Dice Roll' name: 'Show Dice Roll'
cb: @node cb: @node

View File

@ -1,42 +1,65 @@
Fourchan = Fourchan =
init: -> init: ->
board = g.BOARD.ID return unless g.VIEW in ['index', 'thread']
if board is 'g'
$.globalEval """ id = g.BOARD.ID
if id is 'g'
$.globalEval '''
window.addEventListener('prettyprint', function(e) { window.addEventListener('prettyprint', function(e) {
window.dispatchEvent(new CustomEvent('prettyprint:cb', { window.dispatchEvent(new CustomEvent('prettyprint:cb', {
detail: prettyPrintOne(e.detail) detail: prettyPrintOne(e.detail)
})); }));
}, false); }, false);
""" '''
Post.callbacks.push Post.callbacks.push
name: 'Parse /g/ code' name: 'Parse /g/ code'
cb: @code cb: @code
if board is 'sci' if id is 'sci'
# https://github.com/MayhemYDG/4chan-x/issues/645#issuecomment-13704562 # https://github.com/MayhemYDG/4chan-x/issues/645#issuecomment-13704562
$.globalEval """ $.globalEval '''
window.addEventListener('jsmath', function(e) { window.addEventListener('jsmath', function(e) {
if (jsMath.loaded) { if (!jsMath) return;
// process one post // process one post
jsMath.ProcessBeforeShowing(document.getElementById(e.detail)); jsMath.ProcessBeforeShowing(e.target);
} else { } else if (jsMath.Autoload && jsMath.Autoload.checked) {
// load jsMath and process whole document // load jsMath and process whole document
jsMath.Autoload.Script.Push('ProcessBeforeShowing', [null]); jsMath.Autoload.Script.Push('ProcessBeforeShowing', [null]);
jsMath.Autoload.LoadJsMath(); jsMath.Autoload.LoadJsMath();
} }
}, false); }, false);
""" '''
Post.callbacks.push Post.callbacks.push
name: 'Parse /sci/ math' name: 'Parse /sci/ math'
cb: @math cb: @math
CatalogThread.callbacks.push
name: 'Parse /sci/ math'
cb: @math
# Disable 4chan's ID highlighting (replaced by IDHighlight) and reported post hiding.
Main.ready ->
$.globalEval '''
(function() {
window.clickable_ids = false;
var nodes = document.querySelectorAll('.posteruid, .capcode');
for (var i = 0; i < nodes.length; i++) {
nodes[i].removeEventListener("click", window.idClick, false);
}
window.removeEventListener("message", Report.onMessage, false);
})();
'''
code: -> code: ->
return if @isClone return if @isClone
apply = (e) -> pre.innerHTML = e.detail apply = (e) ->
pre.innerHTML = e.detail
$.addClass pre, 'prettyprinted'
$.on window, 'prettyprint:cb', apply $.on window, 'prettyprint:cb', apply
for pre in $$ '.prettyprint:not(.prettyprinted)', @nodes.comment for pre in $$ '.prettyprint:not(.prettyprinted)', @nodes.comment
$.event 'prettyprint', pre.innerHTML, window $.event 'prettyprint', pre.innerHTML, window
$.off window, 'prettyprint:cb', apply $.off window, 'prettyprint:cb', apply
return return
math: -> math: ->
return if @isClone or !$ '.math', @nodes.comment return if (@isClone and doc.contains @origin.nodes.root) or !$ '.math', @nodes.comment
$.event 'jsmath', @nodes.post.id, window $.asap (=> doc.contains @nodes.comment), =>
$.event 'jsmath', null, @nodes.comment

View File

@ -1,6 +1,6 @@
IDColor = IDColor =
init: -> init: ->
return if !Conf['Color User IDs'] return unless g.VIEW in ['index', 'thread'] and Conf['Color User IDs']
@ids = { @ids = {
Heaven: [0, 0, 0, '#fff'] Heaven: [0, 0, 0, '#fff']
} }
@ -15,17 +15,16 @@ IDColor =
rgb = IDColor.ids[uid] or IDColor.compute uid rgb = IDColor.ids[uid] or IDColor.compute uid
# Style the damn node. # Style the damn node.
span.style.color = rgb[3] {style} = span
span.style.backgroundColor = "rgb(#{rgb[0]},#{rgb[1]},#{rgb[2]})" style.color = rgb[3]
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) ->
# Convert chars to integers, bitshift and math to create a larger integer # Convert chars to integers, bitshift and math to create a larger integer
# Create a nice string of binary # Create a nice string of binary
i = 1 hash = IDColor.hash uid
hash = uid.charCodeAt 0
hash = (hash << 5) - hash + uid.charCodeAt i++ while i < 8
# Convert binary string to numerical values with bitshift and '&' truncation. # Convert binary string to numerical values with bitshift and '&' truncation.
rgb = [ rgb = [
@ -41,4 +40,11 @@ IDColor =
'#fff' '#fff'
# Cache. # Cache.
@ids[uid] = rgb @ids[uid] = rgb
hash: (uid) ->
msg = 0
i = 0
while i < 8
msg = (msg << 5) - msg + uid.charCodeAt i++
msg