From 608f18b707c6a51f1d31352d31f60a2dee189d51 Mon Sep 17 00:00:00 2001 From: Hedgehog Date: Wed, 18 Jun 2014 15:04:24 +0400 Subject: [PATCH] Fixed img.bi support --- js/twister_formatpost.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/js/twister_formatpost.js b/js/twister_formatpost.js index 76e87f0..f66464d 100644 --- a/js/twister_formatpost.js +++ b/js/twister_formatpost.js @@ -323,16 +323,23 @@ function imagePreview(link) { }; function getImgbi(link) { - var params = link.split('!'); - imgBiJSDownload(params[0].replace('#','') + 'download/' + params[1], params[2], new XMLHttpRequest(), link); + var originLink = link; + if (link.indexOf('#/' > 0)) var link = link.replace('#/', '#!'); - function imgBiJSDownload(url, pass, request, link) { + var params = link.split('!'); + var url = params[0].replace('#','') + 'download/' + params[1]; + var pass = params[2]; + + imgBiJSDownload(url, pass, new XMLHttpRequest(), link, originLink); + + function imgBiJSDownload(url, pass, request, link, originLink) { request.open('GET', url); + request.onload = function() { if (request.status == 200) { var result = sjcl.decrypt(pass,request.responseText); if (result) { - var elem = $('img[data-imgbi="'+link+'"]')[0]; + var elem = $('img[data-imgbi="'+originLink+'"]')[0]; elem.src = result; } else { console.log('Failed to decrypt image');