🚧 Make it work with async work
This commit is contained in:
parent
21d1e6f0ef
commit
e7aee8fbaa
@ -7,25 +7,19 @@ ext.runtime.onMessage.addListener(
|
||||
var data = JSON.parse(request.data);
|
||||
var url;
|
||||
var token;
|
||||
storage.get('url', function(resp) {
|
||||
storage.get(['url', 'token'], function(resp) {
|
||||
url = resp.url;
|
||||
storage.get('token', function(resp) {
|
||||
token = resp.token;
|
||||
console.log("Extension Type: ", "/* @echo extension */");
|
||||
console.log("PERFORM AJAX", request.data);
|
||||
var destination = url+"?v=1&u="+encodeURIComponent(data.url)+"&t="+encodeURIComponent(data.title)+"&m="+encodeURIComponent(token);
|
||||
|
||||
console.log("Destination: ", destination);
|
||||
fetch(destination)
|
||||
.then(function(response) {
|
||||
console.log(response);
|
||||
});
|
||||
|
||||
sendResponse({ action: "saved" });
|
||||
token = resp.token;
|
||||
var destination = url+"?v=1&u="+encodeURIComponent(data.url)+"&t="+encodeURIComponent(data.title)+"&m="+encodeURIComponent(token);
|
||||
|
||||
console.log("Destination: ", destination);
|
||||
fetch(destination).then(function(response) {
|
||||
console.log(response);
|
||||
sendResponse({ action: "saved" });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
return true; // https://stackoverflow.com/a/20077854
|
||||
}
|
||||
}
|
||||
);
|
@ -21,11 +21,11 @@ var template = (data) => {
|
||||
<button data-bookmark='${json}' id="save-btn" class="btn btn-primary">Save</button>
|
||||
</div>
|
||||
`);
|
||||
}
|
||||
};
|
||||
var renderMessage = (message) => {
|
||||
var displayContainer = document.getElementById("display-container");
|
||||
displayContainer.innerHTML = `<p class='message'>${message}</p>`;
|
||||
}
|
||||
};
|
||||
|
||||
var renderBookmark = (data) => {
|
||||
var displayContainer = document.getElementById("display-container")
|
||||
@ -44,15 +44,15 @@ ext.tabs.query({active: true, currentWindow: true}, function(tabs) {
|
||||
|
||||
popup.addEventListener("click", function(e) {
|
||||
if(e.target && e.target.matches("#save-btn")) {
|
||||
e.preventDefault();
|
||||
var data = e.target.getAttribute("data-bookmark");
|
||||
ext.runtime.sendMessage({ action: "perform-save", data: data }, function(response) {
|
||||
if(response && response.action === "saved") {
|
||||
renderMessage("Your bookmark was saved successfully!");
|
||||
} else {
|
||||
renderMessage("Sorry, there was an error while saving your bookmark.");
|
||||
}
|
||||
})
|
||||
e.preventDefault();
|
||||
var data = e.target.getAttribute("data-bookmark");
|
||||
ext.runtime.sendMessage({action: "perform-save", data: data}, function (response) {
|
||||
if (response && response.action === "saved") {
|
||||
renderMessage("Your bookmark was saved successfully!");
|
||||
} else {
|
||||
renderMessage("Sorry, there was an error while saving your bookmark.");
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@ -60,4 +60,4 @@ var optionsLink = document.querySelector(".js-options");
|
||||
optionsLink.addEventListener("click", function(e) {
|
||||
e.preventDefault();
|
||||
ext.tabs.create({'url': ext.extension.getURL('options.html')});
|
||||
})
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user