chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { switch (request.action) { case "copy": const result = copyFormElementValues(document.activeElement); sendResponse(result); break; case "paste": pasteFormElementValues(document.activeElement, request.formData, false); break; case "paste2": pasteFormElementValues(document.activeElement, request.formData, true); break; default: break; } }); function copyFormElementValues(el) { const container = getContainer(el); if (container == null) { writeLog("Form container not found"); return null; } const result = getFormElementValueSet(container, "input", "select", "textarea"); console.log(result); return result; } function pasteFormElementValues(el, formData, includeHidden) { if (String.isNullOrUndefined(formData)) { return; } let container = getContainer(el); if (container == null) { writeLog("Form container not found"); return; } for (let key in formData) { if (String.isNullOrWhitespace(key)) { continue; } const dataType = Object.getDataType(formData[key]); if (dataType == "object") { continue; } const foundEls = container.querySelectorAll("[name='" + key + "']"); if (foundEls.length <= 0) { continue; } if (dataType == "array") { setFormElementValues(foundEls, formData[key], includeHidden); } else { for (let x=0; x " + message); } Object.getDataType = function(value) { if (String.isNullOrUndefined(value)) { return "null"; } if (typeof(value) == "object") { if (Array.isArray(value)) { return "array"; } else { return "object"; } } return typeof(value); }; String.isNullOrUndefined = function(value) { if (typeof (value) == "undefined") { return true; } if (value == null) { return true; } return false; }; String.isNullOrWhitespace = function(value) { const a = this; if (String.isNullOrUndefined(value)) { return true; } if (typeof(value) == "string") { return (value.trim().length <= 0); } else { return (value.toString().trim().length <= 0); } };