mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	Add already-section when pageurl matches existing note.
Trigger search note by url after connection to backend
This commit is contained in:
		| @@ -444,4 +444,8 @@ browser.runtime.onMessage.addListener(async request => { | ||||
| 	else if (request.name === 'send-trilium-search-status') { | ||||
| 		triliumServerFacade.sendTriliumSearchStatusToPopup(); | ||||
| 	} | ||||
| 	else if (request.name === 'trigger-trilium-search-note-url') { | ||||
| 		const activeTab = await getActiveTab(); | ||||
| 		triliumServerFacade.triggerSearchNoteByUrl(activeTab.url); | ||||
| 	} | ||||
| }); | ||||
|   | ||||
| @@ -11,12 +11,14 @@ | ||||
|   <div style="display: flex; justify-content: space-between; vertical-align: middle;"> | ||||
|     <h3>Trilium Web Clipper</h3> | ||||
|      | ||||
|  | ||||
|     <div style="position: relative; top: 6px;"> | ||||
|       <button class="button" id="show-options-button">Options</button> | ||||
|  | ||||
|       <button class="button" id="show-help-button">Help</button> | ||||
|     </div> | ||||
|   </div> | ||||
|   <div id="already-visited"></div> | ||||
|  | ||||
|   <button class="button full needs-connection" id="save-cropped-screenshot-button">Crop screen shot</button> | ||||
|   <button class="button full needs-connection" id="save-whole-screenshot-button">Save whole screen shot</button> | ||||
| @@ -44,6 +46,7 @@ | ||||
|   <script src="../lib/cash.min.js"></script> | ||||
|   <script src="popup.js"></script> | ||||
|   <script src="../utils.js"></script> | ||||
|   <script src="../content.js"></script> | ||||
| </body> | ||||
|  | ||||
| </html> | ||||
|   | ||||
| @@ -108,6 +108,7 @@ function escapeHtml(string) { | ||||
|  | ||||
| const $connectionStatus = $("#connection-status"); | ||||
| const $needsConnection = $(".needs-connection"); | ||||
| const $alreadyVisited = $("#already-visited"); | ||||
|  | ||||
| browser.runtime.onMessage.addListener(request => { | ||||
|     if (request.name === 'trilium-search-status') { | ||||
| @@ -140,12 +141,27 @@ browser.runtime.onMessage.addListener(request => { | ||||
|         if (isConnected) { | ||||
|             $needsConnection.removeAttr("disabled"); | ||||
|             $needsConnection.removeAttr("title"); | ||||
|             browser.runtime.sendMessage({name: "trigger-trilium-search-note-url"}); | ||||
|         } | ||||
|         else { | ||||
|             $needsConnection.attr("disabled", "disabled"); | ||||
|             $needsConnection.attr("title", "This action can't be performed without active connection to Trilium."); | ||||
|         } | ||||
|     } | ||||
|     else if (request.name == "trilium-previously-visited"){ | ||||
|         const {searchNote} = request; | ||||
|         if (searchNote.status === 'found'){ | ||||
|             const a = createLink({name: 'openNoteInTrilium', noteId: searchNote.noteId}, | ||||
|             "Open in Trilium.") | ||||
|             noteFound = `Already visited website!`; | ||||
|             $alreadyVisited.html(noteFound); | ||||
|             $alreadyVisited[0].appendChild(a); | ||||
|         }else{ | ||||
|             $alreadyVisited.html(''); | ||||
|         } | ||||
|          | ||||
|  | ||||
|     } | ||||
| }); | ||||
|  | ||||
| const $checkConnectionButton = $("#check-connection-button"); | ||||
|   | ||||
| @@ -23,6 +23,21 @@ class TriliumServerFacade { | ||||
| 		} | ||||
| 		catch (e) {} // nothing might be listening | ||||
| 	} | ||||
| 	async sendTriliumSearchNoteToPopup(){ | ||||
| 		try{ | ||||
| 			await browser.runtime.sendMessage({ | ||||
| 				name: "trilium-previously-visited", | ||||
| 				searchNote: this.triliumSearchNote | ||||
| 			}) | ||||
|  | ||||
| 		} | ||||
| 		catch (e) {} // nothing might be listening | ||||
| 	} | ||||
|  | ||||
| 	setTriliumSearchNote(st){ | ||||
| 		this.triliumSearchNote = st; | ||||
| 		this.sendTriliumSearchNoteToPopup(); | ||||
| 	} | ||||
|  | ||||
| 	setTriliumSearch(ts) { | ||||
| 		this.triliumSearch = ts; | ||||
| @@ -116,6 +131,18 @@ class TriliumServerFacade { | ||||
| 		this.setTriliumSearch({ status: 'not-found' }); | ||||
| 	} | ||||
|  | ||||
| 	async triggerSearchNoteByUrl(noteUrl) { | ||||
| 		const resp = await triliumServerFacade.callService('GET', 'notes-by-url/' + encodeURIComponent(noteUrl)) | ||||
| 		let newStatus = { | ||||
| 			status: 'not-found', | ||||
| 			noteId: null | ||||
| 		} | ||||
| 		if (resp && resp.noteId) { | ||||
| 			newStatus.noteId = resp.noteId; | ||||
| 			newStatus.status = 'found'; | ||||
| 		} | ||||
| 		this.setTriliumSearchNote(newStatus); | ||||
| 	} | ||||
| 	async waitForTriliumSearch() { | ||||
| 		return new Promise((res, rej) => { | ||||
| 			const checkStatus = () => { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user