From 9bf5b6dbdeb86af0a6faa336ff16d9cddf989324 Mon Sep 17 00:00:00 2001 From: Christian Pierre MOMON Date: Wed, 14 Apr 2021 03:11:58 +0200 Subject: [PATCH] Added download feature (#5318). --- css/privatebin.css | 4 ++++ js/privatebin.js | 41 +++++++++++++++++++++++++++++++++++++++++ tpl/bootstrap.php | 5 ++++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/css/privatebin.css b/css/privatebin.css index a3ab5ea6..b379f191 100644 --- a/css/privatebin.css +++ b/css/privatebin.css @@ -249,6 +249,10 @@ button img { padding: 1px 0 1px 0; } +#downloadtextbutton img { + padding: 1px 0 1px 0; +} + #remainingtime, #password { color: #94a3b4; display: inline; diff --git a/js/privatebin.js b/js/privatebin.js index 6ed9325b..c5b93839 100644 --- a/js/privatebin.js +++ b/js/privatebin.js @@ -3508,6 +3508,7 @@ jQuery.PrivateBin = (function($, RawDeflate) { $password, $passwordInput, $rawTextButton, + $downloadTextButton, $qrCodeLink, $emailLink, $sendButton, @@ -3635,6 +3636,30 @@ jQuery.PrivateBin = (function($, RawDeflate) { newDoc.close(); } + /** + * download text + * + * @name TopNav.downloadText + * @private + * @function + */ + function downloadText() + { + var filename='paste.txt'; + var text = PasteViewer.getText(); + + var element = document.createElement('a'); + element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); + element.setAttribute('download', filename); + + element.style.display = 'none'; + document.body.appendChild(element); + + element.click(); + + document.body.removeChild(element); + } + /** * saves the language in a cookie and reloads the page * @@ -3859,6 +3884,7 @@ jQuery.PrivateBin = (function($, RawDeflate) { $newButton.removeClass('hidden'); $cloneButton.removeClass('hidden'); $rawTextButton.removeClass('hidden'); + $downloadTextButton.removeClass('hidden'); $qrCodeLink.removeClass('hidden'); viewButtonsDisplayed = true; @@ -3879,6 +3905,7 @@ jQuery.PrivateBin = (function($, RawDeflate) { $cloneButton.addClass('hidden'); $newButton.addClass('hidden'); $rawTextButton.addClass('hidden'); + $downloadTextButton.addClass('hidden'); $qrCodeLink.addClass('hidden'); me.hideEmailButton(); @@ -4040,6 +4067,17 @@ jQuery.PrivateBin = (function($, RawDeflate) { $rawTextButton.addClass('hidden'); }; + /** + * only hides the download text button + * + * @name TopNav.hideRawButton + * @function + */ + me.hideDownloadButton = function() + { + $downloadTextButton.addClass('hidden'); + }; + /** * only hides the qr code button * @@ -4278,6 +4316,7 @@ jQuery.PrivateBin = (function($, RawDeflate) { $password = $('#password'); $passwordInput = $('#passwordinput'); $rawTextButton = $('#rawtextbutton'); + $downloadTextButton = $('#downloadtextbutton'); $retryButton = $('#retrybutton'); $sendButton = $('#sendbutton'); $qrCodeLink = $('#qrcodelink'); @@ -4295,6 +4334,7 @@ jQuery.PrivateBin = (function($, RawDeflate) { $sendButton.click(PasteEncrypter.sendPaste); $cloneButton.click(Controller.clonePaste); $rawTextButton.click(rawText); + $downloadTextButton.click(downloadText); $retryButton.click(clickRetryButton); $fileRemoveButton.click(removeAttachment); $qrCodeLink.click(displayQrCode); @@ -4631,6 +4671,7 @@ jQuery.PrivateBin = (function($, RawDeflate) { TopNav.showEmailButton(); TopNav.hideRawButton(); + TopNav.hideDownloadButton(); Editor.hide(); // parse and show text diff --git a/tpl/bootstrap.php b/tpl/bootstrap.php index 87faa556..db44707b 100644 --- a/tpl/bootstrap.php +++ b/tpl/bootstrap.php @@ -72,7 +72,7 @@ endif; ?> - + @@ -199,6 +199,9 @@ endif; +