mirror of https://github.com/calzoneman/sync.git
Improve link filter
This commit is contained in:
parent
ba66aadf66
commit
8ba5743bc2
|
@ -1,3 +1,9 @@
|
|||
Fri Sep 27 10:27 2013 CDT
|
||||
* lib/channel.js: Change the link regex, change the way 'affects links'
|
||||
works. The default link filter will only transform a link of no
|
||||
previous filters transform it (and filters will only transform a link
|
||||
if 'affects links' is ticked).
|
||||
|
||||
Thu Sep 26 23:40 2013 CDT
|
||||
* lib/config.js: Add config keys for statistics interval & max age,
|
||||
alias purge interval & max age.
|
||||
|
|
|
@ -21,6 +21,7 @@ var Filter = require("./filter.js").Filter;
|
|||
var Playlist = require("./playlist");
|
||||
var sanitize = require("validator").sanitize;
|
||||
var $util = require("./utilities");
|
||||
var url = require("url");
|
||||
|
||||
var Channel = function(name, Server) {
|
||||
var self = this;
|
||||
|
@ -2101,17 +2102,25 @@ Channel.prototype.chainMessage = function(user, msg, data) {
|
|||
}
|
||||
|
||||
Channel.prototype.filterMessage = function(msg) {
|
||||
const link = /((?:(?:https?)|(?:ftp))(?::\/\/[0-9a-zA-Z\.]+(?::[0-9]+)?[^\s'"$]+))/g;
|
||||
const link = /(\w+:\/\/(?:[^:\/\[\]\s]+|\[[0-9a-f:]+\])(?::\d+)?(?:\/[^\/\s]*)*)/ig;
|
||||
var subs = msg.split(link);
|
||||
// Apply other filters
|
||||
for(var j = 0; j < subs.length; j++) {
|
||||
if(this.opts.enable_link_regex && subs[j].match(link)) {
|
||||
subs[j] = subs[j].replace(link, "<a href=\"$1\" target=\"_blank\">$1</a>");
|
||||
var orig = subs[j];
|
||||
for(var i = 0; i < this.filters.length; i++) {
|
||||
if(!this.filters[i].filterlinks || !this.filters[i].active)
|
||||
continue;
|
||||
subs[j] = this.filters[i].filter(subs[j]);
|
||||
}
|
||||
|
||||
// only apply link filter if another filter hasn't changed
|
||||
// the link
|
||||
if (subs[j] === orig) {
|
||||
subs[j] = url.format(url.parse(subs[j]));
|
||||
subs[j] = subs[j].replace(link,
|
||||
"<a href=\"$1\" target=\"_blank\">$1</a>");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
for(var i = 0; i < this.filters.length; i++) {
|
||||
|
|
Loading…
Reference in New Issue