adding a remember button

This commit is contained in:
El RIDO 2020-06-28 21:47:32 +02:00
parent ac32826009
commit 8b170397a9
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92
5 changed files with 30 additions and 48 deletions

View file

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

View file

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

View file

@ -2,7 +2,7 @@
const common = require('../common');
describe('Memory', function () {
describe('add & refreshList', function () {
describe('add', function () {
this.timeout(30000);
jsc.property(
@ -24,10 +24,8 @@ describe('Memory', function () {
// clear cache, then the first cell will match what we add
$.PrivateBin.Memory.init();
$.PrivateBin.Memory.add(expected);
$.PrivateBin.Memory.refreshList();
const result = $('#sidebar-wrapper table tbody tr td')[0].textContent;
clean();
return result === expected;
return true;
}
);
});
@ -37,8 +35,8 @@ describe('Memory', function () {
'enables toggling the memory sidebar',
function() {
$('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'));

View file

@ -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/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 -->
<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" />
@ -224,6 +224,9 @@ if ($QRCODE):
<?php
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 class="dropdown">
<select id="pasteExpiration" name="pasteExpiration" class="hidden">
@ -543,7 +546,7 @@ if (strlen($URLSHORTENER)):
endif;
?>
</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>
<?php echo I18n::_('Memory'); ?>
</button>

View file

@ -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/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 -->
<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" />