Skip to content

Commit

Permalink
Updates v3.0.1
Browse files Browse the repository at this point in the history
- Resolves #25
- Resolves #26
  • Loading branch information
kvgc committed Jan 7, 2024
1 parent 1846de7 commit c3b3d47
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 6 deletions.
57 changes: 52 additions & 5 deletions webresearcher/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,25 @@ document.getElementById('exportNotesJoplin').addEventListener('click', ()=>{
}

console.log("User asked to export notes to Joplin.");
console.log( exportHTML.join(''));
// console.log( exportHTML.join(''));

fetch("http://localhost:41184/notes?token=" + joplinToken,
async function fetchJson(url) {
var results = await fetch(url);
var resultsJSON = await results.json();
if(resultsJSON.items.length == 0){
// pack results into a dictionary
let foo_final ={};
foo_final['HTML'] = WBJS_HTML;
foo_final['JSON'] = WBJS_JSON;
foo_final['CSS'] = WBJS_CSS;
let metaDataBlock = `<div id="metadata_wbjs" style="display:none;">` + JSON.stringify(foo_final) + `</div>`;

// create note in Joplin
fetch("http://localhost:41184/notes?token=" + joplinToken,
{
body: JSON.stringify({
"title": document.title ,
"body_html": exportHTML.join(''),
"body": exportHTML.join('') + metaDataBlock,
"tags" : "WBJS",
"source_url": url_window,
}),
Expand All @@ -27,7 +39,42 @@ document.getElementById('exportNotesJoplin').addEventListener('click', ()=>{
"Content-Type": "application/json",
},
}
);
$.notify('Adding notes to Joplin', "success");
);
$.notify('Adding notes to Joplin', "success");
}

if(resultsJSON.items.length == 1){
// pack results into a dictionary
let foo_final ={};
foo_final['HTML'] = WBJS_HTML;
foo_final['JSON'] = WBJS_JSON;
foo_final['CSS'] = WBJS_CSS;
let metaDataBlock = `<div id="metadata_wbjs" style="display:none;">` + JSON.stringify(foo_final) + `</div>`;

$.notify('Overwriting existing note', "info");
fetch("http://localhost:41184/notes/"+resultsJSON.items[0].id+"?token=" + joplinToken,
{
body: JSON.stringify({
"body": exportHTML.join('') + metaDataBlock,
}),
method: "PUT",
headers: {
"Content-Type": "application/json",
},
}
);
$.notify('Adding notes to Joplin', "success");

}
if(resultsJSON.items.length>1){
$.notify('Error: Multiple notes with same title found. Cannot save to Joplin. Delete and retry.', "error");
}

}
// Check if a note already exists
// If yes, then use the exisiting note ID
// If no, then create a new note

fetchJson("http://localhost:41184/search?token=" + joplinToken + "&query=" + pageTitle);

});
3 changes: 2 additions & 1 deletion webresearcher/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ var htmlAppend = $("html").append(`
<button class="badge btn btn-primary " style="width:100%" id='exportNotesJoplin'>Joplin</button>
</div>
`);
$("#userButtonPanelWBJS").draggable();
$("#userButtonPanelWBJS").draggable();

8 changes: 8 additions & 0 deletions webresearcher/loadLocalStorage.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Check if there are any notes already in localstorage and if so load them up
$.notify("WBJS is initializing.", "info",{autoHideDelay: 30000});

if(localStorage.getItem(webPageUrl)!=null){
var foo_loaded = JSON.parse(localStorage.getItem(webPageUrl));
var foo_loaded_keys = Object.keys(foo_loaded['HTML']);


for(k=0;k<foo_loaded_keys.length;k++){
console.info("WBJS: Adding locally stored notes.");
Expand Down Expand Up @@ -104,7 +106,13 @@ function getRandomInt(max) {
return Math.floor(Math.random() * max);
}


let showSaveMessage = 0;
async function saved(){
if(showSaveMessage==0){
showSaveMessage=1;
$.notify("WBJS is running", "success");
}

console.info("WBJS: saved");
// save all the notes created so far
Expand Down

0 comments on commit c3b3d47

Please sign in to comment.