mirror of
https://github.com/Tygs/0bin.git
synced 2023-08-10 21:13:00 +03:00
added previous pastes saving in localstorage
This commit is contained in:
parent
1fa7218c7d
commit
af3d088ea4
@ -33,7 +33,13 @@ zerobin = {
|
|||||||
},
|
},
|
||||||
get_time: function(){
|
get_time: function(){
|
||||||
var date = new Date();
|
var date = new Date();
|
||||||
return date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();
|
var h=date.getHours();
|
||||||
|
var m=date.getMinutes();
|
||||||
|
var s=date.getSeconds();
|
||||||
|
if (h<10) {h = "0" + h}
|
||||||
|
if (m<10) {m = "0" + m}
|
||||||
|
if (s<10) {s = "0" + s}
|
||||||
|
return h+":"+m+":"+s;
|
||||||
},
|
},
|
||||||
support_localstorage: function(){
|
support_localstorage: function(){
|
||||||
if (localStorage){
|
if (localStorage){
|
||||||
@ -47,25 +53,22 @@ zerobin = {
|
|||||||
var date = new Date();
|
var date = new Date();
|
||||||
var paste = zerobin.get_date()+" "+zerobin.get_time()+";"+url;
|
var paste = zerobin.get_date()+" "+zerobin.get_time()+";"+url;
|
||||||
if (localStorage.length > 19)
|
if (localStorage.length > 19)
|
||||||
void removeItem(localStorage.length);
|
void removeItem(0);
|
||||||
localStorage.setItem(localStorage.length, paste);
|
localStorage.setItem(localStorage.length, paste);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
get_pastes: function(){
|
get_pastes: function(){
|
||||||
if (zerobin.support_localstorage){
|
if (zerobin.support_localstorage){
|
||||||
var date = new Date();
|
var pastes = '';
|
||||||
var pastes = '';
|
|
||||||
var key = '';
|
|
||||||
|
|
||||||
for (i=0; i<=localStorage.length-1; i++)
|
for (i=localStorage.length-1; i>=0; i--)
|
||||||
{
|
{
|
||||||
key = localStorage.key(i);
|
if (localStorage.getItem(i).split(';')[0].split(' ')[0] == zerobin.get_date()){
|
||||||
if (localStorage.getItem(key).split(';')[0].split(' ')[0] == zerobin.get_date()){
|
var display_date = localStorage.getItem(i).split(';')[0].split(' ')[1];
|
||||||
var display_date = localStorage.getItem(key).split(';')[0].split(' ')[1];
|
|
||||||
}else{
|
}else{
|
||||||
var display_date = zerobin.get_date();
|
var display_date = zerobin.get_date();
|
||||||
}
|
}
|
||||||
pastes = pastes + '<li><a class="items" href="' + localStorage.getItem(key).split(';')[1] + '">' + display_date + '</a></li>';
|
pastes = pastes + '<li><a class="items" href="' + localStorage.getItem(i).split(';')[1] + '">' + display_date + '</a></li>';
|
||||||
}
|
}
|
||||||
if (!pastes){
|
if (!pastes){
|
||||||
return '<i class="grey">Your previous pastes will be saved in your browser <a href="http://www.w3.org/TR/webstorage/">localStorage</a>.</i>';
|
return '<i class="grey">Your previous pastes will be saved in your browser <a href="http://www.w3.org/TR/webstorage/">localStorage</a>.</i>';
|
||||||
|
Loading…
Reference in New Issue
Block a user