refactor: getbookmarks
This commit is contained in:
		
							parent
							
								
									63286cd4ec
								
							
						
					
					
						commit
						e610b306df
					
				
							
								
								
									
										22
									
								
								main.js
								
								
								
								
							
							
						
						
									
										22
									
								
								main.js
								
								
								
								
							| 
						 | 
					@ -316,11 +316,15 @@ var snippets = [
 | 
				
			||||||
	insert: "x " + (new Date).toISOString().substring(0, 10) + " "
 | 
						insert: "x " + (new Date).toISOString().substring(0, 10) + " "
 | 
				
			||||||
}];
 | 
					}];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					function getbookmarks()
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						var note = getnote("bookmarks") || {title: "bookmarks", content: "[]"};
 | 
				
			||||||
 | 
						return JSON.parse(note.content);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function browsebookmarks()
 | 
					function browsebookmarks()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	var bookmarks = JSON.parse(getnote("bookmarks").content);
 | 
						searchinlist(getbookmarks().map(b => b.title))
 | 
				
			||||||
	searchinlist(bookmarks.map(b => b.title))
 | 
					 | 
				
			||||||
	.then(openbookmark);
 | 
						.then(openbookmark);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1195,14 +1199,8 @@ function loadstorage()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (clip)
 | 
						if (clip)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		var bmnote = getnote("bookmarks");
 | 
							var bmnote = getorcreate("bookmarks", "[]");
 | 
				
			||||||
		if (!bmnote)
 | 
							var bookmarks = getbookmarks();
 | 
				
			||||||
		{
 | 
					 | 
				
			||||||
			bmnote = {title: "bookmarks", content: "[]"};
 | 
					 | 
				
			||||||
			localdata.unshift(bmnote);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		var bookmarks = JSON.parse(bmnote.content);
 | 
					 | 
				
			||||||
		bookmarks.unshift(JSON.parse(clip));
 | 
							bookmarks.unshift(JSON.parse(clip));
 | 
				
			||||||
		bmnote.content = JSON.stringify(bookmarks, null, " ");
 | 
							bmnote.content = JSON.stringify(bookmarks, null, " ");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1634,7 +1632,7 @@ function titlewithtags(note)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function openbookmark(title)
 | 
					function openbookmark(title)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	window.open(JSON.parse(getnote("bookmarks").content).find(b => b.title == title).url, "_blank");
 | 
						window.open(getbookmarks().find(b => b.title == title).url, "_blank");
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function commandpalette()
 | 
					function commandpalette()
 | 
				
			||||||
| 
						 | 
					@ -1672,7 +1670,7 @@ function commandpalette()
 | 
				
			||||||
				suffix: s == "password" ? null : [settings[s]]
 | 
									suffix: s == "password" ? null : [settings[s]]
 | 
				
			||||||
			};
 | 
								};
 | 
				
			||||||
		}))
 | 
							}))
 | 
				
			||||||
		.concat(JSON.parse((getnote("bookmarks") || {content: "[]"}).content).map(b =>
 | 
							.concat(getbookmarks().map(b =>
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return {
 | 
								return {
 | 
				
			||||||
				prefix: "open bookmark ",
 | 
									prefix: "open bookmark ",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue