added: amount of data sent in stats
added: download all vaults added: confirmation before switching vault added: tab/shift+tab to indent/unindent
This commit is contained in:
		
							parent
							
								
									43b70a187b
								
							
						
					
					
						commit
						d879c324c8
					
				
							
								
								
									
										124
									
								
								main.js
								
								
								
								
							
							
						
						
									
										124
									
								
								main.js
								
								
								
								
							|  | @ -42,12 +42,14 @@ var stat = | ||||||
| 	ses: | 	ses: | ||||||
| 	{ | 	{ | ||||||
| 		q: 0, | 		q: 0, | ||||||
| 		t: timestamp() | 		t: timestamp(), | ||||||
|  | 		d: 0 | ||||||
| 	}, | 	}, | ||||||
| 	cur: | 	cur: | ||||||
| 	{ | 	{ | ||||||
| 		q: 0, | 		q: 0, | ||||||
| 		t: timestamp() | 		t: timestamp(), | ||||||
|  | 		d: 0 | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -313,17 +315,21 @@ var commands = [ | ||||||
| 	action: comment | 	action: comment | ||||||
| }, | }, | ||||||
| { | { | ||||||
| 	hint: "Download note", | 	hint: "Download current note", | ||||||
| 	action: downloadnote | 	action: downloadnote | ||||||
| }, | }, | ||||||
| { | { | ||||||
| 	hint: "Download note with merged subnotes", | 	hint: "Download current note with merged subnotes", | ||||||
| 	action: downloadnotewithsubs | 	action: downloadnotewithsubs | ||||||
| }, | }, | ||||||
| { | { | ||||||
| 	hint: "Download vault", | 	hint: "Download current vault", | ||||||
| 	action: downloadvault, | 	action: downloadvault, | ||||||
| 	shortcut: "ctrl+shift+S" | 	shortcut: "ctrl+shift+S" | ||||||
|  | }, | ||||||
|  | { | ||||||
|  | 	hint: "Download all vaults", | ||||||
|  | 	action: downloadallvaults | ||||||
| }]; | }]; | ||||||
| 
 | 
 | ||||||
| var snippets = [ | var snippets = [ | ||||||
|  | @ -456,6 +462,22 @@ function togglespellcheck() | ||||||
| 	md.spellcheck = !md.spellcheck; | 	md.spellcheck = !md.spellcheck; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | function formatsize(size) | ||||||
|  | { | ||||||
|  | 	var unit = "b"; | ||||||
|  | 	if (size > 1024) | ||||||
|  | 	{ | ||||||
|  | 		size /= 1024; | ||||||
|  | 		unit = "kb"; | ||||||
|  | 	} | ||||||
|  | 	if (size > 1024) | ||||||
|  | 	{ | ||||||
|  | 		size /= 1024; | ||||||
|  | 		unit = "mb"; | ||||||
|  | 	} | ||||||
|  |  	return size.toFixed(2) + " " + unit; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| function showinfo() | function showinfo() | ||||||
| { | { | ||||||
| 	var tags = gettags(currentnote); | 	var tags = gettags(currentnote); | ||||||
|  | @ -465,12 +487,15 @@ function showinfo() | ||||||
| 			"vault: " + currentvault, | 			"vault: " + currentvault, | ||||||
| 			(tags ? "tags: " + tags : ""), | 			(tags ? "tags: " + tags : ""), | ||||||
| 			"saved: " + saved, | 			"saved: " + saved, | ||||||
|  | 			"spell check: " + (md.spellcheck ? "en" : "dis") + "abled", | ||||||
| 			"word count: " + getwords(), | 			"word count: " + getwords(), | ||||||
| 			"current filter: " + currenttag || "", | 			"current filter: " + currenttag || "", | ||||||
| 			"current note start: " + stat.cur.t, | 			"current note start: " + stat.cur.t, | ||||||
| 			"current note queries: " + stat.cur.q, | 			"current note queries: " + stat.cur.q, | ||||||
|  | 			"current note data sent: " + formatsize(stat.cur.d), | ||||||
| 			"session start: " + stat.ses.t, | 			"session start: " + stat.ses.t, | ||||||
| 			"session queries: " + stat.ses.q | 			"session queries: " + stat.ses.q, | ||||||
|  | 			"session data sent: " + formatsize(stat.ses.d) | ||||||
| 		], "Note info"); | 		], "Note info"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -530,7 +555,11 @@ function applyvault(vault) | ||||||
| 
 | 
 | ||||||
| function switchvault() | function switchvault() | ||||||
| { | { | ||||||
| 	applyvault(currentvault == "local" ? "remote" : "local"); | 	var newvault = currentvault == "local" ? "remote" : "local"; | ||||||
|  | 	if (confirm("Switch to " + newvault + "?")) | ||||||
|  | 	{ | ||||||
|  | 		applyvault(newvault); | ||||||
|  | 	}	 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function selectvault() | function selectvault() | ||||||
|  | @ -873,6 +902,18 @@ function downloadnotes() | ||||||
| 	}); | 	}); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | function downloadallvaults() | ||||||
|  | { | ||||||
|  | 	var data =  | ||||||
|  | 	{ | ||||||
|  | 		local: JSON.parse(window.localStorage.getItem("local")), | ||||||
|  | 		remote: JSON.parse(window.localStorage.getItem("remote")), | ||||||
|  | 		sandbox: JSON.parse(window.localStorage.getItem("sandbox")), | ||||||
|  | 		trash: JSON.parse(window.localStorage.getItem("trash")), | ||||||
|  | 	}; | ||||||
|  | 	download("notes " + timestamp() + ".json", JSON.stringify(data)); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| function downloadvault() | function downloadvault() | ||||||
| { | { | ||||||
| 	download("notes " + timestamp() + " " + currentvault + ".json", window.localStorage.getItem(currentvault)); | 	download("notes " + timestamp() + " " + currentvault + ".json", window.localStorage.getItem(currentvault)); | ||||||
|  | @ -1112,6 +1153,9 @@ function queryremote(params) | ||||||
| 			paramlist.push(i + "=" + encodeURIComponent(params[i])); | 			paramlist.push(i + "=" + encodeURIComponent(params[i])); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
|  | 		stat.cur.d += paramlist.join("&").length; | ||||||
|  | 		stat.ses.d += paramlist.join("&").length; | ||||||
|  | 
 | ||||||
| 		var xhr = new XMLHttpRequest(); | 		var xhr = new XMLHttpRequest(); | ||||||
| 		xhr.open("POST", "handler.php"); | 		xhr.open("POST", "handler.php"); | ||||||
| 		xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | 		xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); | ||||||
|  | @ -2015,49 +2059,40 @@ function editorkeydown() | ||||||
| 	else if (event.key === "Tab") | 	else if (event.key === "Tab") | ||||||
| 	{ | 	{ | ||||||
| 		event.preventDefault(); | 		event.preventDefault(); | ||||||
|         // todo: reverse with shift
 | 		var init = { | ||||||
| 		if (before(2) == "* " || before(2) == "- ") | 			start: md.selectionStart, | ||||||
|  | 			end: md.selectionEnd | ||||||
|  | 		}; | ||||||
|  | 		var range = getlinesrange(); | ||||||
|  | 		range.start--; | ||||||
|  | 		range.end--; | ||||||
|  | 		var selection = md.value.substring(range.start, range.end); | ||||||
|  | 		var newtext; | ||||||
|  | 		if (event.shiftKey) | ||||||
| 		{ | 		{ | ||||||
| 			setpos(getpos() - 2); | 			newtext = selection.replaceAll("\n    ", "\n"); | ||||||
| 			insert("    ", 2); |  | ||||||
| 		} | 		} | ||||||
| 		else | 		else | ||||||
| 		{ | 		{ | ||||||
| 			var init = { | 			newtext = selection.replaceAll("\n", "\n    "); | ||||||
| 				start: md.selectionStart, |  | ||||||
| 				end: md.selectionEnd |  | ||||||
| 			}; |  | ||||||
| 			var range = getlinesrange(); |  | ||||||
| 			range.start--; |  | ||||||
| 			range.end--; |  | ||||||
| 			var selection = md.value.substring(range.start, range.end); |  | ||||||
| 			var newtext; |  | ||||||
| 			if (event.shiftKey) |  | ||||||
| 			{ |  | ||||||
| 				newtext = selection.replaceAll("\n    ", "\n"); |  | ||||||
| 			} |  | ||||||
| 			else |  | ||||||
| 			{ |  | ||||||
| 				newtext = selection.replaceAll("\n", "\n    "); |  | ||||||
| 
 | 
 | ||||||
| 			} |  | ||||||
| 			md.value = md.value.substring(0, range.start) |  | ||||||
| 			+ newtext |  | ||||||
| 			+ md.value.substring(range.end); |  | ||||||
| 
 |  | ||||||
| 			var shift = 0; |  | ||||||
| 			if (newtext.length < selection.length) |  | ||||||
| 			{ |  | ||||||
| 				shift = -4; |  | ||||||
| 			} |  | ||||||
| 			else if (newtext.length > selection.length) |  | ||||||
| 			{ |  | ||||||
| 				shift = 4; |  | ||||||
| 			} |  | ||||||
| 
 |  | ||||||
| 			md.selectionStart = init.start + shift; |  | ||||||
| 			md.selectionEnd = init.end + (newtext.length - selection.length); |  | ||||||
| 		} | 		} | ||||||
|  | 		md.value = md.value.substring(0, range.start) | ||||||
|  | 		+ newtext | ||||||
|  | 		+ md.value.substring(range.end); | ||||||
|  | 
 | ||||||
|  | 		var shift = 0; | ||||||
|  | 		if (newtext.length < selection.length) | ||||||
|  | 		{ | ||||||
|  | 			shift = -4; | ||||||
|  | 		} | ||||||
|  | 		else if (newtext.length > selection.length) | ||||||
|  | 		{ | ||||||
|  | 			shift = 4; | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		md.selectionStart = init.start + shift; | ||||||
|  | 		md.selectionEnd = init.end + (newtext.length - selection.length); | ||||||
| 	} | 	} | ||||||
| 	else if (event.key === "[" && before(1) == "[") | 	else if (event.key === "[" && before(1) == "[") | ||||||
| 	{ | 	{ | ||||||
|  | @ -2159,6 +2194,7 @@ function loadnote(name) | ||||||
| 	putontop(); | 	putontop(); | ||||||
| 
 | 
 | ||||||
| 	stat.cur.q = 0; | 	stat.cur.q = 0; | ||||||
|  | 	stat.cur.d = 0; | ||||||
| 	stat.cur.t = timestamp(); | 	stat.cur.t = timestamp(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 quenousimporte
						quenousimporte