diff --git a/background.js b/background.js index 81f1627..0ff560f 100644 --- a/background.js +++ b/background.js @@ -1,24 +1,42 @@ chrome.runtime.onInstalled.addListener(function() { - chrome.contextMenus.create({ "id": "copy_form", "title": "Copy Form", "contexts": ["editable"] }); - chrome.contextMenus.create({ "id": "paste_form", "title": "Paste Form", "contexts": ["editable"], enabled: false }); - chrome.contextMenus.create({ "id": "paste_form2", "title": "Paste Form (with Hidden)", "contexts": ["editable"], enabled: false }); + chrome.contextMenus.create({ "id": "copy-form", "title": "Copy Form", "contexts": ["editable"] }); + chrome.contextMenus.create({ "id": "paste-form", "title": "Paste Form", "contexts": ["editable"], enabled: false }); + chrome.contextMenus.create({ "id": "paste-form2", "title": "Paste Form (with Hidden)", "contexts": ["editable"], enabled: false }); }); chrome.contextMenus.onClicked.addListener(function(msg, tab) { switch (msg.menuItemId) { - case "copy_form": + case "copy-form": copyFormContextMenu(tab); break; - case "paste_form": + case "paste-form": pasteFormContextMenu(tab, false); break; - case "paste_form2": + case "paste-form2": pasteFormContextMenu(tab, true); break; default: break; } }); +chrome.commands.onCommand.addListener(function (command) { + switch (command) { + case 'copy-form': + chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) { + copyFormContextMenu(tabs[0]); + }); + + break; + case 'paste-form': + chrome.tabs.query({ currentWindow: true, active: true }, function (tabs) { + pasteFormContextMenu(tabs[0], false); + }); + + break; + default: break; + } +}); + @@ -26,7 +44,8 @@ function copyFormContextMenu(tab) { chrome.tabs.sendMessage(tab.id, { action: "copy" }, function(response) { try { chrome.storage.local.set({ 'clipboard': JSON.stringify(response) },function() { - chrome.contextMenus.update("paste_form", { enabled: true }); + chrome.contextMenus.update("paste-form", { enabled: true }); + chrome.contextMenus.update("paste-form2", { enabled: true }); }); } catch (err) { // Do nothing diff --git a/content.js b/content.js index 1eddf6c..cafb489 100644 --- a/content.js +++ b/content.js @@ -1,14 +1,14 @@ -chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { - switch (request.action) { +chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) { + switch (message.action) { case "copy": const result = copyFormElementValues(document.activeElement); sendResponse(result); break; case "paste": - pasteFormElementValues(document.activeElement, request.formData, false); + pasteFormElementValues(document.activeElement, message.formData, false); break; case "paste2": - pasteFormElementValues(document.activeElement, request.formData, true); + pasteFormElementValues(document.activeElement, message.formData, true); break; default: break; } @@ -65,6 +65,8 @@ function pasteFormElementValues(el, formData, includeHidden) { } } } + + writeLog("Pasted"); } @@ -147,6 +149,10 @@ function getFormElementValueSet(form, ...tagNames){ for (let i=0; i