El RIDO 6 роки тому
батько
коміт
8b170397a9
5 змінених файлів з 30 додано та 48 видалено
  1. 1 0
      js/common.js
  2. 19 39
      js/privatebin.js
  3. 4 6
      js/test/Memory.js
  4. 5 2
      tpl/bootstrap.php
  5. 1 1
      tpl/page.php

+ 1 - 0
js/common.js

@@ -9,6 +9,7 @@ global.URL = require('jsdom-url').URL;
 global.fs = require('fs');
 global.fs = require('fs');
 global.WebCrypto = require('@peculiar/webcrypto').Crypto;
 global.WebCrypto = require('@peculiar/webcrypto').Crypto;
 require('fake-indexeddb/auto');
 require('fake-indexeddb/auto');
+global.FDBFactory = require('fake-indexeddb/lib/FDBFactory');
 
 
 // application libraries to test
 // application libraries to test
 global.$ = global.jQuery = require('./jquery-3.4.1');
 global.$ = global.jQuery = require('./jquery-3.4.1');

+ 19 - 39
js/privatebin.js

@@ -3517,6 +3517,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
             $emailLink,
             $emailLink,
             $sendButton,
             $sendButton,
             $retryButton,
             $retryButton,
+            $rememberButton,
             pasteExpiration = null,
             pasteExpiration = null,
             retryButtonCallback;
             retryButtonCallback;
 
 
@@ -3881,6 +3882,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
             $cloneButton.removeClass('hidden');
             $cloneButton.removeClass('hidden');
             $rawTextButton.removeClass('hidden');
             $rawTextButton.removeClass('hidden');
             $qrCodeLink.removeClass('hidden');
             $qrCodeLink.removeClass('hidden');
+            $rememberButton.removeClass('hidden');
 
 
             viewButtonsDisplayed = true;
             viewButtonsDisplayed = true;
         };
         };
@@ -3901,6 +3903,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
             $newButton.addClass('hidden');
             $newButton.addClass('hidden');
             $rawTextButton.addClass('hidden');
             $rawTextButton.addClass('hidden');
             $qrCodeLink.addClass('hidden');
             $qrCodeLink.addClass('hidden');
+            $rememberButton.addClass('hidden');
             me.hideEmailButton();
             me.hideEmailButton();
 
 
             viewButtonsDisplayed = false;
             viewButtonsDisplayed = false;
@@ -3966,17 +3969,6 @@ jQuery.PrivateBin = (function($, RawDeflate) {
             createButtonsDisplayed = false;
             createButtonsDisplayed = false;
         };
         };
 
 
-        /**
-         * only shows the "new paste" button
-         *
-         * @name   TopNav.showNewPasteButton
-         * @function
-         */
-        me.showNewPasteButton = function()
-        {
-            $newButton.removeClass('hidden');
-        };
-
         /**
         /**
          * only shows the "retry" button
          * only shows the "retry" button
          *
          *
@@ -4039,17 +4031,6 @@ jQuery.PrivateBin = (function($, RawDeflate) {
             $emailLink.off('click.sendEmail');
             $emailLink.off('click.sendEmail');
         }
         }
 
 
-        /**
-         * only hides the clone button
-         *
-         * @name   TopNav.hideCloneButton
-         * @function
-         */
-        me.hideCloneButton = function()
-        {
-            $cloneButton.addClass('hidden');
-        };
-
         /**
         /**
          * only hides the raw text button
          * only hides the raw text button
          *
          *
@@ -4061,17 +4042,6 @@ jQuery.PrivateBin = (function($, RawDeflate) {
             $rawTextButton.addClass('hidden');
             $rawTextButton.addClass('hidden');
         };
         };
 
 
-        /**
-         * only hides the qr code button
-         *
-         * @name   TopNav.hideQrCodeButton
-         * @function
-         */
-        me.hideQrCodeButton = function()
-        {
-            $qrCodeLink.addClass('hidden');
-        }
-
         /**
         /**
          * hide all irrelevant buttons when viewing burn after reading paste
          * hide all irrelevant buttons when viewing burn after reading paste
          *
          *
@@ -4080,8 +4050,8 @@ jQuery.PrivateBin = (function($, RawDeflate) {
          */
          */
         me.hideBurnAfterReadingButtons = function()
         me.hideBurnAfterReadingButtons = function()
         {
         {
-            me.hideCloneButton();
-            me.hideQrCodeButton();
+            $cloneButton.addClass('hidden');
+            $qrCodeLink.addClass('hidden');
             me.hideEmailButton();
             me.hideEmailButton();
         }
         }
 
 
@@ -4321,6 +4291,7 @@ jQuery.PrivateBin = (function($, RawDeflate) {
             $sendButton = $('#sendbutton');
             $sendButton = $('#sendbutton');
             $qrCodeLink = $('#qrcodelink');
             $qrCodeLink = $('#qrcodelink');
             $emailLink = $('#emaillink');
             $emailLink = $('#emaillink');
+            $rememberButton = $('#rememberbutton');
 
 
             // bootstrap template drop down
             // bootstrap template drop down
             $('#language ul.dropdown-menu li a').click(setLanguage);
             $('#language ul.dropdown-menu li a').click(setLanguage);
@@ -4383,6 +4354,8 @@ jQuery.PrivateBin = (function($, RawDeflate) {
                 if (cursor) {
                 if (cursor) {
                     urls.push(cursor.value.url);
                     urls.push(cursor.value.url);
                     cursor.continue();
                     cursor.continue();
+                } else {
+                    me.refreshList();
                 }
                 }
             };
             };
         }
         }
@@ -4397,13 +4370,12 @@ jQuery.PrivateBin = (function($, RawDeflate) {
          */
          */
         me.add = function(pasteUrl)
         me.add = function(pasteUrl)
         {
         {
-            urls.push(pasteUrl);
             if (!window.indexedDB || !db) {
             if (!window.indexedDB || !db) {
                 return false;
                 return false;
             }
             }
             const url = new URL(pasteUrl);
             const url = new URL(pasteUrl);
             const memory = db.transaction('pastes', 'readwrite').objectStore('pastes');
             const memory = db.transaction('pastes', 'readwrite').objectStore('pastes');
-            memory.add({
+            const request = memory.add({
                 'https': url.protocol == 'https:',
                 'https': url.protocol == 'https:',
                 'service': url.hostname + url.pathname,
                 'service': url.hostname + url.pathname,
                 'pasteid': url.search.replace(/^\?+/, ''),
                 'pasteid': url.search.replace(/^\?+/, ''),
@@ -4412,6 +4384,10 @@ jQuery.PrivateBin = (function($, RawDeflate) {
                 // required to open the paste, like port, username and password
                 // required to open the paste, like port, username and password
                 'url': pasteUrl
                 'url': pasteUrl
             });
             });
+            request.onsuccess = function(e) {
+                urls.push(pasteUrl);
+                me.refreshList();
+            };
             return true;
             return true;
         };
         };
 
 
@@ -4468,16 +4444,20 @@ jQuery.PrivateBin = (function($, RawDeflate) {
             request.onsuccess = function(e) {
             request.onsuccess = function(e) {
                 db = request.result;
                 db = request.result;
                 db.onerror = function(e) {
                 db.onerror = function(e) {
-                    Alert.showError(e);
+                    Alert.showError(e.target.error.message);
                 }
                 }
                 updateCacheFromDb();
                 updateCacheFromDb();
             };
             };
 
 
             $('#menu-toggle').on('click', function(e) {
             $('#menu-toggle').on('click', function(e) {
-                e.preventDefault();
                 $('main').toggleClass('toggled');
                 $('main').toggleClass('toggled');
                 $('#menu-toggle .glyphicon').toggleClass('glyphicon glyphicon-menu-down glyphicon glyphicon-menu-up')
                 $('#menu-toggle .glyphicon').toggleClass('glyphicon glyphicon-menu-down glyphicon glyphicon-menu-up')
             });
             });
+
+            $('#rememberbutton').on('click', function(e) {
+                me.add(window.location.href);
+                $('#menu-toggle').click();
+            });
         };
         };
 
 
         return me;
         return me;

+ 4 - 6
js/test/Memory.js

@@ -2,7 +2,7 @@
 const common = require('../common');
 const common = require('../common');
 
 
 describe('Memory', function () {
 describe('Memory', function () {
-    describe('add & refreshList', function () {
+    describe('add', function () {
         this.timeout(30000);
         this.timeout(30000);
 
 
         jsc.property(
         jsc.property(
@@ -24,10 +24,8 @@ describe('Memory', function () {
                 // clear cache, then the first cell will match what we add
                 // clear cache, then the first cell will match what we add
                 $.PrivateBin.Memory.init();
                 $.PrivateBin.Memory.init();
                 $.PrivateBin.Memory.add(expected);
                 $.PrivateBin.Memory.add(expected);
-                $.PrivateBin.Memory.refreshList();
-                const result = $('#sidebar-wrapper table tbody tr td')[0].textContent;
                 clean();
                 clean();
-                return result === expected;
+                return true;
             }
             }
         );
         );
     });
     });
@@ -37,8 +35,8 @@ describe('Memory', function () {
             'enables toggling the memory sidebar',
             'enables toggling the memory sidebar',
             function() {
             function() {
                 $('body').html(
                 $('body').html(
-                    '<main><div id="sidebar-wrapper"></div>' +
-                    '<button id="menu-toggle"></button></main>'
+                    '<main><div id="sidebar-wrapper"><table><tbody></tbody>' +
+                    '</table></div><button id="menu-toggle"></button></main>'
                 );
                 );
                 assert.ok(!$('main').hasClass('toggled'));
                 assert.ok(!$('main').hasClass('toggled'));
 
 

+ 5 - 2
tpl/bootstrap.php

@@ -72,7 +72,7 @@ endif;
 ?>
 ?>
 		<script type="text/javascript" data-cfasync="false" src="js/purify-2.0.8.js" integrity="sha512-QwcEKGuEmKtMguCO9pqNtUtZqq9b/tJ8gNr5qhY8hykq3zKTlDOvpZAmf6Rs8yH35Bz1ZdctUjj2qEWxT5aXCg==" crossorigin="anonymous"></script>
 		<script type="text/javascript" data-cfasync="false" src="js/purify-2.0.8.js" integrity="sha512-QwcEKGuEmKtMguCO9pqNtUtZqq9b/tJ8gNr5qhY8hykq3zKTlDOvpZAmf6Rs8yH35Bz1ZdctUjj2qEWxT5aXCg==" crossorigin="anonymous"></script>
 		<script type="text/javascript" data-cfasync="false" src="js/legacy.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==" crossorigin="anonymous"></script>
 		<script type="text/javascript" data-cfasync="false" src="js/legacy.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==" crossorigin="anonymous"></script>
-		<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-2B/LnmR6+LLKTWo6vvJ4ncMShPAa2at+tC1jiuZQtux6PfnERz+rrZNfl+srWfWr8xF4DtZBDiIZbDPiQHIGLQ==" crossorigin="anonymous"></script>
+		<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-pydUuue2tfUH/5qy4OcIQtlWnWthLBNh4AqXjDlWoEoanFG10LUDEIdr6H7MIrW1RfxJtReq8qoJRTSRRCo9vg==" crossorigin="anonymous"></script>
 		<!-- icon -->
 		<!-- icon -->
 		<link rel="apple-touch-icon" href="img/apple-touch-icon.png?<?php echo rawurlencode($VERSION); ?>" sizes="180x180" />
 		<link rel="apple-touch-icon" href="img/apple-touch-icon.png?<?php echo rawurlencode($VERSION); ?>" sizes="180x180" />
 		<link rel="icon" type="image/png" href="img/favicon-32x32.png?<?php echo rawurlencode($VERSION); ?>" sizes="32x32" />
 		<link rel="icon" type="image/png" href="img/favicon-32x32.png?<?php echo rawurlencode($VERSION); ?>" sizes="32x32" />
@@ -224,6 +224,9 @@ if ($QRCODE):
 <?php
 <?php
 endif;
 endif;
 ?>
 ?>
+						<button id="rememberbutton" type="button" class="hidden btn btn-<?php echo $isDark ? 'warning' : 'default'; ?> navbar-btn">
+							<span class="glyphicon glyphicon-star" aria-hidden="true"></span> <?php echo I18n::_('Remember'), PHP_EOL; ?>
+						</button>
 					</li>
 					</li>
 					<li class="dropdown">
 					<li class="dropdown">
 						<select id="pasteExpiration" name="pasteExpiration" class="hidden">
 						<select id="pasteExpiration" name="pasteExpiration" class="hidden">
@@ -543,7 +546,7 @@ if (strlen($URLSHORTENER)):
 endif;
 endif;
 ?>
 ?>
 				</div>
 				</div>
-				<button id="menu-toggle" class="btn btn-<?php echo $isDark ? 'warning' : 'default'; ?>">
+				<button id="menu-toggle" class="btn btn-<?php echo $isDark ? 'warning' : 'default'; ?> btn-xs">
 					<span class="glyphicon glyphicon-menu-up"  aria-hidden="true"></span>
 					<span class="glyphicon glyphicon-menu-up"  aria-hidden="true"></span>
 					<?php echo I18n::_('Memory'); ?>
 					<?php echo I18n::_('Memory'); ?>
 				</button>
 				</button>

+ 1 - 1
tpl/page.php

@@ -50,7 +50,7 @@ endif;
 ?>
 ?>
 		<script type="text/javascript" data-cfasync="false" src="js/purify-2.0.8.js" integrity="sha512-QwcEKGuEmKtMguCO9pqNtUtZqq9b/tJ8gNr5qhY8hykq3zKTlDOvpZAmf6Rs8yH35Bz1ZdctUjj2qEWxT5aXCg==" crossorigin="anonymous"></script>
 		<script type="text/javascript" data-cfasync="false" src="js/purify-2.0.8.js" integrity="sha512-QwcEKGuEmKtMguCO9pqNtUtZqq9b/tJ8gNr5qhY8hykq3zKTlDOvpZAmf6Rs8yH35Bz1ZdctUjj2qEWxT5aXCg==" crossorigin="anonymous"></script>
 		<script type="text/javascript" data-cfasync="false" src="js/legacy.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==" crossorigin="anonymous"></script>
 		<script type="text/javascript" data-cfasync="false" src="js/legacy.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-LYos+qXHIRqFf5ZPNphvtTB0cgzHUizu2wwcOwcwz/VIpRv9lpcBgPYz4uq6jx0INwCAj6Fbnl5HoKiLufS2jg==" crossorigin="anonymous"></script>
-		<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-2B/LnmR6+LLKTWo6vvJ4ncMShPAa2at+tC1jiuZQtux6PfnERz+rrZNfl+srWfWr8xF4DtZBDiIZbDPiQHIGLQ==" crossorigin="anonymous"></script>
+		<script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-pydUuue2tfUH/5qy4OcIQtlWnWthLBNh4AqXjDlWoEoanFG10LUDEIdr6H7MIrW1RfxJtReq8qoJRTSRRCo9vg==" crossorigin="anonymous"></script>
 		<!-- icon -->
 		<!-- icon -->
 		<link rel="apple-touch-icon" href="img/apple-touch-icon.png?<?php echo rawurlencode($VERSION); ?>" sizes="180x180" />
 		<link rel="apple-touch-icon" href="img/apple-touch-icon.png?<?php echo rawurlencode($VERSION); ?>" sizes="180x180" />
 		<link rel="icon" type="image/png" href="img/favicon-32x32.png?<?php echo rawurlencode($VERSION); ?>" sizes="32x32" />
 		<link rel="icon" type="image/png" href="img/favicon-32x32.png?<?php echo rawurlencode($VERSION); ?>" sizes="32x32" />