save and load state

This commit is contained in:
2020-01-12 16:19:38 +08:00
parent f1cf32b83a
commit c7f4fe7cc4
7 changed files with 85 additions and 17 deletions

View File

@ -50,10 +50,18 @@ function sendMessage(tab, req, log, cond, interval, limit = 0) {
});
}
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
if (!message.action || !message.action.startsWith(EXT_NAME)) {
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
if (!request.action || !request.action.startsWith(EXT_NAME)) {
return;
}
sendResponse("Calling from user pages is not allowed.");
return;
switch (request.action) {
case ACTION_UPLOAD_STATE:
sendResponse('recieved!');
__EXTRACTOR_STATE__ = request.state;
console.log(`State (${request.name}) recieved. Use following to load it: \nsome_var = new Extractor().load()`);
break;
default:
sendResponse("Request not supported.");
break;
}
});