Small backpedalling on some design decisions
This commit is contained in:
parent
541454d45a
commit
ed9febf9f1
@ -6591,20 +6591,23 @@
|
|||||||
|
|
||||||
Linkify = {
|
Linkify = {
|
||||||
init: function() {
|
init: function() {
|
||||||
if (g.VIEW === 'catalog') {
|
if (g.VIEW === 'catalog' || !Conf['Linkify']) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.regString = Conf['Allow False Positives'] ? /(\b([a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]|[-a-z0-9]+\.[a-z]|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]|[a-z]{3,}:[a-z0-9?]|[\S]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi : /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi;
|
this.regString = Conf['Allow False Positives'] ? /(\b([a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]|[-a-z0-9]+\.[a-z]|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]|[a-z]{3,}:[a-z0-9?]|[\S]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi : /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi;
|
||||||
if (Conf['Comment Expansion']) {
|
if (Conf['Comment Expansion']) {
|
||||||
ExpandComment.callbacks.push(this.node);
|
ExpandComment.callbacks.push(this.node);
|
||||||
}
|
}
|
||||||
|
if (Conf['Title Link']) {
|
||||||
|
$.sync('CachedTitles', Linkify.titleSync);
|
||||||
|
}
|
||||||
return Post.prototype.callbacks.push({
|
return Post.prototype.callbacks.push({
|
||||||
name: 'Linkify',
|
name: 'Linkify',
|
||||||
cb: this.node
|
cb: this.node
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
node: function() {
|
node: function() {
|
||||||
var data, embedder, i, len, link, links, match, node, range, snapshot, _i, _j, _k, _len, _len1, _len2, _ref, _ref1;
|
var data, embedder, i, len, match, node, range, snapshot, _i, _j, _len, _len1, _ref, _ref1;
|
||||||
|
|
||||||
if (this.isClone && Conf['Embedding']) {
|
if (this.isClone && Conf['Embedding']) {
|
||||||
_ref = $$('.embedder', this.nodes.comment);
|
_ref = $$('.embedder', this.nodes.comment);
|
||||||
@ -6617,40 +6620,32 @@
|
|||||||
snapshot = $.X('.//text()', this.nodes.comment);
|
snapshot = $.X('.//text()', this.nodes.comment);
|
||||||
i = -1;
|
i = -1;
|
||||||
len = snapshot.snapshotLength;
|
len = snapshot.snapshotLength;
|
||||||
links = [];
|
|
||||||
while (++i < len) {
|
while (++i < len) {
|
||||||
node = snapshot.snapshotItem(i);
|
node = snapshot.snapshotItem(i);
|
||||||
data = node.data;
|
data = node.data;
|
||||||
if (match = data.match(Linkify.regString)) {
|
if (match = data.match(Linkify.regString)) {
|
||||||
links.pushArrays(Linkify.gatherLinks(match, node));
|
Linkify.gatherLinks(match, node, this);
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Conf['Linkify']) {
|
|
||||||
for (_j = 0, _len1 = links.length; _j < _len1; _j++) {
|
|
||||||
range = links[_j];
|
|
||||||
this.nodes.links.push(Linkify.makeLink(range));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!(Conf['Embedding'] || Conf['Link Title'])) {
|
if (!(Conf['Embedding'] || Conf['Link Title'])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_ref1 = this.nodes.links || links;
|
_ref1 = this.nodes.links;
|
||||||
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
|
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
||||||
range = _ref1[_k];
|
range = _ref1[_j];
|
||||||
if (link = Linkify.services(range)) {
|
if (data = Linkify.services(range)) {
|
||||||
if (Conf['Embedding']) {
|
if (Conf['Embedding']) {
|
||||||
Linkify.embed(link);
|
Linkify.embed(data);
|
||||||
}
|
}
|
||||||
if (Conf['Link Title']) {
|
if (Conf['Link Title']) {
|
||||||
Linkify.title(link);
|
Linkify.title(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
gatherLinks: function(match, node) {
|
gatherLinks: function(match, node, post) {
|
||||||
var data, i, len, len2, link, links, next, range, result;
|
var data, i, len, len2, link, next, range, result;
|
||||||
|
|
||||||
links = [];
|
|
||||||
i = 0;
|
i = 0;
|
||||||
len = match.length;
|
len = match.length;
|
||||||
data = node.data;
|
data = node.data;
|
||||||
@ -6658,14 +6653,14 @@
|
|||||||
range = document.createRange();
|
range = document.createRange();
|
||||||
range.setStart(node, len2 = data.indexOf(link));
|
range.setStart(node, len2 = data.indexOf(link));
|
||||||
range.setEnd(node, len2 + link.length);
|
range.setEnd(node, len2 + link.length);
|
||||||
links.push(range);
|
post.nodes.links.push(Linkify.makeLink(range));
|
||||||
}
|
}
|
||||||
range = document.createRange();
|
range = document.createRange();
|
||||||
range.setStart(node, len = data.indexOf(link));
|
range.setStart(node, len = data.indexOf(link));
|
||||||
if ((data.length - (len += link.length)) > 0) {
|
if ((data.length - (len += link.length)) > 0) {
|
||||||
range.setEnd(node, len);
|
range.setEnd(node, len);
|
||||||
links.push(range);
|
post.nodes.links.push(Linkify.makeLink(range));
|
||||||
return links;
|
return;
|
||||||
}
|
}
|
||||||
while ((next = node.nextSibling) && next.nodeName.toLowerCase() !== 'br') {
|
while ((next = node.nextSibling) && next.nodeName.toLowerCase() !== 'br') {
|
||||||
node = next;
|
node = next;
|
||||||
@ -6680,8 +6675,7 @@
|
|||||||
}
|
}
|
||||||
range.setEnd(node, node.length);
|
range.setEnd(node, node.length);
|
||||||
}
|
}
|
||||||
links.push(range);
|
post.nodes.links.push(Linkify.makeLink(range));
|
||||||
return links;
|
|
||||||
},
|
},
|
||||||
makeLink: function(range) {
|
makeLink: function(range) {
|
||||||
var a, link;
|
var a, link;
|
||||||
@ -6700,16 +6694,13 @@
|
|||||||
services: function(link) {
|
services: function(link) {
|
||||||
var href, key, match, type, _ref;
|
var href, key, match, type, _ref;
|
||||||
|
|
||||||
href = Conf['Linkify'] ? link.href : link.toString();
|
href = link.href;
|
||||||
_ref = Linkify.types;
|
_ref = Linkify.types;
|
||||||
for (key in _ref) {
|
for (key in _ref) {
|
||||||
type = _ref[key];
|
type = _ref[key];
|
||||||
if (!(match = type.regExp.exec(href))) {
|
if (!(match = type.regExp.exec(href))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!Conf['Linkify']) {
|
|
||||||
link = Linkify.makeLink(link);
|
|
||||||
}
|
|
||||||
return [key, match[1], match[2], link];
|
return [key, match[1], match[2], link];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -6730,6 +6721,36 @@
|
|||||||
$.on(embed, 'click', Linkify.cb.toggle);
|
$.on(embed, 'click', Linkify.cb.toggle);
|
||||||
return $.after(link, [$.tn(' '), embed]);
|
return $.after(link, [$.tn(' '), embed]);
|
||||||
},
|
},
|
||||||
|
title: function(data) {
|
||||||
|
var err, key, link, options, service, title, titles, uid;
|
||||||
|
|
||||||
|
key = data[0], uid = data[1], options = data[2], link = data[3];
|
||||||
|
service = Linkify.types[key].title;
|
||||||
|
titles = Conf['CachedTitles'];
|
||||||
|
if (title = titles[uid]) {
|
||||||
|
link.textContent = title[0];
|
||||||
|
if (Conf['Embedding']) {
|
||||||
|
return link.nextElementSibling.dataset.title = title[0];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
$.cache(service.api(uid), function() {
|
||||||
|
return title = Linkify.cb.title.apply(this, [data]);
|
||||||
|
});
|
||||||
|
} catch (_error) {
|
||||||
|
err = _error;
|
||||||
|
link.innerHTML = "[" + key + "] <span class=warning>Title Link Blocked</span> (are you using NoScript?)</a>";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (title) {
|
||||||
|
titles[uid] = [title, Date.now()];
|
||||||
|
return $.set('CachedTitles', titles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
titleSync: function(value) {
|
||||||
|
return Conf['CachedTitles'] = value;
|
||||||
|
},
|
||||||
cb: {
|
cb: {
|
||||||
toggle: function() {
|
toggle: function() {
|
||||||
var el, embed;
|
var el, embed;
|
||||||
@ -6785,39 +6806,6 @@
|
|||||||
}).call(this);
|
}).call(this);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
title: function(data) {
|
|
||||||
var key, link, options, service, title, titles, uid;
|
|
||||||
|
|
||||||
key = data[0], uid = data[1], options = data[2], link = data[3];
|
|
||||||
titles = {};
|
|
||||||
service = Linkify.types[key].title;
|
|
||||||
title = "";
|
|
||||||
return $.get('CachedTitles', {}, function(item) {
|
|
||||||
var err;
|
|
||||||
|
|
||||||
titles = item['CachedTitles'];
|
|
||||||
if (title = titles[uid]) {
|
|
||||||
link.textContent = title[0];
|
|
||||||
if (Conf['Embedding']) {
|
|
||||||
link.nextElementSibling.dataset.title = title[0];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
$.cache(service.api(uid), function() {
|
|
||||||
return title = Linkify.cb.title.apply(this, [data]);
|
|
||||||
});
|
|
||||||
} catch (_error) {
|
|
||||||
err = _error;
|
|
||||||
link.innerHTML = "[" + key + "] <span class=warning>Title Link Blocked</span> (are you using NoScript?)</a>";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (title) {
|
|
||||||
titles[uid] = [title, Date.now()];
|
|
||||||
return $.set('CachedTitles', titles);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
types: {
|
types: {
|
||||||
YouTube: {
|
YouTube: {
|
||||||
regExp: /.*(?:youtu.be\/|youtube.*v=|youtube.*\/embed\/|youtube.*\/v\/|youtube.*videos\/)([^#\&\?]*)\??(t\=.*)?/,
|
regExp: /.*(?:youtu.be\/|youtube.*v=|youtube.*\/embed\/|youtube.*\/v\/|youtube.*videos\/)([^#\&\?]*)\??(t\=.*)?/,
|
||||||
@ -14549,7 +14537,8 @@
|
|||||||
'Enabled Mascots nsfw': [],
|
'Enabled Mascots nsfw': [],
|
||||||
'Deleted Mascots': [],
|
'Deleted Mascots': [],
|
||||||
'Hidden Categories': ["Questionable"],
|
'Hidden Categories': ["Questionable"],
|
||||||
'selectedArchives': {}
|
'selectedArchives': {},
|
||||||
|
'CachedTitles': {}
|
||||||
});
|
});
|
||||||
return $.get(Conf, Main.initFeatures);
|
return $.get(Conf, Main.initFeatures);
|
||||||
},
|
},
|
||||||
@ -14557,10 +14546,6 @@
|
|||||||
var init, pathname, _ref;
|
var init, pathname, _ref;
|
||||||
|
|
||||||
Conf = items;
|
Conf = items;
|
||||||
if (Conf['Post Form Style'] === 'transparent fade') {
|
|
||||||
$.set('Post Form Style', Conf['Post Form Style'] = 'fixed');
|
|
||||||
$.set('Transparent Post Form', Conf['Transparent Post Form'] = true);
|
|
||||||
}
|
|
||||||
pathname = location.pathname.split('/');
|
pathname = location.pathname.split('/');
|
||||||
g.BOARD = new Board(pathname[1]);
|
g.BOARD = new Board(pathname[1]);
|
||||||
g.VIEW = (function() {
|
g.VIEW = (function() {
|
||||||
|
|||||||
@ -6594,20 +6594,23 @@
|
|||||||
|
|
||||||
Linkify = {
|
Linkify = {
|
||||||
init: function() {
|
init: function() {
|
||||||
if (g.VIEW === 'catalog') {
|
if (g.VIEW === 'catalog' || !Conf['Linkify']) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.regString = Conf['Allow False Positives'] ? /(\b([a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]|[-a-z0-9]+\.[a-z]|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]|[a-z]{3,}:[a-z0-9?]|[\S]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi : /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi;
|
this.regString = Conf['Allow False Positives'] ? /(\b([a-z]+:\/\/|[a-z]{3,}\.[-a-z0-9]+\.[a-z]|[-a-z0-9]+\.[a-z]|[0-9]+\.[0-9]+\.[0-9]+\.[0-9]|[a-z]{3,}:[a-z0-9?]|[\S]+@[a-z0-9.-]+\.[a-z0-9])[^\s'"]+)/gi : /(((magnet|mailto)\:|(www\.)|(news|(ht|f)tp(s?))\:\/\/){1}\S+)/gi;
|
||||||
if (Conf['Comment Expansion']) {
|
if (Conf['Comment Expansion']) {
|
||||||
ExpandComment.callbacks.push(this.node);
|
ExpandComment.callbacks.push(this.node);
|
||||||
}
|
}
|
||||||
|
if (Conf['Title Link']) {
|
||||||
|
$.sync('CachedTitles', Linkify.titleSync);
|
||||||
|
}
|
||||||
return Post.prototype.callbacks.push({
|
return Post.prototype.callbacks.push({
|
||||||
name: 'Linkify',
|
name: 'Linkify',
|
||||||
cb: this.node
|
cb: this.node
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
node: function() {
|
node: function() {
|
||||||
var data, embedder, i, len, link, links, match, node, range, snapshot, _i, _j, _k, _len, _len1, _len2, _ref, _ref1;
|
var data, embedder, i, len, match, node, range, snapshot, _i, _j, _len, _len1, _ref, _ref1;
|
||||||
|
|
||||||
if (this.isClone && Conf['Embedding']) {
|
if (this.isClone && Conf['Embedding']) {
|
||||||
_ref = $$('.embedder', this.nodes.comment);
|
_ref = $$('.embedder', this.nodes.comment);
|
||||||
@ -6620,40 +6623,32 @@
|
|||||||
snapshot = $.X('.//text()', this.nodes.comment);
|
snapshot = $.X('.//text()', this.nodes.comment);
|
||||||
i = -1;
|
i = -1;
|
||||||
len = snapshot.snapshotLength;
|
len = snapshot.snapshotLength;
|
||||||
links = [];
|
|
||||||
while (++i < len) {
|
while (++i < len) {
|
||||||
node = snapshot.snapshotItem(i);
|
node = snapshot.snapshotItem(i);
|
||||||
data = node.data;
|
data = node.data;
|
||||||
if (match = data.match(Linkify.regString)) {
|
if (match = data.match(Linkify.regString)) {
|
||||||
links.pushArrays(Linkify.gatherLinks(match, node));
|
Linkify.gatherLinks(match, node, this);
|
||||||
}
|
|
||||||
}
|
|
||||||
if (Conf['Linkify']) {
|
|
||||||
for (_j = 0, _len1 = links.length; _j < _len1; _j++) {
|
|
||||||
range = links[_j];
|
|
||||||
this.nodes.links.push(Linkify.makeLink(range));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!(Conf['Embedding'] || Conf['Link Title'])) {
|
if (!(Conf['Embedding'] || Conf['Link Title'])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_ref1 = this.nodes.links || links;
|
_ref1 = this.nodes.links;
|
||||||
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
|
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
||||||
range = _ref1[_k];
|
range = _ref1[_j];
|
||||||
if (link = Linkify.services(range)) {
|
if (data = Linkify.services(range)) {
|
||||||
if (Conf['Embedding']) {
|
if (Conf['Embedding']) {
|
||||||
Linkify.embed(link);
|
Linkify.embed(data);
|
||||||
}
|
}
|
||||||
if (Conf['Link Title']) {
|
if (Conf['Link Title']) {
|
||||||
Linkify.title(link);
|
Linkify.title(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
gatherLinks: function(match, node) {
|
gatherLinks: function(match, node, post) {
|
||||||
var data, i, len, len2, link, links, next, range, result;
|
var data, i, len, len2, link, next, range, result;
|
||||||
|
|
||||||
links = [];
|
|
||||||
i = 0;
|
i = 0;
|
||||||
len = match.length;
|
len = match.length;
|
||||||
data = node.data;
|
data = node.data;
|
||||||
@ -6661,14 +6656,14 @@
|
|||||||
range = document.createRange();
|
range = document.createRange();
|
||||||
range.setStart(node, len2 = data.indexOf(link));
|
range.setStart(node, len2 = data.indexOf(link));
|
||||||
range.setEnd(node, len2 + link.length);
|
range.setEnd(node, len2 + link.length);
|
||||||
links.push(range);
|
post.nodes.links.push(Linkify.makeLink(range));
|
||||||
}
|
}
|
||||||
range = document.createRange();
|
range = document.createRange();
|
||||||
range.setStart(node, len = data.indexOf(link));
|
range.setStart(node, len = data.indexOf(link));
|
||||||
if ((data.length - (len += link.length)) > 0) {
|
if ((data.length - (len += link.length)) > 0) {
|
||||||
range.setEnd(node, len);
|
range.setEnd(node, len);
|
||||||
links.push(range);
|
post.nodes.links.push(Linkify.makeLink(range));
|
||||||
return links;
|
return;
|
||||||
}
|
}
|
||||||
while ((next = node.nextSibling) && next.nodeName.toLowerCase() !== 'br') {
|
while ((next = node.nextSibling) && next.nodeName.toLowerCase() !== 'br') {
|
||||||
node = next;
|
node = next;
|
||||||
@ -6683,8 +6678,7 @@
|
|||||||
}
|
}
|
||||||
range.setEnd(node, node.length);
|
range.setEnd(node, node.length);
|
||||||
}
|
}
|
||||||
links.push(range);
|
post.nodes.links.push(Linkify.makeLink(range));
|
||||||
return links;
|
|
||||||
},
|
},
|
||||||
makeLink: function(range) {
|
makeLink: function(range) {
|
||||||
var a, link;
|
var a, link;
|
||||||
@ -6703,16 +6697,13 @@
|
|||||||
services: function(link) {
|
services: function(link) {
|
||||||
var href, key, match, type, _ref;
|
var href, key, match, type, _ref;
|
||||||
|
|
||||||
href = Conf['Linkify'] ? link.href : link.toString();
|
href = link.href;
|
||||||
_ref = Linkify.types;
|
_ref = Linkify.types;
|
||||||
for (key in _ref) {
|
for (key in _ref) {
|
||||||
type = _ref[key];
|
type = _ref[key];
|
||||||
if (!(match = type.regExp.exec(href))) {
|
if (!(match = type.regExp.exec(href))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!Conf['Linkify']) {
|
|
||||||
link = Linkify.makeLink(link);
|
|
||||||
}
|
|
||||||
return [key, match[1], match[2], link];
|
return [key, match[1], match[2], link];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -6733,6 +6724,36 @@
|
|||||||
$.on(embed, 'click', Linkify.cb.toggle);
|
$.on(embed, 'click', Linkify.cb.toggle);
|
||||||
return $.after(link, [$.tn(' '), embed]);
|
return $.after(link, [$.tn(' '), embed]);
|
||||||
},
|
},
|
||||||
|
title: function(data) {
|
||||||
|
var err, key, link, options, service, title, titles, uid;
|
||||||
|
|
||||||
|
key = data[0], uid = data[1], options = data[2], link = data[3];
|
||||||
|
service = Linkify.types[key].title;
|
||||||
|
titles = Conf['CachedTitles'];
|
||||||
|
if (title = titles[uid]) {
|
||||||
|
link.textContent = title[0];
|
||||||
|
if (Conf['Embedding']) {
|
||||||
|
return link.nextElementSibling.dataset.title = title[0];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
$.cache(service.api(uid), function() {
|
||||||
|
return title = Linkify.cb.title.apply(this, [data]);
|
||||||
|
});
|
||||||
|
} catch (_error) {
|
||||||
|
err = _error;
|
||||||
|
link.innerHTML = "[" + key + "] <span class=warning>Title Link Blocked</span> (are you using NoScript?)</a>";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (title) {
|
||||||
|
titles[uid] = [title, Date.now()];
|
||||||
|
return $.set('CachedTitles', titles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
titleSync: function(value) {
|
||||||
|
return Conf['CachedTitles'] = value;
|
||||||
|
},
|
||||||
cb: {
|
cb: {
|
||||||
toggle: function() {
|
toggle: function() {
|
||||||
var el, embed;
|
var el, embed;
|
||||||
@ -6788,39 +6809,6 @@
|
|||||||
}).call(this);
|
}).call(this);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
title: function(data) {
|
|
||||||
var key, link, options, service, title, titles, uid;
|
|
||||||
|
|
||||||
key = data[0], uid = data[1], options = data[2], link = data[3];
|
|
||||||
titles = {};
|
|
||||||
service = Linkify.types[key].title;
|
|
||||||
title = "";
|
|
||||||
return $.get('CachedTitles', {}, function(item) {
|
|
||||||
var err;
|
|
||||||
|
|
||||||
titles = item['CachedTitles'];
|
|
||||||
if (title = titles[uid]) {
|
|
||||||
link.textContent = title[0];
|
|
||||||
if (Conf['Embedding']) {
|
|
||||||
link.nextElementSibling.dataset.title = title[0];
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
$.cache(service.api(uid), function() {
|
|
||||||
return title = Linkify.cb.title.apply(this, [data]);
|
|
||||||
});
|
|
||||||
} catch (_error) {
|
|
||||||
err = _error;
|
|
||||||
link.innerHTML = "[" + key + "] <span class=warning>Title Link Blocked</span> (are you using NoScript?)</a>";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (title) {
|
|
||||||
titles[uid] = [title, Date.now()];
|
|
||||||
return $.set('CachedTitles', titles);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
types: {
|
types: {
|
||||||
YouTube: {
|
YouTube: {
|
||||||
regExp: /.*(?:youtu.be\/|youtube.*v=|youtube.*\/embed\/|youtube.*\/v\/|youtube.*videos\/)([^#\&\?]*)\??(t\=.*)?/,
|
regExp: /.*(?:youtu.be\/|youtube.*v=|youtube.*\/embed\/|youtube.*\/v\/|youtube.*videos\/)([^#\&\?]*)\??(t\=.*)?/,
|
||||||
@ -14526,7 +14514,8 @@
|
|||||||
'Enabled Mascots nsfw': [],
|
'Enabled Mascots nsfw': [],
|
||||||
'Deleted Mascots': [],
|
'Deleted Mascots': [],
|
||||||
'Hidden Categories': ["Questionable"],
|
'Hidden Categories': ["Questionable"],
|
||||||
'selectedArchives': {}
|
'selectedArchives': {},
|
||||||
|
'CachedTitles': {}
|
||||||
});
|
});
|
||||||
return $.get(Conf, Main.initFeatures);
|
return $.get(Conf, Main.initFeatures);
|
||||||
},
|
},
|
||||||
@ -14534,10 +14523,6 @@
|
|||||||
var init, pathname, _ref;
|
var init, pathname, _ref;
|
||||||
|
|
||||||
Conf = items;
|
Conf = items;
|
||||||
if (Conf['Post Form Style'] === 'transparent fade') {
|
|
||||||
$.set('Post Form Style', Conf['Post Form Style'] = 'fixed');
|
|
||||||
$.set('Transparent Post Form', Conf['Transparent Post Form'] = true);
|
|
||||||
}
|
|
||||||
pathname = location.pathname.split('/');
|
pathname = location.pathname.split('/');
|
||||||
g.BOARD = new Board(pathname[1]);
|
g.BOARD = new Board(pathname[1]);
|
||||||
g.VIEW = (function() {
|
g.VIEW = (function() {
|
||||||
|
|||||||
@ -27,18 +27,13 @@ Main =
|
|||||||
'Deleted Mascots': []
|
'Deleted Mascots': []
|
||||||
'Hidden Categories': ["Questionable"]
|
'Hidden Categories': ["Questionable"]
|
||||||
'selectedArchives': {}
|
'selectedArchives': {}
|
||||||
|
'CachedTitles': {}
|
||||||
|
|
||||||
$.get Conf, Main.initFeatures
|
$.get Conf, Main.initFeatures
|
||||||
|
|
||||||
initFeatures: (items) ->
|
initFeatures: (items) ->
|
||||||
Conf = items
|
Conf = items
|
||||||
|
|
||||||
if Conf['Post Form Style'] is 'transparent fade'
|
|
||||||
# XXX Compatibility to break old option into new option(s)
|
|
||||||
# Remove by 2.2.x
|
|
||||||
$.set 'Post Form Style', Conf['Post Form Style'] = 'fixed'
|
|
||||||
$.set 'Transparent Post Form', Conf['Transparent Post Form'] = true
|
|
||||||
|
|
||||||
pathname = location.pathname.split '/'
|
pathname = location.pathname.split '/'
|
||||||
g.BOARD = new Board pathname[1]
|
g.BOARD = new Board pathname[1]
|
||||||
g.VIEW =
|
g.VIEW =
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
Linkify =
|
Linkify =
|
||||||
init: ->
|
init: ->
|
||||||
return if g.VIEW is 'catalog'
|
return if g.VIEW is 'catalog' or not Conf['Linkify']
|
||||||
|
|
||||||
@regString = if Conf['Allow False Positives']
|
@regString = if Conf['Allow False Positives']
|
||||||
///(
|
///(
|
||||||
@ -25,6 +25,9 @@ Linkify =
|
|||||||
if Conf['Comment Expansion']
|
if Conf['Comment Expansion']
|
||||||
ExpandComment.callbacks.push @node
|
ExpandComment.callbacks.push @node
|
||||||
|
|
||||||
|
if Conf['Title Link']
|
||||||
|
$.sync 'CachedTitles', Linkify.titleSync
|
||||||
|
|
||||||
Post::callbacks.push
|
Post::callbacks.push
|
||||||
name: 'Linkify'
|
name: 'Linkify'
|
||||||
cb: @node
|
cb: @node
|
||||||
@ -36,51 +39,43 @@ Linkify =
|
|||||||
return
|
return
|
||||||
|
|
||||||
snapshot = $.X './/text()', @nodes.comment
|
snapshot = $.X './/text()', @nodes.comment
|
||||||
i = -1
|
i = -1
|
||||||
len = snapshot.snapshotLength
|
len = snapshot.snapshotLength
|
||||||
links = []
|
|
||||||
|
|
||||||
while ++i < len
|
while ++i < len
|
||||||
node = snapshot.snapshotItem i
|
node = snapshot.snapshotItem i
|
||||||
data = node.data
|
data = node.data
|
||||||
|
|
||||||
if match = data.match Linkify.regString
|
if match = data.match Linkify.regString
|
||||||
links.pushArrays Linkify.gatherLinks match, node
|
Linkify.gatherLinks match, node, @
|
||||||
|
|
||||||
if Conf['Linkify']
|
|
||||||
for range in links
|
|
||||||
@nodes.links.push Linkify.makeLink range
|
|
||||||
|
|
||||||
return unless Conf['Embedding'] or Conf['Link Title']
|
return unless Conf['Embedding'] or Conf['Link Title']
|
||||||
|
|
||||||
for range in @nodes.links or links
|
for range in @nodes.links
|
||||||
if link = Linkify.services range
|
if data = Linkify.services range
|
||||||
if Conf['Embedding']
|
Linkify.embed data if Conf['Embedding']
|
||||||
Linkify.embed link
|
Linkify.title data if Conf['Link Title']
|
||||||
if Conf['Link Title']
|
|
||||||
Linkify.title link
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
gatherLinks: (match, node) ->
|
gatherLinks: (match, node, post) ->
|
||||||
links = []
|
i = 0
|
||||||
i = 0
|
len = match.length
|
||||||
len = match.length
|
data = node.data
|
||||||
data = node.data
|
|
||||||
|
|
||||||
while (link = match[i++]) and i > len
|
while (link = match[i++]) and i > len
|
||||||
range = document.createRange();
|
range = document.createRange();
|
||||||
range.setStart node, len2 = data.indexOf link
|
range.setStart node, len2 = data.indexOf link
|
||||||
range.setEnd node, len2 + link.length
|
range.setEnd node, len2 + link.length
|
||||||
links.push range
|
post.nodes.links.push Linkify.makeLink range
|
||||||
|
|
||||||
range = document.createRange()
|
range = document.createRange()
|
||||||
range.setStart node, len = data.indexOf link
|
range.setStart node, len = data.indexOf link
|
||||||
|
|
||||||
if (data.length - (len += link.length)) > 0
|
if (data.length - (len += link.length)) > 0
|
||||||
range.setEnd node, len
|
range.setEnd node, len
|
||||||
links.push range
|
post.nodes.links.push Linkify.makeLink range
|
||||||
return links
|
return
|
||||||
|
|
||||||
while (next = node.nextSibling) and next.nodeName.toLowerCase() isnt 'br'
|
while (next = node.nextSibling) and next.nodeName.toLowerCase() isnt 'br'
|
||||||
node = next
|
node = next
|
||||||
@ -93,8 +88,8 @@ Linkify =
|
|||||||
node = node.previousSibling
|
node = node.previousSibling
|
||||||
range.setEnd node, node.length
|
range.setEnd node, node.length
|
||||||
|
|
||||||
links.push range
|
post.nodes.links.push Linkify.makeLink range
|
||||||
return links
|
return
|
||||||
|
|
||||||
makeLink: (range) ->
|
makeLink: (range) ->
|
||||||
link = range.toString()
|
link = range.toString()
|
||||||
@ -118,14 +113,10 @@ Linkify =
|
|||||||
return a
|
return a
|
||||||
|
|
||||||
services: (link) ->
|
services: (link) ->
|
||||||
href = if Conf['Linkify']
|
href = link.href
|
||||||
link.href
|
|
||||||
else
|
|
||||||
link.toString()
|
|
||||||
|
|
||||||
for key, type of Linkify.types
|
for key, type of Linkify.types
|
||||||
continue unless match = type.regExp.exec href
|
continue unless match = type.regExp.exec href
|
||||||
link = Linkify.makeLink link unless Conf['Linkify']
|
|
||||||
return [key, match[1], match[2], link]
|
return [key, match[1], match[2], link]
|
||||||
|
|
||||||
return
|
return
|
||||||
@ -147,34 +138,56 @@ Linkify =
|
|||||||
$.on embed, 'click', Linkify.cb.toggle
|
$.on embed, 'click', Linkify.cb.toggle
|
||||||
$.after link, [$.tn(' '), embed]
|
$.after link, [$.tn(' '), embed]
|
||||||
|
|
||||||
|
title: (data) ->
|
||||||
|
[key, uid, options, link] = data
|
||||||
|
service = Linkify.types[key].title
|
||||||
|
titles = Conf['CachedTitles']
|
||||||
|
if title = titles[uid]
|
||||||
|
link.textContent = title[0]
|
||||||
|
if Conf['Embedding']
|
||||||
|
link.nextElementSibling.dataset.title = title[0]
|
||||||
|
else
|
||||||
|
try
|
||||||
|
$.cache service.api(uid), ->
|
||||||
|
title = Linkify.cb.title.apply @, [data]
|
||||||
|
catch err
|
||||||
|
link.innerHTML = "[#{key}] <span class=warning>Title Link Blocked</span> (are you using NoScript?)</a>"
|
||||||
|
return
|
||||||
|
if title
|
||||||
|
titles[uid] = [title, Date.now()]
|
||||||
|
$.set 'CachedTitles', titles
|
||||||
|
|
||||||
|
titleSync: (value) ->
|
||||||
|
Conf['CachedTitles'] = value
|
||||||
|
|
||||||
cb:
|
cb:
|
||||||
toggle: ->
|
toggle: ->
|
||||||
# We setup the link to be replaced by the embedded video
|
# We setup the link to be replaced by the embedded video
|
||||||
embed = @previousElementSibling
|
embed = @previousElementSibling
|
||||||
|
|
||||||
# Unembed.
|
# Unembed.
|
||||||
el = unless @className.contains "embedded"
|
el = unless @className.contains "embedded"
|
||||||
Linkify.cb.embed @
|
Linkify.cb.embed @
|
||||||
else
|
else
|
||||||
Linkify.cb.unembed @
|
Linkify.cb.unembed @
|
||||||
|
|
||||||
$.replace embed, el
|
$.replace embed, el
|
||||||
$.toggleClass @, 'embedded'
|
$.toggleClass @, 'embedded'
|
||||||
|
|
||||||
embed: (a) ->
|
embed: (a) ->
|
||||||
# We create an element to embed
|
# We create an element to embed
|
||||||
el = (type = Linkify.types[a.dataset.service]).el.call a
|
el = (type = Linkify.types[a.dataset.service]).el.call a
|
||||||
|
|
||||||
# Set style values.
|
# Set style values.
|
||||||
el.style.cssText = if style = type.style
|
el.style.cssText = if style = type.style
|
||||||
style
|
style
|
||||||
else
|
else
|
||||||
"border: 0; width: 640px; height: 390px"
|
"border: 0; width: 640px; height: 390px"
|
||||||
|
|
||||||
a.textContent = '(unembed)'
|
a.textContent = '(unembed)'
|
||||||
|
|
||||||
return el
|
return el
|
||||||
|
|
||||||
unembed: (a) ->
|
unembed: (a) ->
|
||||||
# Recreate the original link.
|
# Recreate the original link.
|
||||||
el = $.el 'a',
|
el = $.el 'a',
|
||||||
@ -183,10 +196,10 @@ Linkify =
|
|||||||
className: 'linkify'
|
className: 'linkify'
|
||||||
href: url = a.dataset.originalurl
|
href: url = a.dataset.originalurl
|
||||||
textContent: a.dataset.title or url
|
textContent: a.dataset.title or url
|
||||||
|
|
||||||
a.textContent = '(embed)'
|
a.textContent = '(embed)'
|
||||||
$.addClass el, "#{a.dataset.service}"
|
$.addClass el, "#{a.dataset.service}"
|
||||||
|
|
||||||
return el
|
return el
|
||||||
|
|
||||||
title: (data) ->
|
title: (data) ->
|
||||||
@ -205,30 +218,6 @@ Linkify =
|
|||||||
else
|
else
|
||||||
"[#{key}] #{@status}'d"
|
"[#{key}] #{@status}'d"
|
||||||
|
|
||||||
title: (data) ->
|
|
||||||
[key, uid, options, link] = data
|
|
||||||
titles = {}
|
|
||||||
service = Linkify.types[key].title
|
|
||||||
title = ""
|
|
||||||
|
|
||||||
$.get 'CachedTitles', {}, (item) ->
|
|
||||||
titles = item['CachedTitles']
|
|
||||||
if title = titles[uid]
|
|
||||||
link.textContent = title[0]
|
|
||||||
if Conf['Embedding']
|
|
||||||
link.nextElementSibling.dataset.title = title[0]
|
|
||||||
return
|
|
||||||
else
|
|
||||||
try
|
|
||||||
$.cache service.api(uid), ->
|
|
||||||
title = Linkify.cb.title.apply @, [data]
|
|
||||||
catch err
|
|
||||||
link.innerHTML = "[#{key}] <span class=warning>Title Link Blocked</span> (are you using NoScript?)</a>"
|
|
||||||
return
|
|
||||||
if title
|
|
||||||
titles[uid] = [title, Date.now()]
|
|
||||||
$.set 'CachedTitles', titles
|
|
||||||
|
|
||||||
types:
|
types:
|
||||||
YouTube:
|
YouTube:
|
||||||
regExp: /.*(?:youtu.be\/|youtube.*v=|youtube.*\/embed\/|youtube.*\/v\/|youtube.*videos\/)([^#\&\?]*)\??(t\=.*)?/
|
regExp: /.*(?:youtu.be\/|youtube.*v=|youtube.*\/embed\/|youtube.*\/v\/|youtube.*videos\/)([^#\&\?]*)\??(t\=.*)?/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user