Tell 4chan to parse posts if we enabled 4chan's extension.
Add code/math parsing. Add math tags keybinds. Close #507.
This commit is contained in:
parent
88afacb8ee
commit
aa16428d78
@ -42,7 +42,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var $, $$, Anonymize, ArchiveLink, AutoGIF, Board, Build, Clone, Conf, Config, DeleteLink, DownloadLink, ExpandComment, ExpandThread, Favicon, FileInfo, Filter, Get, Header, ImageExpand, ImageHover, Keybinds, Main, Menu, Nav, Notification, Polyfill, Post, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, Quotify, Recursive, Redirect, RelativeDates, ReplyHiding, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, d, doc, g,
|
var $, $$, Anonymize, ArchiveLink, AutoGIF, Board, Build, Clone, Conf, Config, DeleteLink, DownloadLink, ExpandComment, ExpandThread, Favicon, FileInfo, Filter, Fourchan, Get, Header, ImageExpand, ImageHover, Keybinds, Main, Menu, Nav, Notification, Polyfill, Post, QR, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, Quotify, Recursive, Redirect, RelativeDates, ReplyHiding, ReportLink, RevealSpoilers, Sauce, Settings, Thread, ThreadExcerpt, ThreadHiding, ThreadStats, ThreadUpdater, ThreadWatcher, Time, UI, Unread, d, doc, g,
|
||||||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
|
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; },
|
||||||
__hasProp = {}.hasOwnProperty,
|
__hasProp = {}.hasOwnProperty,
|
||||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
||||||
@ -146,6 +146,7 @@
|
|||||||
'Close': ['Esc', 'Close Settings, Notifications or QR.'],
|
'Close': ['Esc', 'Close Settings, Notifications or QR.'],
|
||||||
'Spoiler tags': ['Ctrl+s', 'Insert spoiler tags.'],
|
'Spoiler tags': ['Ctrl+s', 'Insert spoiler tags.'],
|
||||||
'Code tags': ['Alt+c', 'Insert code tags.'],
|
'Code tags': ['Alt+c', 'Insert code tags.'],
|
||||||
|
'Math tags': ['Alt+m', 'Insert math tags.'],
|
||||||
'Submit QR': ['Alt+s', 'Submit post.'],
|
'Submit QR': ['Alt+s', 'Submit post.'],
|
||||||
'Watch': ['w', 'Watch thread.'],
|
'Watch': ['w', 'Watch thread.'],
|
||||||
'Update': ['u', 'Update the thread now.'],
|
'Update': ['u', 'Update the thread now.'],
|
||||||
@ -1158,6 +1159,60 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Fourchan = {
|
||||||
|
init: function() {
|
||||||
|
var board;
|
||||||
|
if (g.VIEW === 'catalog') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
board = g.BOARD.ID;
|
||||||
|
if (board === 'g') {
|
||||||
|
Post.prototype.callbacks.push({
|
||||||
|
name: 'Parse /g/ code',
|
||||||
|
cb: this.code
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (board === 'sci') {
|
||||||
|
return Post.prototype.callbacks.push({
|
||||||
|
name: 'Parse /sci/ math',
|
||||||
|
cb: this.math
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
code: function() {
|
||||||
|
var pre, _i, _len, _ref;
|
||||||
|
if (this.isClone) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_ref = $$('.prettyprint', this.nodes.comment);
|
||||||
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
|
pre = _ref[_i];
|
||||||
|
pre.innerHTML = $.unsafeWindow.prettyPrintOne(pre.innerHTML);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
math: function() {
|
||||||
|
var jsMath;
|
||||||
|
if (this.isClone || !$('.math', this.nodes.comment)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
jsMath = $.unsafeWindow.jsMath;
|
||||||
|
if (jsMath) {
|
||||||
|
if (jsMath.loaded) {
|
||||||
|
return jsMath.ProcessBeforeShowing(this.nodes.post);
|
||||||
|
} else {
|
||||||
|
return $.globalEval("jsMath.Autoload.Script.Push('ProcessBeforeShowing', [null]);\njsMath.Autoload.LoadJsMath();");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
parseThread: function(threadID, offset, limit) {
|
||||||
|
return $.event('4chanParsingDone', {
|
||||||
|
threadId: threadID,
|
||||||
|
offset: offset,
|
||||||
|
limit: limit
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
Filter = {
|
Filter = {
|
||||||
filters: {},
|
filters: {},
|
||||||
init: function() {
|
init: function() {
|
||||||
@ -2297,6 +2352,12 @@
|
|||||||
}
|
}
|
||||||
Keybinds.tags('code', target);
|
Keybinds.tags('code', target);
|
||||||
break;
|
break;
|
||||||
|
case Conf['Math tags']:
|
||||||
|
if (target.nodeName !== 'TEXTAREA') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Keybinds.tags('math', target);
|
||||||
|
break;
|
||||||
case Conf['Submit QR']:
|
case Conf['Submit QR']:
|
||||||
if (QR.el && !QR.status()) {
|
if (QR.el && !QR.status()) {
|
||||||
QR.submit();
|
QR.submit();
|
||||||
@ -4323,7 +4384,13 @@
|
|||||||
QuoteOP.node.call(post);
|
QuoteOP.node.call(post);
|
||||||
}
|
}
|
||||||
if (Conf['Mark Cross-thread Quotes']) {
|
if (Conf['Mark Cross-thread Quotes']) {
|
||||||
return QuoteCT.node.call(post);
|
QuoteCT.node.call(post);
|
||||||
|
}
|
||||||
|
if (g.BOARD.ID === 'g') {
|
||||||
|
Fourchan.code.call(post);
|
||||||
|
}
|
||||||
|
if (g.BOARD.ID === 'sci') {
|
||||||
|
return Fourchan.math.call(post);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -4434,7 +4501,12 @@
|
|||||||
nodes.push(node);
|
nodes.push(node);
|
||||||
}
|
}
|
||||||
Main.callbackNodes(Post, posts);
|
Main.callbackNodes(Post, posts);
|
||||||
return $.after(a, nodes);
|
$.after(a, nodes);
|
||||||
|
if (Conf['Enable 4chan\'s extension']) {
|
||||||
|
return $.unsafeWindow.Parser.parseThread(thread.ID, 1, nodes.length);
|
||||||
|
} else {
|
||||||
|
return Fourchan.parseThread(thread.ID, 1, nodes.length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -4907,10 +4979,15 @@
|
|||||||
if (scroll) {
|
if (scroll) {
|
||||||
nodes[0].scrollIntoView();
|
nodes[0].scrollIntoView();
|
||||||
}
|
}
|
||||||
$.event('4chanParsingDone', {
|
$.queueTask(function() {
|
||||||
threadId: ThreadUpdater.thread.ID,
|
var length, threadID;
|
||||||
offset: ThreadUpdater.root.children.length - count,
|
threadID = ThreadUpdater.thread.ID;
|
||||||
limit: ThreadUpdater.root.children.length
|
length = ThreadUpdater.root.children.length;
|
||||||
|
if (Conf['Enable 4chan\'s extension']) {
|
||||||
|
return $.unsafeWindow.Parser.parseThread(threadID, -count);
|
||||||
|
} else {
|
||||||
|
return Fourchan.parseThread(threadID, length - count, length);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return $.event('ThreadUpdate', {
|
return $.event('ThreadUpdate', {
|
||||||
@ -5883,6 +5960,7 @@
|
|||||||
return QR.response(this.response);
|
return QR.response(this.response);
|
||||||
},
|
},
|
||||||
onerror: function() {
|
onerror: function() {
|
||||||
|
delete QR.ajax;
|
||||||
QR.cooldown.auto = false;
|
QR.cooldown.auto = false;
|
||||||
QR.status();
|
QR.status();
|
||||||
return QR.error($.el('a', {
|
return QR.error($.el('a', {
|
||||||
@ -6381,6 +6459,7 @@
|
|||||||
initFeature('Polyfill', Polyfill);
|
initFeature('Polyfill', Polyfill);
|
||||||
initFeature('Header', Header);
|
initFeature('Header', Header);
|
||||||
initFeature('Settings', Settings);
|
initFeature('Settings', Settings);
|
||||||
|
initFeature('Fourchan thingies', Fourchan);
|
||||||
initFeature('Resurrect Quotes', Quotify);
|
initFeature('Resurrect Quotes', Quotify);
|
||||||
initFeature('Filter', Filter);
|
initFeature('Filter', Filter);
|
||||||
initFeature('Thread Hiding', ThreadHiding);
|
initFeature('Thread Hiding', ThreadHiding);
|
||||||
|
|||||||
@ -22,6 +22,7 @@ alpha
|
|||||||
Thread & Post Hiding Buttons can now be disabled in the settings.
|
Thread & Post Hiding Buttons can now be disabled in the settings.
|
||||||
Recursive Hiding will be automatically applied when manually hiding a post.
|
Recursive Hiding will be automatically applied when manually hiding a post.
|
||||||
Visible posts will not be taken into account towards the unread count.
|
Visible posts will not be taken into account towards the unread count.
|
||||||
|
Added [math] tags keybind.
|
||||||
Fix Chrome's install warning saying that 4chan X would execute on all domains.
|
Fix Chrome's install warning saying that 4chan X would execute on all domains.
|
||||||
Fix Quote Backlinks not affecting inlined quotes.
|
Fix Quote Backlinks not affecting inlined quotes.
|
||||||
Fix Quote Highlighting not affecting inlined quotes.
|
Fix Quote Highlighting not affecting inlined quotes.
|
||||||
|
|||||||
@ -136,6 +136,7 @@ Config =
|
|||||||
'Close': ['Esc', 'Close Settings, Notifications or QR.']
|
'Close': ['Esc', 'Close Settings, Notifications or QR.']
|
||||||
'Spoiler tags': ['Ctrl+s', 'Insert spoiler tags.']
|
'Spoiler tags': ['Ctrl+s', 'Insert spoiler tags.']
|
||||||
'Code tags': ['Alt+c', 'Insert code tags.']
|
'Code tags': ['Alt+c', 'Insert code tags.']
|
||||||
|
'Math tags': ['Alt+m', 'Insert math tags.']
|
||||||
'Submit QR': ['Alt+s', 'Submit post.']
|
'Submit QR': ['Alt+s', 'Submit post.']
|
||||||
# Thread related
|
# Thread related
|
||||||
'Watch': ['w', 'Watch thread.']
|
'Watch': ['w', 'Watch thread.']
|
||||||
|
|||||||
@ -151,6 +151,47 @@ Settings =
|
|||||||
$.event 'CloseMenu'
|
$.event 'CloseMenu'
|
||||||
# Here be settings
|
# Here be settings
|
||||||
|
|
||||||
|
Fourchan =
|
||||||
|
init: ->
|
||||||
|
return if g.VIEW is 'catalog'
|
||||||
|
|
||||||
|
board = g.BOARD.ID
|
||||||
|
if board is 'g'
|
||||||
|
Post::callbacks.push
|
||||||
|
name: 'Parse /g/ code'
|
||||||
|
cb: @code
|
||||||
|
if board is 'sci'
|
||||||
|
Post::callbacks.push
|
||||||
|
name: 'Parse /sci/ math'
|
||||||
|
cb: @math
|
||||||
|
code: ->
|
||||||
|
return if @isClone
|
||||||
|
for pre in $$ '.prettyprint', @nodes.comment
|
||||||
|
pre.innerHTML = $.unsafeWindow.prettyPrintOne pre.innerHTML
|
||||||
|
return
|
||||||
|
math: ->
|
||||||
|
return if @isClone or !$ '.math', @nodes.comment
|
||||||
|
# https://github.com/MayhemYDG/4chan-x/issues/645#issuecomment-13704562
|
||||||
|
{jsMath} = $.unsafeWindow
|
||||||
|
if jsMath
|
||||||
|
if jsMath.loaded
|
||||||
|
# process one post
|
||||||
|
jsMath.ProcessBeforeShowing @nodes.post
|
||||||
|
else
|
||||||
|
# load jsMath and process whole document
|
||||||
|
# Yes this requires to be globalEval'd, don't ask me why.
|
||||||
|
$.globalEval """
|
||||||
|
jsMath.Autoload.Script.Push('ProcessBeforeShowing', [null]);
|
||||||
|
jsMath.Autoload.LoadJsMath();
|
||||||
|
"""
|
||||||
|
parseThread: (threadID, offset, limit) ->
|
||||||
|
# Fix /sci/
|
||||||
|
# Fix /g/
|
||||||
|
$.event '4chanParsingDone',
|
||||||
|
threadId: threadID
|
||||||
|
offset: offset
|
||||||
|
limit: limit
|
||||||
|
|
||||||
Filter =
|
Filter =
|
||||||
filters: {}
|
filters: {}
|
||||||
init: ->
|
init: ->
|
||||||
@ -1064,6 +1105,9 @@ Keybinds =
|
|||||||
when Conf['Code tags']
|
when Conf['Code tags']
|
||||||
return if target.nodeName isnt 'TEXTAREA'
|
return if target.nodeName isnt 'TEXTAREA'
|
||||||
Keybinds.tags 'code', target
|
Keybinds.tags 'code', target
|
||||||
|
when Conf['Math tags']
|
||||||
|
return if target.nodeName isnt 'TEXTAREA'
|
||||||
|
Keybinds.tags 'math', target
|
||||||
when Conf['Submit QR']
|
when Conf['Submit QR']
|
||||||
QR.submit() if QR.el and !QR.status()
|
QR.submit() if QR.el and !QR.status()
|
||||||
# Thread related
|
# Thread related
|
||||||
@ -2726,8 +2770,10 @@ ExpandComment =
|
|||||||
QuoteOP.node.call post
|
QuoteOP.node.call post
|
||||||
if Conf['Mark Cross-thread Quotes']
|
if Conf['Mark Cross-thread Quotes']
|
||||||
QuoteCT.node.call post
|
QuoteCT.node.call post
|
||||||
# XXX g code
|
if g.BOARD.ID is 'g'
|
||||||
# XXX sci math
|
Fourchan.code.call post
|
||||||
|
if g.BOARD.ID is 'sci'
|
||||||
|
Fourchan.math.call post
|
||||||
|
|
||||||
ExpandThread =
|
ExpandThread =
|
||||||
init: ->
|
init: ->
|
||||||
@ -2813,6 +2859,12 @@ ExpandThread =
|
|||||||
Main.callbackNodes Post, posts
|
Main.callbackNodes Post, posts
|
||||||
$.after a, nodes
|
$.after a, nodes
|
||||||
|
|
||||||
|
# Enable 4chan features.
|
||||||
|
if Conf['Enable 4chan\'s extension']
|
||||||
|
$.unsafeWindow.Parser.parseThread thread.ID, 1, nodes.length
|
||||||
|
else
|
||||||
|
Fourchan.parseThread thread.ID, 1, nodes.length
|
||||||
|
|
||||||
ThreadExcerpt =
|
ThreadExcerpt =
|
||||||
init: ->
|
init: ->
|
||||||
return if g.VIEW isnt 'thread' or !Conf['Thread Excerpt']
|
return if g.VIEW isnt 'thread' or !Conf['Thread Excerpt']
|
||||||
@ -3200,10 +3252,14 @@ ThreadUpdater =
|
|||||||
if scroll
|
if scroll
|
||||||
nodes[0].scrollIntoView()
|
nodes[0].scrollIntoView()
|
||||||
|
|
||||||
$.event '4chanParsingDone',
|
$.queueTask ->
|
||||||
threadId: ThreadUpdater.thread.ID
|
# Enable 4chan features.
|
||||||
offset: ThreadUpdater.root.children.length - count
|
threadID = ThreadUpdater.thread.ID
|
||||||
limit: ThreadUpdater.root.children.length
|
{length} = ThreadUpdater.root.children
|
||||||
|
if Conf['Enable 4chan\'s extension']
|
||||||
|
$.unsafeWindow.Parser.parseThread threadID, -count
|
||||||
|
else
|
||||||
|
Fourchan.parseThread threadID, length - count, length
|
||||||
|
|
||||||
$.event 'ThreadUpdate',
|
$.event 'ThreadUpdate',
|
||||||
404: false
|
404: false
|
||||||
|
|||||||
@ -307,6 +307,7 @@ Main =
|
|||||||
initFeature 'Polyfill', Polyfill
|
initFeature 'Polyfill', Polyfill
|
||||||
initFeature 'Header', Header
|
initFeature 'Header', Header
|
||||||
initFeature 'Settings', Settings
|
initFeature 'Settings', Settings
|
||||||
|
initFeature 'Fourchan thingies', Fourchan
|
||||||
initFeature 'Resurrect Quotes', Quotify
|
initFeature 'Resurrect Quotes', Quotify
|
||||||
initFeature 'Filter', Filter
|
initFeature 'Filter', Filter
|
||||||
initFeature 'Thread Hiding', ThreadHiding
|
initFeature 'Thread Hiding', ThreadHiding
|
||||||
|
|||||||
@ -705,6 +705,7 @@ QR =
|
|||||||
onload: ->
|
onload: ->
|
||||||
QR.response @response
|
QR.response @response
|
||||||
onerror: ->
|
onerror: ->
|
||||||
|
delete QR.ajax
|
||||||
# Connection error, or
|
# Connection error, or
|
||||||
# CORS disabled error on www.4chan.org/banned
|
# CORS disabled error on www.4chan.org/banned
|
||||||
QR.cooldown.auto = false
|
QR.cooldown.auto = false
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user