Added hotkey support on Ctrl+Shift+2 and Ctrl+Shift+3

This commit is contained in:
Ray 2024-02-01 23:07:51 +00:00
parent a39229690c
commit b55b10c7b3
3 changed files with 68 additions and 25 deletions

View File

@ -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

View File

@ -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<els.length; i++) {
let newValue = null;
if (String.isNullOrWhitespace(els[i].name)) {
continue;
}
switch (els[i].type)
{
case "checkbox":

View File

@ -2,7 +2,20 @@
"manifest_version": 3,
"name": "Form Copypasta",
"description": "Copy and paste form element values. Not for distribution. Internal use only. Based on Copy Form (0.0.1.2) by Sam Larison.",
"version": "0.1.0.035",
"version": "0.1.0.075",
"icons": {
"16": "icon16.png",
"32": "icon32.png",
"48": "icon48.png",
"64": "icon64.png",
"128": "icon128.png"
},
"permissions": [
"activeTab",
"contextMenus",
"storage",
"tabs"
],
"content_scripts": [
{
"js": [
@ -19,17 +32,22 @@
"service_worker": "background.js",
"type": "module"
},
"icons": {
"16": "icon16.png",
"32": "icon32.png",
"48": "icon48.png",
"64": "icon64.png",
"128": "icon128.png"
},
"permissions": [
"activeTab",
"contextMenus",
"storage",
"tabs"
]
"commands": {
"copy-form": {
"suggested_key": {
"default": "Ctrl+Shift+2",
"windows": "Ctrl+Shift+2",
"mac": "Command+Shift+2"
},
"description": "Copy form"
},
"paste-form": {
"suggested_key": {
"default": "Ctrl+Shift+3",
"windows": "Ctrl+Shift+3",
"mac": "Command+Shift+3"
},
"description": "Paste form"
}
}
}