Eliminate title cacheing for the time being.
Causing too many problems. Also attempt to optimize Linkify.
This commit is contained in:
parent
a48357a45f
commit
3b611160ac
2
LICENSE
2
LICENSE
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* appchan x - Version 2.9.6 - 2014-03-19
|
* appchan x - Version 2.9.6 - 2014-03-20
|
||||||
*
|
*
|
||||||
* 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.6 - 2014-03-19
|
* appchan x - Version 2.9.6 - 2014-03-20
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@ -8120,20 +8120,21 @@
|
|||||||
cb: this.node
|
cb: this.node
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
node: function() {
|
events: function(post) {
|
||||||
var data, el, end, endNode, i, index, items, length, link, links, node, result, saved, snapshot, space, test, word, _i, _len, _ref;
|
var el, i, items;
|
||||||
if (this.isClone) {
|
i = 0;
|
||||||
if (Conf['Embedding']) {
|
items = $$('.embedder', post.nodes.comment);
|
||||||
i = 0;
|
while (el = items[i++]) {
|
||||||
items = $$('.embedder', this.nodes.comment);
|
$.on(el, 'click', Linkify.cb.toggle);
|
||||||
while (el = items[i++]) {
|
if ($.hasClass(el, 'embedded')) {
|
||||||
$.on(el, 'click', Linkify.cb.toggle);
|
Linkify.cb.toggle.call(el);
|
||||||
if ($.hasClass(el, 'embedded')) {
|
|
||||||
Linkify.cb.toggle.call(el);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
}
|
||||||
|
},
|
||||||
|
node: function() {
|
||||||
|
var data, end, endNode, i, index, length, link, links, node, result, saved, snapshot, space, test, word;
|
||||||
|
if (this.isClone) {
|
||||||
|
return (Conf['Embedding'] ? Linkify.events(this) : null);
|
||||||
}
|
}
|
||||||
if (!Linkify.regString.test(this.info.comment)) {
|
if (!Linkify.regString.test(this.info.comment)) {
|
||||||
return;
|
return;
|
||||||
@ -8145,7 +8146,7 @@
|
|||||||
links = [];
|
links = [];
|
||||||
while (node = snapshot.snapshotItem(i++)) {
|
while (node = snapshot.snapshotItem(i++)) {
|
||||||
data = node.data;
|
data = node.data;
|
||||||
if (node.parentElement.nodeName === "A" || !data) {
|
if (!data || node.parentElement.nodeName === "A") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
while (result = test.exec(data)) {
|
while (result = test.exec(data)) {
|
||||||
@ -8177,25 +8178,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ref = links.reverse();
|
i = links.length;
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
while (i--) {
|
||||||
link = _ref[_i];
|
link = links[i];
|
||||||
this.nodes.links.push(Linkify.makeLink(link, this));
|
Linkify.embedProcess(Linkify.makeLink(link, this));
|
||||||
link.detach();
|
|
||||||
}
|
}
|
||||||
if (!(Conf['Embedding'] || Conf['Link Title'])) {
|
},
|
||||||
return;
|
embedProcess: function(link) {
|
||||||
}
|
var data;
|
||||||
links = this.nodes.links;
|
if (data = Linkify.services(link)) {
|
||||||
i = 0;
|
if (Conf['Embedding']) {
|
||||||
while (link = links[i++]) {
|
Linkify.embed(data);
|
||||||
if (data = Linkify.services(link)) {
|
}
|
||||||
if (Conf['Embedding']) {
|
if (Conf['Link Title']) {
|
||||||
Linkify.embed(data);
|
return Linkify.title(data);
|
||||||
}
|
|
||||||
if (Conf['Link Title']) {
|
|
||||||
Linkify.title(data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -8250,6 +8246,7 @@
|
|||||||
});
|
});
|
||||||
$.add(a, range.extractContents());
|
$.add(a, range.extractContents());
|
||||||
range.insertNode(a);
|
range.insertNode(a);
|
||||||
|
range.detach();
|
||||||
return a;
|
return a;
|
||||||
},
|
},
|
||||||
services: function(link) {
|
services: function(link) {
|
||||||
@ -8258,10 +8255,9 @@
|
|||||||
_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;
|
return [key, match[1], match[2], link];
|
||||||
}
|
}
|
||||||
return [key, match[1], match[2], link];
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
embed: function(data) {
|
embed: function(data) {
|
||||||
@ -8290,7 +8286,7 @@
|
|||||||
if (Conf['Auto-embed']) {
|
if (Conf['Auto-embed']) {
|
||||||
Linkify.cb.toggle.call(embed);
|
Linkify.cb.toggle.call(embed);
|
||||||
}
|
}
|
||||||
data.push(embed);
|
return data.push(embed);
|
||||||
},
|
},
|
||||||
title: function(data) {
|
title: function(data) {
|
||||||
var embed, err, key, link, options, service, title, titles, uid;
|
var embed, err, key, link, options, service, title, titles, uid;
|
||||||
@ -8308,9 +8304,9 @@
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
$.cache(service.api(uid), function() {
|
return $.cache(service.api(uid), (function() {
|
||||||
return title = Linkify.cb.title(this, data);
|
return Linkify.cb.title(this, data);
|
||||||
}, {
|
}), {
|
||||||
responseType: 'json'
|
responseType: 'json'
|
||||||
});
|
});
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
@ -8318,23 +8314,15 @@
|
|||||||
if (link) {
|
if (link) {
|
||||||
link.innerHTML = "[" + key + "] <span class=warning>Title Link Blocked</span> (are you using NoScript?)</a>";
|
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;
|
|
||||||
},
|
|
||||||
clean: function() {
|
clean: function() {
|
||||||
var age, name, pruned, uid, _ref, _ref1;
|
var age, pruned, uid, _, _ref, _ref1;
|
||||||
pruned = false;
|
pruned = false;
|
||||||
_ref = Conf['CachedTitles'];
|
_ref = Conf['CachedTitles'];
|
||||||
for (uid in _ref) {
|
for (uid in _ref) {
|
||||||
_ref1 = _ref[uid], name = _ref1[0], age = _ref1[1];
|
_ref1 = _ref[uid], _ = _ref1[0], age = _ref1[1];
|
||||||
if (!(age + $.DAY > Date.now())) {
|
if (!(age + $.DAY > Date.now())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -8370,26 +8358,26 @@
|
|||||||
$.addClass(el, a.dataset.key);
|
$.addClass(el, a.dataset.key);
|
||||||
return el;
|
return el;
|
||||||
},
|
},
|
||||||
title: function(response, data) {
|
title: function(req, data) {
|
||||||
var embed, key, link, options, service, text, uid;
|
var embed, key, link, options, service, status, text, uid;
|
||||||
key = data[0], uid = data[1], options = data[2], link = data[3], embed = data[4];
|
key = data[0], uid = data[1], options = data[2], link = data[3], embed = data[4];
|
||||||
|
status = req.status;
|
||||||
service = Linkify.types[key].title;
|
service = Linkify.types[key].title;
|
||||||
switch (response.status) {
|
text = "[" + key + "] " + ((function() {
|
||||||
case 200:
|
switch (status) {
|
||||||
case 304:
|
case 200:
|
||||||
text = "" + (service.text(response.response));
|
case 304:
|
||||||
if (Conf['Embedding']) {
|
return service.text(req.response);
|
||||||
embed.dataset.title = text;
|
case 404:
|
||||||
}
|
return "Not Found";
|
||||||
break;
|
case 403:
|
||||||
case 404:
|
return "Forbidden or Private";
|
||||||
text = "[" + key + "] Not Found";
|
default:
|
||||||
break;
|
return "" + status + "'d";
|
||||||
case 403:
|
}
|
||||||
text = "[" + key + "] Forbidden or Private";
|
})());
|
||||||
break;
|
if (Conf['Embedding'] && (status === 200 || status === 304)) {
|
||||||
default:
|
embed.dataset.title = text;
|
||||||
text = "[" + key + "] " + this.status + "'d";
|
|
||||||
}
|
}
|
||||||
if (link) {
|
if (link) {
|
||||||
return link.textContent = text;
|
return link.textContent = text;
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
// Generated by CoffeeScript
|
// Generated by CoffeeScript
|
||||||
/*
|
/*
|
||||||
* appchan x - Version 2.9.6 - 2014-03-19
|
* appchan x - Version 2.9.6 - 2014-03-20
|
||||||
*
|
*
|
||||||
* 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
|
||||||
@ -8171,20 +8171,21 @@
|
|||||||
cb: this.node
|
cb: this.node
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
node: function() {
|
events: function(post) {
|
||||||
var data, el, end, endNode, i, index, items, length, link, links, node, result, saved, snapshot, space, test, word, _i, _len, _ref;
|
var el, i, items;
|
||||||
if (this.isClone) {
|
i = 0;
|
||||||
if (Conf['Embedding']) {
|
items = $$('.embedder', post.nodes.comment);
|
||||||
i = 0;
|
while (el = items[i++]) {
|
||||||
items = $$('.embedder', this.nodes.comment);
|
$.on(el, 'click', Linkify.cb.toggle);
|
||||||
while (el = items[i++]) {
|
if ($.hasClass(el, 'embedded')) {
|
||||||
$.on(el, 'click', Linkify.cb.toggle);
|
Linkify.cb.toggle.call(el);
|
||||||
if ($.hasClass(el, 'embedded')) {
|
|
||||||
Linkify.cb.toggle.call(el);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
}
|
||||||
|
},
|
||||||
|
node: function() {
|
||||||
|
var data, end, endNode, i, index, length, link, links, node, result, saved, snapshot, space, test, word;
|
||||||
|
if (this.isClone) {
|
||||||
|
return (Conf['Embedding'] ? Linkify.events(this) : null);
|
||||||
}
|
}
|
||||||
if (!Linkify.regString.test(this.info.comment)) {
|
if (!Linkify.regString.test(this.info.comment)) {
|
||||||
return;
|
return;
|
||||||
@ -8196,7 +8197,7 @@
|
|||||||
links = [];
|
links = [];
|
||||||
while (node = snapshot.snapshotItem(i++)) {
|
while (node = snapshot.snapshotItem(i++)) {
|
||||||
data = node.data;
|
data = node.data;
|
||||||
if (node.parentElement.nodeName === "A" || !data) {
|
if (!data || node.parentElement.nodeName === "A") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
while (result = test.exec(data)) {
|
while (result = test.exec(data)) {
|
||||||
@ -8228,25 +8229,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ref = links.reverse();
|
i = links.length;
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
while (i--) {
|
||||||
link = _ref[_i];
|
link = links[i];
|
||||||
this.nodes.links.push(Linkify.makeLink(link, this));
|
Linkify.embedProcess(Linkify.makeLink(link, this));
|
||||||
link.detach();
|
|
||||||
}
|
}
|
||||||
if (!(Conf['Embedding'] || Conf['Link Title'])) {
|
},
|
||||||
return;
|
embedProcess: function(link) {
|
||||||
}
|
var data;
|
||||||
links = this.nodes.links;
|
if (data = Linkify.services(link)) {
|
||||||
i = 0;
|
if (Conf['Embedding']) {
|
||||||
while (link = links[i++]) {
|
Linkify.embed(data);
|
||||||
if (data = Linkify.services(link)) {
|
}
|
||||||
if (Conf['Embedding']) {
|
if (Conf['Link Title']) {
|
||||||
Linkify.embed(data);
|
return Linkify.title(data);
|
||||||
}
|
|
||||||
if (Conf['Link Title']) {
|
|
||||||
Linkify.title(data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -8301,6 +8297,7 @@
|
|||||||
});
|
});
|
||||||
$.add(a, range.extractContents());
|
$.add(a, range.extractContents());
|
||||||
range.insertNode(a);
|
range.insertNode(a);
|
||||||
|
range.detach();
|
||||||
return a;
|
return a;
|
||||||
},
|
},
|
||||||
services: function(link) {
|
services: function(link) {
|
||||||
@ -8309,10 +8306,9 @@
|
|||||||
_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;
|
return [key, match[1], match[2], link];
|
||||||
}
|
}
|
||||||
return [key, match[1], match[2], link];
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
embed: function(data) {
|
embed: function(data) {
|
||||||
@ -8341,7 +8337,7 @@
|
|||||||
if (Conf['Auto-embed']) {
|
if (Conf['Auto-embed']) {
|
||||||
Linkify.cb.toggle.call(embed);
|
Linkify.cb.toggle.call(embed);
|
||||||
}
|
}
|
||||||
data.push(embed);
|
return data.push(embed);
|
||||||
},
|
},
|
||||||
title: function(data) {
|
title: function(data) {
|
||||||
var embed, err, key, link, options, service, title, titles, uid;
|
var embed, err, key, link, options, service, title, titles, uid;
|
||||||
@ -8359,9 +8355,9 @@
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
$.cache(service.api(uid), function() {
|
return $.cache(service.api(uid), (function() {
|
||||||
return title = Linkify.cb.title(this, data);
|
return Linkify.cb.title(this, data);
|
||||||
}, {
|
}), {
|
||||||
responseType: 'json'
|
responseType: 'json'
|
||||||
});
|
});
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
@ -8369,23 +8365,15 @@
|
|||||||
if (link) {
|
if (link) {
|
||||||
link.innerHTML = "[" + key + "] <span class=warning>Title Link Blocked</span> (are you using NoScript?)</a>";
|
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;
|
|
||||||
},
|
|
||||||
clean: function() {
|
clean: function() {
|
||||||
var age, name, pruned, uid, _ref, _ref1;
|
var age, pruned, uid, _, _ref, _ref1;
|
||||||
pruned = false;
|
pruned = false;
|
||||||
_ref = Conf['CachedTitles'];
|
_ref = Conf['CachedTitles'];
|
||||||
for (uid in _ref) {
|
for (uid in _ref) {
|
||||||
_ref1 = _ref[uid], name = _ref1[0], age = _ref1[1];
|
_ref1 = _ref[uid], _ = _ref1[0], age = _ref1[1];
|
||||||
if (!(age + $.DAY > Date.now())) {
|
if (!(age + $.DAY > Date.now())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -8421,26 +8409,26 @@
|
|||||||
$.addClass(el, a.dataset.key);
|
$.addClass(el, a.dataset.key);
|
||||||
return el;
|
return el;
|
||||||
},
|
},
|
||||||
title: function(response, data) {
|
title: function(req, data) {
|
||||||
var embed, key, link, options, service, text, uid;
|
var embed, key, link, options, service, status, text, uid;
|
||||||
key = data[0], uid = data[1], options = data[2], link = data[3], embed = data[4];
|
key = data[0], uid = data[1], options = data[2], link = data[3], embed = data[4];
|
||||||
|
status = req.status;
|
||||||
service = Linkify.types[key].title;
|
service = Linkify.types[key].title;
|
||||||
switch (response.status) {
|
text = "[" + key + "] " + ((function() {
|
||||||
case 200:
|
switch (status) {
|
||||||
case 304:
|
case 200:
|
||||||
text = "" + (service.text(response.response));
|
case 304:
|
||||||
if (Conf['Embedding']) {
|
return service.text(req.response);
|
||||||
embed.dataset.title = text;
|
case 404:
|
||||||
}
|
return "Not Found";
|
||||||
break;
|
case 403:
|
||||||
case 404:
|
return "Forbidden or Private";
|
||||||
text = "[" + key + "] Not Found";
|
default:
|
||||||
break;
|
return "" + status + "'d";
|
||||||
case 403:
|
}
|
||||||
text = "[" + key + "] Forbidden or Private";
|
})());
|
||||||
break;
|
if (Conf['Embedding'] && (status === 200 || status === 304)) {
|
||||||
default:
|
embed.dataset.title = text;
|
||||||
text = "[" + key + "] " + this.status + "'d";
|
|
||||||
}
|
}
|
||||||
if (link) {
|
if (link) {
|
||||||
return link.textContent = text;
|
return link.textContent = text;
|
||||||
|
|||||||
@ -13,28 +13,26 @@ Linkify =
|
|||||||
name: 'Linkify'
|
name: 'Linkify'
|
||||||
cb: @node
|
cb: @node
|
||||||
|
|
||||||
|
events: (post) ->
|
||||||
|
i = 0
|
||||||
|
items = $$ '.embedder', post.nodes.comment
|
||||||
|
while el = items[i++]
|
||||||
|
$.on el, 'click', Linkify.cb.toggle
|
||||||
|
Linkify.cb.toggle.call el if $.hasClass el, 'embedded'
|
||||||
|
return
|
||||||
|
|
||||||
node: ->
|
node: ->
|
||||||
if @isClone
|
return (if Conf['Embedding'] then Linkify.events @ else null) if @isClone
|
||||||
if Conf['Embedding']
|
|
||||||
i = 0
|
|
||||||
items = $$ '.embedder', @nodes.comment
|
|
||||||
while el = items[i++]
|
|
||||||
$.on el, 'click', Linkify.cb.toggle
|
|
||||||
Linkify.cb.toggle.call el if $.hasClass el, 'embedded'
|
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
return unless Linkify.regString.test @info.comment
|
return unless Linkify.regString.test @info.comment
|
||||||
|
|
||||||
test = /[^\s'"]+/g
|
test = /[^\s'"]+/g
|
||||||
space = /[\s'"]/
|
space = /[\s'"]/
|
||||||
|
|
||||||
snapshot = $.X './/br|.//text()', @nodes.comment
|
snapshot = $.X './/br|.//text()', @nodes.comment
|
||||||
i = 0
|
i = 0
|
||||||
links = []
|
links = []
|
||||||
while node = snapshot.snapshotItem i++
|
while node = snapshot.snapshotItem i++
|
||||||
{data} = node
|
{data} = node
|
||||||
continue if node.parentElement.nodeName is "A" or not data
|
continue if !data or node.parentElement.nodeName is "A"
|
||||||
|
|
||||||
while result = test.exec data
|
while result = test.exec data
|
||||||
{index} = result
|
{index} = result
|
||||||
@ -59,41 +57,33 @@ Linkify =
|
|||||||
i--
|
i--
|
||||||
break
|
break
|
||||||
|
|
||||||
if Linkify.regString.exec word
|
links.push Linkify.makeRange node, endNode, index, length if Linkify.regString.exec word
|
||||||
links.push Linkify.makeRange node, endNode, index, length
|
|
||||||
|
|
||||||
break unless test.lastIndex and node is endNode
|
break unless test.lastIndex and node is endNode
|
||||||
|
|
||||||
for link in links.reverse()
|
i = links.length
|
||||||
@nodes.links.push Linkify.makeLink link, @
|
while i--
|
||||||
link.detach()
|
link = links[i]
|
||||||
|
Linkify.embedProcess Linkify.makeLink link, @
|
||||||
return unless Conf['Embedding'] or Conf['Link Title']
|
|
||||||
|
|
||||||
{links} = @nodes
|
|
||||||
i = 0
|
|
||||||
while link = links[i++]
|
|
||||||
if data = Linkify.services link
|
|
||||||
Linkify.embed data if Conf['Embedding']
|
|
||||||
Linkify.title data if Conf['Link Title']
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
embedProcess: (link) ->
|
||||||
|
if data = Linkify.services link
|
||||||
|
Linkify.embed data if Conf['Embedding']
|
||||||
|
Linkify.title data if Conf['Link Title']
|
||||||
|
|
||||||
regString: ///(
|
regString: ///(
|
||||||
# http, magnet, ftp, etc
|
# http, magnet, ftp, etc
|
||||||
(https?|mailto|git|magnet|ftp|irc):(
|
(https?|mailto|git|magnet|ftp|irc):(
|
||||||
[a-z\d%/]
|
[a-z\d%/]
|
||||||
)
|
)
|
||||||
|
|
| # This should account for virtually all links posted without http:
|
||||||
# This should account for virtually all links posted without http:
|
|
||||||
[-a-z\d]+[.](
|
[-a-z\d]+[.](
|
||||||
aero|asia|biz|cat|com|coop|info|int|jobs|mobi|museum|name|net|org|post|pro|tel|travel|xxx|edu|gov|mil|[a-z]{2}
|
aero|asia|biz|cat|com|coop|info|int|jobs|mobi|museum|name|net|org|post|pro|tel|travel|xxx|edu|gov|mil|[a-z]{2}
|
||||||
)(/|(?!.))
|
)(/|(?!.))
|
||||||
|
|
| # IPv4 Addresses
|
||||||
# IPv4 Addresses
|
|
||||||
[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}
|
[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}
|
||||||
|
|
| # E-mails
|
||||||
# E-mails
|
|
||||||
[-\w\d.@]+@[a-z\d.-]+\.[a-z\d]
|
[-\w\d.@]+@[a-z\d.-]+\.[a-z\d]
|
||||||
)///i
|
)///i
|
||||||
|
|
||||||
@ -106,7 +96,7 @@ Linkify =
|
|||||||
makeLink: (range) ->
|
makeLink: (range) ->
|
||||||
text = range.toString()
|
text = range.toString()
|
||||||
|
|
||||||
# Clean leading brackets, >
|
# Clean start of range
|
||||||
i = 0
|
i = 0
|
||||||
i++ while /[(\[{<>]/.test text.charAt i
|
i++ while /[(\[{<>]/.test text.charAt i
|
||||||
|
|
||||||
@ -116,7 +106,7 @@ Linkify =
|
|||||||
|
|
||||||
range.setStart range.startContainer, range.startOffset + i if i
|
range.setStart range.startContainer, range.startOffset + i if i
|
||||||
|
|
||||||
# Clean hanging brackets, commas, periods
|
# Clean end of range
|
||||||
i = 0
|
i = 0
|
||||||
while /[)\]}>.,]/.test t = text.charAt text.length - (1 + i)
|
while /[)\]}>.,]/.test t = text.charAt text.length - (1 + i)
|
||||||
break unless /[.,]/.test(t) or (text.match /[()\[\]{}<>]/g).length % 2
|
break unless /[.,]/.test(t) or (text.match /[()\[\]{}<>]/g).length % 2
|
||||||
@ -129,6 +119,7 @@ Linkify =
|
|||||||
if i
|
if i
|
||||||
range.setEnd range.endContainer, range.endOffset - i
|
range.setEnd range.endContainer, range.endOffset - i
|
||||||
|
|
||||||
|
# Make our link 'valid' if it is formatted incorrectly.
|
||||||
unless /(https?|mailto|git|magnet|ftp|irc):/.test text
|
unless /(https?|mailto|git|magnet|ftp|irc):/.test text
|
||||||
text = (
|
text = (
|
||||||
if /@/.test text
|
if /@/.test text
|
||||||
@ -142,15 +133,17 @@ Linkify =
|
|||||||
rel: 'nofollow noreferrer'
|
rel: 'nofollow noreferrer'
|
||||||
target: '_blank'
|
target: '_blank'
|
||||||
href: text
|
href: text
|
||||||
|
|
||||||
|
# Insert the range into the anchor, the anchor into the range's DOM location, and destroy the range.
|
||||||
$.add a, range.extractContents()
|
$.add a, range.extractContents()
|
||||||
range.insertNode a
|
range.insertNode a
|
||||||
|
range.detach()
|
||||||
|
|
||||||
a
|
a
|
||||||
|
|
||||||
services: (link) ->
|
services: (link) ->
|
||||||
href = link.href
|
{href} = link
|
||||||
|
for key, type of Linkify.types when match = type.regExp.exec href
|
||||||
for key, type of Linkify.types
|
|
||||||
continue unless match = type.regExp.exec href
|
|
||||||
return [key, match[1], match[2], link]
|
return [key, match[1], match[2], link]
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -162,9 +155,7 @@ Linkify =
|
|||||||
href: 'javascript:;'
|
href: 'javascript:;'
|
||||||
textContent: '(embed)'
|
textContent: '(embed)'
|
||||||
|
|
||||||
for name, value of {key, href, uid, options}
|
embed.dataset[name] = value for name, value of {key, href, uid, options}
|
||||||
embed.dataset[name] = value
|
|
||||||
|
|
||||||
embed.dataset.nodedata = link.innerHTML
|
embed.dataset.nodedata = link.innerHTML
|
||||||
|
|
||||||
$.addClass link, "#{embed.dataset.key}"
|
$.addClass link, "#{embed.dataset.key}"
|
||||||
@ -172,13 +163,10 @@ Linkify =
|
|||||||
$.on embed, 'click', Linkify.cb.toggle
|
$.on embed, 'click', Linkify.cb.toggle
|
||||||
$.after link, [$.tn(' '), embed]
|
$.after link, [$.tn(' '), embed]
|
||||||
|
|
||||||
if Conf['Auto-embed']
|
Linkify.cb.toggle.call embed if Conf['Auto-embed']
|
||||||
Linkify.cb.toggle.call embed
|
|
||||||
|
|
||||||
data.push embed
|
data.push embed
|
||||||
|
|
||||||
return
|
|
||||||
|
|
||||||
title: (data) ->
|
title: (data) ->
|
||||||
[key, uid, options, link, embed] = data
|
[key, uid, options, link, embed] = data
|
||||||
return unless service = Linkify.types[key].title
|
return unless service = Linkify.types[key].title
|
||||||
@ -191,24 +179,15 @@ Linkify =
|
|||||||
embed.dataset.title = title[0]
|
embed.dataset.title = title[0]
|
||||||
else
|
else
|
||||||
try
|
try
|
||||||
$.cache service.api(uid),
|
$.cache service.api(uid), (-> Linkify.cb.title @, data), responseType: 'json'
|
||||||
-> title = Linkify.cb.title @, data
|
|
||||||
,
|
|
||||||
responseType: 'json'
|
|
||||||
catch err
|
catch err
|
||||||
if link
|
if link
|
||||||
link.innerHTML = "[#{key}] <span class=warning>Title Link Blocked</span> (are you using NoScript?)</a>"
|
link.innerHTML = "[#{key}] <span class=warning>Title Link Blocked</span> (are you using NoScript?)</a>"
|
||||||
return
|
return
|
||||||
if title
|
|
||||||
titles[uid] = [title, Date.now()]
|
|
||||||
$.set 'CachedTitles', titles
|
|
||||||
|
|
||||||
titleSync: (value) ->
|
|
||||||
Conf['CachedTitles'] = value
|
|
||||||
|
|
||||||
clean: ->
|
clean: ->
|
||||||
pruned = false
|
pruned = false
|
||||||
for uid, [name, age] of Conf['CachedTitles'] when age + $.DAY > Date.now()
|
for uid, [_, age] of Conf['CachedTitles'] when age + $.DAY > Date.now()
|
||||||
pruned = true
|
pruned = true
|
||||||
delete Conf['CachedTitles'][uid]
|
delete Conf['CachedTitles'][uid]
|
||||||
$.set 'CachedTitles', Conf['CachedTitles'] if pruned
|
$.set 'CachedTitles', Conf['CachedTitles'] if pruned
|
||||||
@ -247,21 +226,24 @@ Linkify =
|
|||||||
|
|
||||||
return el
|
return el
|
||||||
|
|
||||||
title: (response, data) ->
|
title: (req, data) ->
|
||||||
[key, uid, options, link, embed] = data
|
[key, uid, options, link, embed] = data
|
||||||
|
{status} = req
|
||||||
service = Linkify.types[key].title
|
service = Linkify.types[key].title
|
||||||
switch response.status
|
|
||||||
|
text = "[#{key}] #{switch status
|
||||||
when 200, 304
|
when 200, 304
|
||||||
text = "#{service.text response.response}"
|
service.text req.response
|
||||||
if Conf['Embedding']
|
|
||||||
embed.dataset.title = text
|
|
||||||
when 404
|
when 404
|
||||||
text = "[#{key}] Not Found"
|
"Not Found"
|
||||||
when 403
|
when 403
|
||||||
text = "[#{key}] Forbidden or Private"
|
"Forbidden or Private"
|
||||||
else
|
else
|
||||||
text = "[#{key}] #{@status}'d"
|
"#{status}'d"
|
||||||
link.textContent = text if link
|
}"
|
||||||
|
|
||||||
|
embed.dataset.title = text if Conf['Embedding'] and status in [200, 304]
|
||||||
|
link.textContent = text if link
|
||||||
|
|
||||||
types:
|
types:
|
||||||
audio:
|
audio:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user