client: clickable magnet links

This commit is contained in:
mappu 2017-02-05 18:09:53 +13:00
parent 3c1db1266e
commit 56ced01e97

View File

@ -50,9 +50,22 @@ var fmtBytes = function(b) {
return parseFloat((bytes / Math.pow(k, i)).toFixed(3)) + sizes[i]; return parseFloat((bytes / Math.pow(k, i)).toFixed(3)) + sizes[i];
}; };
var urldesc = function(s) {
return decodeURIComponent(s.replace(/\+/g, " "));
}
var linkify = function(str) { var linkify = function(str) {
return str.replace( // n.b. str is already hesced
/(https?:\/\/[^\s<]+)/g, "<a target='_blank' rel=\"noreferrer\" href=\"$1\">$1</a>" return (str
.replace(
/(https?:\/\/[^\s<]+)/g,
"<a target='_blank' rel=\"noreferrer\" href=\"$1\">$1</a>"
)
.replace(
/magnet:\?.+dn=([^\< ]+)/g,
function(match, m1) { return "<a href=\"" + match + "\">[MAGNET] " + urldesc(m1) + "</a>"; }
)
); );
}; };