webextensions/src/scripts/background.js

22 lines
694 B
JavaScript
Raw Normal View History

2018-04-08 22:33:36 +02:00
import ext from "./utils/ext";
import storage from "./utils/storage";
ext.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if(request.action === "perform-save") {
var data = request.data;
2018-04-08 22:33:36 +02:00
var url;
var token;
storage.get(['url', 'token'], function(resp) {
2018-04-08 22:33:36 +02:00
url = resp.url;
token = resp.token;
var destination = url+"?v=1&u="+encodeURIComponent(data.url)+"&t="+encodeURIComponent(data.title)+"&m="+encodeURIComponent(token);
fetch(destination).then(function(response) {
sendResponse({ action: "saved" });
2018-04-08 22:33:36 +02:00
});
});
return true; // https://stackoverflow.com/a/20077854
2018-04-08 22:33:36 +02:00
}
}
);