You may have a content script detect the save action. Suppose this is a specific DOM element that you know for sure, it will be in a specific master or created by yourself.
content.js
//content script document.onreadystatechange = function () { if (document.readyState == "complete") { // Grab the UI frmo the mainpage you want to append the save functionality var someElementsYouWantToAppendASaveButtonTo = document.getElementsByTagName("..."); var len = someElementsYouWantToAppendASaveButtonTo.length; for (var i = 0; i < len; i++) { // Create a UI save button to provide a functionality var theSaveButton = document.createElement("button"); theSaveButton.value = "Save to Chrome Extension"; // Send data to extension when clicked theSaveButton.addEventListener("click", function() { var dataToSentToExtension = {...} // Retrieve from the clicked element, or whatever you want to save chrome.extension.sendMessage(dataToSentToExtension, function(response) { if(response.success) console.log("Saved successfully"); else console.log("There was an error while saving") }); }, false); someElementsYouWantToAppendASaveButtonTo[i].appendChild(theSaveButton) } } }
Then in the background you find the answer and customize the popup as you wish.
background.js
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) { if(request.dataToSave) { chrome.storage.local.set(dataToSave, function() {...}); // You can then set upn the proper popup for the next click or even switch to it switch(request.popupToDisplay) { case "awesomeDisplay": chrome.browserAction.setPopup({...}) break; } var responseFromExtension = {success: true} } else { var responseFromExtension = {error: true} } });
jjperezaguinaga
source share