mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-17 07:12:30 +08:00
Add already-section when pageurl matches existing note.
Trigger search note by url after connection to backend
This commit is contained in:
parent
b731a051f1
commit
1d6211c7fd
@ -444,4 +444,8 @@ browser.runtime.onMessage.addListener(async request => {
|
|||||||
else if (request.name === 'send-trilium-search-status') {
|
else if (request.name === 'send-trilium-search-status') {
|
||||||
triliumServerFacade.sendTriliumSearchStatusToPopup();
|
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;">
|
<div style="display: flex; justify-content: space-between; vertical-align: middle;">
|
||||||
<h3>Trilium Web Clipper</h3>
|
<h3>Trilium Web Clipper</h3>
|
||||||
|
|
||||||
|
|
||||||
<div style="position: relative; top: 6px;">
|
<div style="position: relative; top: 6px;">
|
||||||
<button class="button" id="show-options-button">Options</button>
|
<button class="button" id="show-options-button">Options</button>
|
||||||
|
|
||||||
<button class="button" id="show-help-button">Help</button>
|
<button class="button" id="show-help-button">Help</button>
|
||||||
</div>
|
</div>
|
||||||
</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-cropped-screenshot-button">Crop screen shot</button>
|
||||||
<button class="button full needs-connection" id="save-whole-screenshot-button">Save whole 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="../lib/cash.min.js"></script>
|
||||||
<script src="popup.js"></script>
|
<script src="popup.js"></script>
|
||||||
<script src="../utils.js"></script>
|
<script src="../utils.js"></script>
|
||||||
|
<script src="../content.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
@ -108,6 +108,7 @@ function escapeHtml(string) {
|
|||||||
|
|
||||||
const $connectionStatus = $("#connection-status");
|
const $connectionStatus = $("#connection-status");
|
||||||
const $needsConnection = $(".needs-connection");
|
const $needsConnection = $(".needs-connection");
|
||||||
|
const $alreadyVisited = $("#already-visited");
|
||||||
|
|
||||||
browser.runtime.onMessage.addListener(request => {
|
browser.runtime.onMessage.addListener(request => {
|
||||||
if (request.name === 'trilium-search-status') {
|
if (request.name === 'trilium-search-status') {
|
||||||
@ -140,12 +141,27 @@ browser.runtime.onMessage.addListener(request => {
|
|||||||
if (isConnected) {
|
if (isConnected) {
|
||||||
$needsConnection.removeAttr("disabled");
|
$needsConnection.removeAttr("disabled");
|
||||||
$needsConnection.removeAttr("title");
|
$needsConnection.removeAttr("title");
|
||||||
|
browser.runtime.sendMessage({name: "trigger-trilium-search-note-url"});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$needsConnection.attr("disabled", "disabled");
|
$needsConnection.attr("disabled", "disabled");
|
||||||
$needsConnection.attr("title", "This action can't be performed without active connection to Trilium.");
|
$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");
|
const $checkConnectionButton = $("#check-connection-button");
|
||||||
|
@ -23,6 +23,21 @@ class TriliumServerFacade {
|
|||||||
}
|
}
|
||||||
catch (e) {} // nothing might be listening
|
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) {
|
setTriliumSearch(ts) {
|
||||||
this.triliumSearch = ts;
|
this.triliumSearch = ts;
|
||||||
@ -116,6 +131,18 @@ class TriliumServerFacade {
|
|||||||
this.setTriliumSearch({ status: 'not-found' });
|
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() {
|
async waitForTriliumSearch() {
|
||||||
return new Promise((res, rej) => {
|
return new Promise((res, rej) => {
|
||||||
const checkStatus = () => {
|
const checkStatus = () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user