diff --git a/pages/download_as_binary.html b/pages/download_as_binary.html new file mode 100644 index 00000000..63df4be3 --- /dev/null +++ b/pages/download_as_binary.html @@ -0,0 +1,68 @@ +

Download base64 or dataURL - as binary file.

+Base64 or dataURL:
+ +
+filename.extension: + +
+
+ + \ No newline at end of file diff --git a/scripts/img2base64.js b/scripts/img2base64.js index 66af6805..032c9ea5 100644 --- a/scripts/img2base64.js +++ b/scripts/img2base64.js @@ -60,7 +60,7 @@ var _loader=$('#inputFileToLoad')[0]; function updateImage(loader) { _loader = loader; - var file = _loader.files[0]; + var file = _loader.files[0]; //After selection file, the filename available in - file.name; filetype in - file.type. var reader = new FileReader(); reader.onloadend = function() { var res = reader.result; @@ -72,7 +72,8 @@ function updateImage(loader) { $('.output').find('img').attr('src', 'error'); $('#info').css('color','red'); } else { - $('#result').text('[xmg='+res.substring(res.indexOf(',')+1)+']'); +// $('#result').text('[xmg='+res.substring(res.indexOf(',')+1)+']'); //old code with bb-code xmg + $('#result').text('[file name="'+file.name+'" type="'+file.type+'"]'+res.substring(res.indexOf(',')+1)+'[/file]'); //bb-code file, with filename and mime-type, like in karasiq-nanoboard. $('.output').find('img').attr('src', res); $('#info').css('color','black'); } @@ -118,7 +119,7 @@ function updateImage(loader) { $('#result').text('error'); } else { $('#info').css('color','black'); - $('#result').text('[xmg='+dataURL.substring(dataURL.indexOf(',')+1)+']'); + $('#result').text('[xmg='+dataURL.substring(dataURL.indexOf(',')+1)+']'); //saving backward compatibility with old zipJPEGs and bb-code xmg. } }; var shrd = canvas.toDataURL(); diff --git a/scripts/nanoclient.js b/scripts/nanoclient.js index 53cb024f..bfe64fba 100644 --- a/scripts/nanoclient.js +++ b/scripts/nanoclient.js @@ -1,3 +1,12 @@ +//Function for checking, without throw error, is str base64-encoded or not. return true/false. +function isBase64(str) { + try { + return btoa(atob(str)) == str; + } catch (err) { + return false; + } +} + function numSuffix(numStr) { if (numStr.endsWith('11')) return 's'; if (numStr.endsWith('1')) return ''; @@ -93,9 +102,96 @@ function addPost(post, appendFunc, hasShowButton, short) { }, _post_delete_timeout); })); appendFunc(d); + + //This code need function isBase64(str), and this function in beginning of this script + var post_content = escapeTags(Base64.decode(post.message)); + //console.log(post_content); + + //detect files + if(post_content.indexOf('[file')!==-1){ //if bb-code "file" found + var files_array = post_content.split('[file'); //split by file + //console.log('files_array', files_array); //show array in console + for(i=1;i['+filename+']' + //and add link to download this as binary, + //with green base64 encoded PNG image to this link. + +''; + + //console.log('html_link', html_link); //show this link... + + post_content = post_content.split('[file name="'+filename+'" type="'+filetype+'"]'+maybe_base+'[/file]').join(html_link); //and replace bb-code file to this link. + + //console.log('post_content: ', post_content); //show results... + }else{ //not base64 in the middle of [file][/file] + //console.log('not base64', maybe_base); //do nothing + } + //and continue replace files to links in all post, splitted by file-tag, again and again... + } + //console.log('post_content: ', post_content); //show post in the end and continue script + }//or continue script without replacing... + var inner = $('
') .addClass('post-inner') - .html(applyFormatting(escapeTags(Base64.decode(post.message)))) +// .html(applyFormatting(escapeTags(Base64.decode(post.message)))) //old code + .html(applyFormatting(post_content)) //<--- HERE using replaced contend of post .appendTo(d); detectPlacesCommands(inner); d.find('img').click(function(){ @@ -107,7 +203,7 @@ function addPost(post, appendFunc, hasShowButton, short) { if (imgcnt > 0) { for (var i = 0; i < imgcnt; i++) { var img = imgs[i]; - if (img.src.startsWith('data:image/jpeg;base64,UEsDB')) { + if (img.src.startsWith('data:image/jpeg;base64,UEsDB')) {//if PK at first - then zip //saving backward compatibility with old zipJPEGs $(img).replaceWith($('[file'+(i+1)+'.zip]')); } }