2024-02-01 00:53:14 +00:00
|
|
|
chrome.runtime.onInstalled.addListener(function() {
|
2024-02-01 23:07:51 +00:00
|
|
|
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 });
|
2024-02-01 00:53:14 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
chrome.contextMenus.onClicked.addListener(function(msg, tab) {
|
|
|
|
switch (msg.menuItemId) {
|
2024-02-01 23:07:51 +00:00
|
|
|
case "copy-form":
|
2024-02-01 00:53:14 +00:00
|
|
|
copyFormContextMenu(tab);
|
|
|
|
break;
|
2024-02-01 23:07:51 +00:00
|
|
|
case "paste-form":
|
2024-02-01 20:31:47 +00:00
|
|
|
pasteFormContextMenu(tab, false);
|
|
|
|
break;
|
2024-02-01 23:07:51 +00:00
|
|
|
case "paste-form2":
|
2024-02-01 20:31:47 +00:00
|
|
|
pasteFormContextMenu(tab, true);
|
2024-02-01 00:53:14 +00:00
|
|
|
break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-02-01 23:07:51 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-02-01 00:53:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function copyFormContextMenu(tab) {
|
|
|
|
chrome.tabs.sendMessage(tab.id, { action: "copy" }, function(response) {
|
2024-02-01 22:03:49 +00:00
|
|
|
try {
|
2024-02-01 00:53:14 +00:00
|
|
|
chrome.storage.local.set({ 'clipboard': JSON.stringify(response) },function() {
|
2024-02-01 23:07:51 +00:00
|
|
|
chrome.contextMenus.update("paste-form", { enabled: true });
|
|
|
|
chrome.contextMenus.update("paste-form2", { enabled: true });
|
2024-02-01 00:53:14 +00:00
|
|
|
});
|
2024-02-01 22:03:49 +00:00
|
|
|
} catch (err) {
|
|
|
|
// Do nothing
|
2024-02-01 00:53:14 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-02-01 20:31:47 +00:00
|
|
|
function pasteFormContextMenu(tab, includeHiddenEl) {
|
2024-02-01 00:53:14 +00:00
|
|
|
chrome.storage.local.get('clipboard', function(response) {
|
|
|
|
try {
|
2024-02-01 22:03:49 +00:00
|
|
|
const payload = {
|
|
|
|
action: (includeHiddenEl === true ? "paste2" : "paste"),
|
|
|
|
formData: JSON.parse(response.clipboard)
|
|
|
|
};
|
2024-02-01 00:53:14 +00:00
|
|
|
|
2024-02-01 22:03:49 +00:00
|
|
|
chrome.tabs.sendMessage(tab.id, payload);
|
2024-02-01 00:53:14 +00:00
|
|
|
} catch (err) {
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|