Added hotkey support on Ctrl+Shift+2 and Ctrl+Shift+3
This commit is contained in:
parent
a39229690c
commit
b55b10c7b3
@ -1,24 +1,42 @@
|
|||||||
chrome.runtime.onInstalled.addListener(function() {
|
chrome.runtime.onInstalled.addListener(function() {
|
||||||
chrome.contextMenus.create({ "id": "copy_form", "title": "Copy Form", "contexts": ["editable"] });
|
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-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": "paste-form2", "title": "Paste Form (with Hidden)", "contexts": ["editable"], enabled: false });
|
||||||
});
|
});
|
||||||
|
|
||||||
chrome.contextMenus.onClicked.addListener(function(msg, tab) {
|
chrome.contextMenus.onClicked.addListener(function(msg, tab) {
|
||||||
switch (msg.menuItemId) {
|
switch (msg.menuItemId) {
|
||||||
case "copy_form":
|
case "copy-form":
|
||||||
copyFormContextMenu(tab);
|
copyFormContextMenu(tab);
|
||||||
break;
|
break;
|
||||||
case "paste_form":
|
case "paste-form":
|
||||||
pasteFormContextMenu(tab, false);
|
pasteFormContextMenu(tab, false);
|
||||||
break;
|
break;
|
||||||
case "paste_form2":
|
case "paste-form2":
|
||||||
pasteFormContextMenu(tab, true);
|
pasteFormContextMenu(tab, true);
|
||||||
break;
|
break;
|
||||||
default: 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) {
|
chrome.tabs.sendMessage(tab.id, { action: "copy" }, function(response) {
|
||||||
try {
|
try {
|
||||||
chrome.storage.local.set({ 'clipboard': JSON.stringify(response) },function() {
|
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) {
|
} catch (err) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
|
14
content.js
14
content.js
@ -1,14 +1,14 @@
|
|||||||
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
|
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse) {
|
||||||
switch (request.action) {
|
switch (message.action) {
|
||||||
case "copy":
|
case "copy":
|
||||||
const result = copyFormElementValues(document.activeElement);
|
const result = copyFormElementValues(document.activeElement);
|
||||||
sendResponse(result);
|
sendResponse(result);
|
||||||
break;
|
break;
|
||||||
case "paste":
|
case "paste":
|
||||||
pasteFormElementValues(document.activeElement, request.formData, false);
|
pasteFormElementValues(document.activeElement, message.formData, false);
|
||||||
break;
|
break;
|
||||||
case "paste2":
|
case "paste2":
|
||||||
pasteFormElementValues(document.activeElement, request.formData, true);
|
pasteFormElementValues(document.activeElement, message.formData, true);
|
||||||
break;
|
break;
|
||||||
default: 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++) {
|
for (let i=0; i<els.length; i++) {
|
||||||
let newValue = null;
|
let newValue = null;
|
||||||
|
|
||||||
|
if (String.isNullOrWhitespace(els[i].name)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
switch (els[i].type)
|
switch (els[i].type)
|
||||||
{
|
{
|
||||||
case "checkbox":
|
case "checkbox":
|
||||||
|
@ -2,7 +2,20 @@
|
|||||||
"manifest_version": 3,
|
"manifest_version": 3,
|
||||||
"name": "Form Copypasta",
|
"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.",
|
"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": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
"js": [
|
"js": [
|
||||||
@ -19,17 +32,22 @@
|
|||||||
"service_worker": "background.js",
|
"service_worker": "background.js",
|
||||||
"type": "module"
|
"type": "module"
|
||||||
},
|
},
|
||||||
"icons": {
|
"commands": {
|
||||||
"16": "icon16.png",
|
"copy-form": {
|
||||||
"32": "icon32.png",
|
"suggested_key": {
|
||||||
"48": "icon48.png",
|
"default": "Ctrl+Shift+2",
|
||||||
"64": "icon64.png",
|
"windows": "Ctrl+Shift+2",
|
||||||
"128": "icon128.png"
|
"mac": "Command+Shift+2"
|
||||||
},
|
},
|
||||||
"permissions": [
|
"description": "Copy form"
|
||||||
"activeTab",
|
},
|
||||||
"contextMenus",
|
"paste-form": {
|
||||||
"storage",
|
"suggested_key": {
|
||||||
"tabs"
|
"default": "Ctrl+Shift+3",
|
||||||
]
|
"windows": "Ctrl+Shift+3",
|
||||||
|
"mac": "Command+Shift+3"
|
||||||
|
},
|
||||||
|
"description": "Paste form"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user