});
}
-//document.onload(function () {
-//var a = document.getElementById("myid");
-//a.innerHTML = "ciaociao";
-//});
-
-/*
-var storageLocal = chrome.storage.local;
-storageLocal.getBytesInUse(null, function(bytesInUse) {
- var elem = document.createElement("div");
- elem.innerHTML = "<b>BYTES IN USE: " + bytesInUse + "</b><br />";
- document.body.appendChild(elem);
-});*/
+/**
+ * Callback from other pages (like the background).
+ */
+chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
+ console.log(`Got message from ${sender.id}: action=${request.action}`, request);
+
+ let asyncResponse = false;
+ switch (request?.action) {
+ case 'insertBackupItem':
+ insertBackupItem(...request.args);
+ break;
+
+ case 'removeBackupItemDiv':
+ removeBackupItemDiv(...request.args);
+ break;
+ }
+ return asyncResponse;
+});
// perform automatic backup
backupNow(true, formattedDate, function({success, backupName, backupObj}) {
// automatic backup completed
- var popupViews = chrome.extension.getViews({type: "popup"});
- if (popupViews.length > 0) {
- for (var i = 0; i < popupViews.length; i++) {
- var popupView = popupViews[i];
- if (!popupView.insertBackupItem) {
- continue;
- }
-
- popupView.insertBackupItem(backupName, backupObj, true /*insertAtBeginning*/, true /*doAnimation*/);
- popupView.updateStorageInfo();
- }
- }
+ chrome.runtime.sendMessage({
+ action: 'insertBackupItem',
+ args: [backupName, backupObj, true /*insertAtBeginning*/, true /*doAnimation*/],
+ });
});
}
//
if (i > 0) {
var deletedBackupName = backupsList[i-1];
- var popupViews = chrome.extension.getViews({type: "popup"});
- if (popupViews.length > 0) {
- for (var j = 0; j < popupViews.length; j++) {
- var popupView = popupViews[j];
- if (!popupView.removeBackupItemDiv) {
- continue;
- }
-
- popupView.removeBackupItemDiv(deletedBackupName);
- popupView.updateStorageInfo();
- }
- }
+ chrome.runtime.sendMessage({
+ action: 'removeBackupItemDiv',
+ args: [deletedBackupName],
+ });
}
//
args: ['full_backup'],
});
}
+
+/**
+ * Callback from other pages (like the background).
+ */
+chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
+ console.log(`Got message from ${sender.id}: action=${request.action}`, request);
+
+ let asyncResponse = false;
+ switch (request?.action) {
+ case 'insertBackupItem':
+ insertBackupItem(...request.args);
+ updateStorageInfo();
+ break;
+
+ case 'removeBackupItemDiv':
+ removeBackupItemDiv(...request.args);
+ updateStorageInfo();
+ break;
+ }
+ return asyncResponse;
+});