allow switching to a memorized paste by clicking it

This commit is contained in:
El RIDO 2020-07-01 21:02:45 +02:00
parent 4e3348795c
commit d027cb188d
No known key found for this signature in database
GPG Key ID: 0F5C940A6BD81F92
3 changed files with 39 additions and 16 deletions

View File

@ -562,10 +562,11 @@ jQuery.PrivateBin = (function($, RawDeflate) {
* *
* @name Helper.reset * @name Helper.reset
* @function * @function
* @param {string} uri - (optional) URI to reset to
*/ */
me.reset = function() me.reset = function(uri)
{ {
baseUri = null; baseUri = typeof uri === 'string' ? uri : null;
}; };
return me; return me;
@ -4389,16 +4390,16 @@ jQuery.PrivateBin = (function($, RawDeflate) {
*/ */
me.add = function(pasteUrl) me.add = function(pasteUrl)
{ {
const url = new URL(pasteUrl); const url = new URL(pasteUrl),
const newPaste = { newPaste = {
'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(/^\?+/, ''),
'key': url.hash.replace(/^#+/, ''), 'key': url.hash.replace(/^#+/, ''),
// we store the full URL as it may contain additonal information // we store the full URL as it may contain additonal information
// required to open the paste, like port, username and password // required to open the paste, like port, username and password
'url': pasteUrl 'url': pasteUrl
}; };
// don't add an already memorized paste // don't add an already memorized paste
if (isInMemory(pasteUrl)) { if (isInMemory(pasteUrl)) {
return false; return false;
@ -4407,14 +4408,33 @@ jQuery.PrivateBin = (function($, RawDeflate) {
if (!window.indexedDB || !db) { if (!window.indexedDB || !db) {
return false; return false;
} }
const memory = db.transaction('pastes', 'readwrite').objectStore('pastes'); const memory = db.transaction('pastes', 'readwrite').objectStore('pastes'),
const request = memory.add(newPaste); request = memory.add(newPaste);
request.onsuccess = function(e) { request.onsuccess = function(e) {
me.refreshList(); me.refreshList();
} }
return true; return true;
}; };
/**
* open a given paste URL using the current instance
*
* @name Memory.open
* @function
* @param {string} pasteUrl
*/
me.open = function(pasteUrl)
{
// parse URL
const url = new URL(pasteUrl);
const baseUri = Helper.baseUri();
history.pushState({type: 'viewpaste'}, document.title, url.search + url.hash);
Helper.reset(url.origin);
Model.reset();
PasteDecrypter.run();
Helper.reset(baseUri);
};
/** /**
* refresh the state of the remember button * refresh the state of the remember button
* *
@ -4450,6 +4470,9 @@ jQuery.PrivateBin = (function($, RawDeflate) {
cell.textContent = paste.url; cell.textContent = paste.url;
row.appendChild(cell); row.appendChild(cell);
$tbody.appendChild(row); $tbody.appendChild(row);
row.addEventListener('click', function () {
me.open(paste.url);
});
}); });
}; };

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/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-SZkPr3E6r0pExLw3xxKtJP6m5kGBSPd3zGhHlVzipEo+muVLaEoucdK6TyaAsxsk2dnwMVfitWfooXdSHeaBEg==" crossorigin="anonymous"></script> <script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-qSwODMjBG5A1mG2x18DCdjCSBjS9JSLaqKtnMQ+wIjJdsuY6Eb603N4Sw2PhN1uJHaL0fAXBg+KOp6t9/lvvfw==" 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" />

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/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-SZkPr3E6r0pExLw3xxKtJP6m5kGBSPd3zGhHlVzipEo+muVLaEoucdK6TyaAsxsk2dnwMVfitWfooXdSHeaBEg==" crossorigin="anonymous"></script> <script type="text/javascript" data-cfasync="false" src="js/privatebin.js?<?php echo rawurlencode($VERSION); ?>" integrity="sha512-qSwODMjBG5A1mG2x18DCdjCSBjS9JSLaqKtnMQ+wIjJdsuY6Eb603N4Sw2PhN1uJHaL0fAXBg+KOp6t9/lvvfw==" 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" />