chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { let formContainer = getContainer(document.activeElement); if (formContainer == null) { writeLog("Form container not found"); return; } switch (request.action) { case "copy": const result = getFormElementValueSet(formContainer, "input", "select", "textarea"); console.log(result); sendResponse(result); break; case "paste": case "paste2": const includeHidden = (request.action == "paste2"); delete request.action; for (let key in request) { if (String.isNullOrWhitespace(key)) { continue; } const dataType = Object.getDataType(request[key]); if (dataType == "object") { continue; } const foundEls = formContainer.querySelectorAll("[name='" + key + "']"); if (foundEls.length <= 0) { continue; } if (dataType == "array") { setFormElementValues(foundEls, request[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); } };