diff --git a/home.html b/home.html index 99970f5..0880b8d 100644 --- a/home.html +++ b/home.html @@ -385,6 +385,9 @@ +
diff --git a/js/interface_common.js b/js/interface_common.js index 5ad554e..cfb1f11 100644 --- a/js/interface_common.js +++ b/js/interface_common.js @@ -807,7 +807,10 @@ function fillElemWithTxt(elem, txt, htmlFormatMsgOpt) { elem.html(formatted.html); elem.find('a').each(function (i, elem) { var href = elem.getAttribute('href'); - if (href && href[0] === '#') + if (elem.classList.contains('link-shortened')) { + $(elem).on('click mouseup', {preventDefault: true}, muteEvent); + fetchShortenedURI(href); + } else if (href && href[0] === '#') $(elem) .on('click', {preventDefault: true}, muteEvent) .on('mouseup', {route: href}, routeOnClick) @@ -819,6 +822,31 @@ function fillElemWithTxt(elem, txt, htmlFormatMsgOpt) { return formatted; } +function fetchShortenedURI(req) { + // FIXME need to check if ret for req is cached here + if (parseInt(twisterVersion) < 93500) { + console.warn('can\'t fetch URI "' + req + '": daemon is obsolete, version 0.9.35 or higher is required'); + return; + } + twisterRpc('decodeshorturl', [req], + function gotShortURI(req, ret) { + // FIXME need to cache ret here + var elems = $('.link-shortened[href="' + req + '"]') + .attr('href', ret) + .removeClass('link-shortened') + .off('click mouseup') + .on('click mouseup', muteEvent) + ; + for (var i = 0; i < elems.length; i++) + if (elems[i].text === req) + elems[i].text = ret; + }, req, + function (req, ret) { + console.warn('can\'t fetch URI "' + req + '": ' + ret.message); + }, req + ); +} + function routeOnClick(event) { function routeNewTab(event) { diff --git a/js/twister_formatpost.js b/js/twister_formatpost.js index dd6ae98..6dcc8bd 100644 --- a/js/twister_formatpost.js +++ b/js/twister_formatpost.js @@ -25,6 +25,7 @@ $(document).ready(function() { _htmlFormatMsgLinkTemplateHashtag = _htmlFormatMsgLinkTemplateHashtag[0].cloneNode(); _htmlFormatMsgLinkTemplateHashtag.removeAttribute('id'); } + twister.tmpl.linkShortened = extractTemplate('#template-link-shortened')[0]; }); // format "userpost" to html element @@ -626,36 +627,33 @@ function htmlFormatMsg(msg, opt) { + '