Start working on quote resurrection. See #253.
This commit is contained in:
parent
19d0617f4c
commit
c182e680a9
@ -73,7 +73,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var $, $$, Anonymize, AutoGif, DAY, ExpandComment, ExpandThread, Favicon, FileInfo, Filter, GetTitle, HOUR, ImageExpand, ImageHover, Keybinds, MINUTE, Main, NAMESPACE, Nav, Options, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, Redirect, ReplyHiding, ReportButton, RevealSpoilers, SECOND, Sauce, StrikethroughQuotes, ThreadHiding, ThreadStats, Threading, Time, TitlePost, Unread, Updater, VERSION, Watcher, conf, config, d, engine, flatten, g, key, log, qr, ui, val, _base;
|
var $, $$, Anonymize, AutoGif, DAY, DeadQuotes, ExpandComment, ExpandThread, Favicon, FileInfo, Filter, GetTitle, HOUR, ImageExpand, ImageHover, Keybinds, MINUTE, Main, NAMESPACE, Nav, Options, QuoteBacklink, QuoteCT, QuoteInline, QuoteOP, QuotePreview, Redirect, ReplyHiding, ReportButton, RevealSpoilers, SECOND, Sauce, StrikethroughQuotes, ThreadHiding, ThreadStats, Threading, Time, TitlePost, Unread, Updater, VERSION, Watcher, conf, config, d, engine, flatten, g, key, log, qr, ui, val, _base;
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
main: {
|
main: {
|
||||||
@ -132,6 +132,7 @@
|
|||||||
'Quote Highlighting': [true, 'Highlight the previewed post'],
|
'Quote Highlighting': [true, 'Highlight the previewed post'],
|
||||||
'Quote Inline': [true, 'Show quoted post inline on quote click'],
|
'Quote Inline': [true, 'Show quoted post inline on quote click'],
|
||||||
'Quote Preview': [true, 'Show quote content on hover'],
|
'Quote Preview': [true, 'Show quote content on hover'],
|
||||||
|
'Resurrect Quotes': [true, 'Bring dead links back to life'],
|
||||||
'Indicate OP quote': [true, 'Add \'(OP)\' to OP quotes'],
|
'Indicate OP quote': [true, 'Add \'(OP)\' to OP quotes'],
|
||||||
'Indicate Cross-thread Quotes': [true, 'Add \'(Cross-thread)\' to cross-threads quotes'],
|
'Indicate Cross-thread Quotes': [true, 'Add \'(Cross-thread)\' to cross-threads quotes'],
|
||||||
'Forward Hiding': [true, 'Hide original posts of inlined backlinks']
|
'Forward Hiding': [true, 'Hide original posts of inlined backlinks']
|
||||||
@ -402,9 +403,6 @@
|
|||||||
if (root == null) root = d.body;
|
if (root == null) root = d.body;
|
||||||
return d.evaluate(path, root, null, 8, null).singleNodeValue;
|
return d.evaluate(path, root, null, 8, null).singleNodeValue;
|
||||||
},
|
},
|
||||||
replace: function(root, el) {
|
|
||||||
return root.parentNode.replaceChild(el, root);
|
|
||||||
},
|
|
||||||
addClass: function(el, className) {
|
addClass: function(el, className) {
|
||||||
return el.classList.add(className);
|
return el.classList.add(className);
|
||||||
},
|
},
|
||||||
@ -439,6 +437,9 @@
|
|||||||
before: function(root, el) {
|
before: function(root, el) {
|
||||||
return root.parentNode.insertBefore($.nodes(el), root);
|
return root.parentNode.insertBefore($.nodes(el), root);
|
||||||
},
|
},
|
||||||
|
replace: function(root, el) {
|
||||||
|
return root.parentNode.replaceChild($.nodes(el), root);
|
||||||
|
},
|
||||||
el: function(tag, properties) {
|
el: function(tag, properties) {
|
||||||
var el;
|
var el;
|
||||||
el = d.createElement(tag);
|
el = d.createElement(tag);
|
||||||
@ -776,7 +777,8 @@
|
|||||||
if (conf['Quote Preview']) QuotePreview.node(post);
|
if (conf['Quote Preview']) QuotePreview.node(post);
|
||||||
if (conf['Quote Inline']) QuoteInline.node(post);
|
if (conf['Quote Inline']) QuoteInline.node(post);
|
||||||
if (conf['Indicate OP quote']) QuoteOP.node(post);
|
if (conf['Indicate OP quote']) QuoteOP.node(post);
|
||||||
if (conf['Indicate Cross-thread Quotes']) return QuoteCT.node(post);
|
if (conf['Indicate Cross-thread Quotes']) QuoteCT.node(post);
|
||||||
|
if (conf['Resurrect Quotes']) return DeadQuotes.node(post);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -3417,6 +3419,31 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DeadQuotes = {
|
||||||
|
init: function() {
|
||||||
|
return g.callbacks.push(this.node);
|
||||||
|
},
|
||||||
|
node: function(post) {
|
||||||
|
var data, i, index, node, nodes, quote, snapshot, text, _ref;
|
||||||
|
if (post["class"] === 'inline') return;
|
||||||
|
snapshot = d.evaluate('.//*[not(self::a) and contains(text(),">>")]/text()', post.el.lastChild, null, 7, null);
|
||||||
|
for (i = 0, _ref = snapshot.snapshotLength; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) {
|
||||||
|
node = snapshot.snapshotItem(i);
|
||||||
|
data = node.data;
|
||||||
|
if (!(quote = data.match(/>>(\d+)/))) continue;
|
||||||
|
index = data.indexOf(quote[0]);
|
||||||
|
nodes = [];
|
||||||
|
if (text = data.slice(0, index)) nodes.push($.tn(text));
|
||||||
|
nodes.push($.el('a', {
|
||||||
|
textContent: "" + quote[0] + "\u00A0(Dead)",
|
||||||
|
href: "#" + quote[1]
|
||||||
|
}));
|
||||||
|
if (text = data.slice(index + quote[0].length)) nodes.push($.tn(text));
|
||||||
|
$.replace(node, nodes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
ReportButton = {
|
ReportButton = {
|
||||||
init: function() {
|
init: function() {
|
||||||
this.a = $.el('a', {
|
this.a = $.el('a', {
|
||||||
@ -3913,6 +3940,7 @@
|
|||||||
if (conf['Quote Backlinks']) QuoteBacklink.init();
|
if (conf['Quote Backlinks']) QuoteBacklink.init();
|
||||||
if (conf['Indicate OP quote']) QuoteOP.init();
|
if (conf['Indicate OP quote']) QuoteOP.init();
|
||||||
if (conf['Indicate Cross-thread Quotes']) QuoteCT.init();
|
if (conf['Indicate Cross-thread Quotes']) QuoteCT.init();
|
||||||
|
if (conf['Resurrect Quotes']) DeadQuotes.init();
|
||||||
return $.ready(Main.ready);
|
return $.ready(Main.ready);
|
||||||
},
|
},
|
||||||
ready: function() {
|
ready: function() {
|
||||||
|
|||||||
@ -50,6 +50,7 @@ config =
|
|||||||
'Quote Highlighting': [true, 'Highlight the previewed post']
|
'Quote Highlighting': [true, 'Highlight the previewed post']
|
||||||
'Quote Inline': [true, 'Show quoted post inline on quote click']
|
'Quote Inline': [true, 'Show quoted post inline on quote click']
|
||||||
'Quote Preview': [true, 'Show quote content on hover']
|
'Quote Preview': [true, 'Show quote content on hover']
|
||||||
|
'Resurrect Quotes': [true, 'Bring dead links back to life']
|
||||||
'Indicate OP quote': [true, 'Add \'(OP)\' to OP quotes']
|
'Indicate OP quote': [true, 'Add \'(OP)\' to OP quotes']
|
||||||
'Indicate Cross-thread Quotes': [true, 'Add \'(Cross-thread)\' to cross-threads quotes']
|
'Indicate Cross-thread Quotes': [true, 'Add \'(Cross-thread)\' to cross-threads quotes']
|
||||||
'Forward Hiding': [true, 'Hide original posts of inlined backlinks']
|
'Forward Hiding': [true, 'Hide original posts of inlined backlinks']
|
||||||
@ -324,8 +325,6 @@ $.extend $,
|
|||||||
# XPathResult.ANY_UNORDERED_NODE_TYPE is 8
|
# XPathResult.ANY_UNORDERED_NODE_TYPE is 8
|
||||||
d.evaluate(path, root, null, 8, null).
|
d.evaluate(path, root, null, 8, null).
|
||||||
singleNodeValue
|
singleNodeValue
|
||||||
replace: (root, el) ->
|
|
||||||
root.parentNode.replaceChild el, root
|
|
||||||
addClass: (el, className) ->
|
addClass: (el, className) ->
|
||||||
el.classList.add className
|
el.classList.add className
|
||||||
removeClass: (el, className) ->
|
removeClass: (el, className) ->
|
||||||
@ -349,6 +348,8 @@ $.extend $,
|
|||||||
root.parentNode.insertBefore $.nodes(el), root.nextSibling
|
root.parentNode.insertBefore $.nodes(el), root.nextSibling
|
||||||
before: (root, el) ->
|
before: (root, el) ->
|
||||||
root.parentNode.insertBefore $.nodes(el), root
|
root.parentNode.insertBefore $.nodes(el), root
|
||||||
|
replace: (root, el) ->
|
||||||
|
root.parentNode.replaceChild $.nodes(el), root
|
||||||
el: (tag, properties) ->
|
el: (tag, properties) ->
|
||||||
el = d.createElement tag
|
el = d.createElement tag
|
||||||
$.extend el, properties if properties
|
$.extend el, properties if properties
|
||||||
@ -669,6 +670,8 @@ ExpandComment =
|
|||||||
QuoteOP.node post
|
QuoteOP.node post
|
||||||
if conf['Indicate Cross-thread Quotes']
|
if conf['Indicate Cross-thread Quotes']
|
||||||
QuoteCT.node post
|
QuoteCT.node post
|
||||||
|
if conf['Resurrect Quotes']
|
||||||
|
DeadQuotes.node post
|
||||||
|
|
||||||
ExpandThread =
|
ExpandThread =
|
||||||
init: ->
|
init: ->
|
||||||
@ -2806,6 +2809,35 @@ QuoteCT =
|
|||||||
$.add quote, $.tn '\u00A0(Cross-thread)'
|
$.add quote, $.tn '\u00A0(Cross-thread)'
|
||||||
return
|
return
|
||||||
|
|
||||||
|
DeadQuotes =
|
||||||
|
init: ->
|
||||||
|
g.callbacks.push @node
|
||||||
|
node: (post) ->
|
||||||
|
return if post.class is 'inline'
|
||||||
|
# XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE is 7
|
||||||
|
|
||||||
|
# We need to make sure we can quotify multiple links per text node
|
||||||
|
# We need to make sure that we don't try to quotify text like `>>text`
|
||||||
|
|
||||||
|
snapshot = d.evaluate './/*[not(self::a) and contains(text(),">>")]/text()', post.el.lastChild, null, 7, null
|
||||||
|
for i in [0...snapshot.snapshotLength]
|
||||||
|
node = snapshot.snapshotItem i
|
||||||
|
data = node.data
|
||||||
|
unless quote = data.match />>(\d+)/
|
||||||
|
continue
|
||||||
|
index = data.indexOf quote[0]
|
||||||
|
nodes = []
|
||||||
|
if text = data[0...index]
|
||||||
|
nodes.push $.tn text
|
||||||
|
nodes.push $.el 'a',
|
||||||
|
# \u00A0 is nbsp
|
||||||
|
textContent: "#{quote[0]}\u00A0(Dead)"
|
||||||
|
href: "##{quote[1]}" # Here be archive link
|
||||||
|
if text = data[index + quote[0].length...]
|
||||||
|
nodes.push $.tn text
|
||||||
|
$.replace node, nodes
|
||||||
|
return
|
||||||
|
|
||||||
ReportButton =
|
ReportButton =
|
||||||
init: ->
|
init: ->
|
||||||
@a = $.el 'a',
|
@a = $.el 'a',
|
||||||
@ -3230,6 +3262,9 @@ Main =
|
|||||||
if conf['Indicate Cross-thread Quotes']
|
if conf['Indicate Cross-thread Quotes']
|
||||||
QuoteCT.init()
|
QuoteCT.init()
|
||||||
|
|
||||||
|
if conf['Resurrect Quotes']
|
||||||
|
DeadQuotes.init()
|
||||||
|
|
||||||
$.ready Main.ready
|
$.ready Main.ready
|
||||||
|
|
||||||
ready: ->
|
ready: ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user