chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { const parentForm = getParentFormNode(document.activeElement); if (parentForm == null) { console.log("Form not found"); return; } switch (request.action) { case "copy": const result = buildFormValueSet(parentForm, "input", "select", "textarea"); console.log(result); sendResponse(result); break; case "paste": delete request.pasteForm; // console.log(request); for (let key in request) { if (String.isNullOrWhitespace(key)) { continue; } const dataType = checkDataType(request[key]); if (dataType == "object") { continue; } const foundElements = parentForm.querySelectorAll("[name='" + key + "']"); if (foundElements.length <= 0) { continue; } if (dataType == "array") { setFormElementValues(foundElements, request[key]); } else { for (let x=0; x 0) { return foundForms[0]; } } while (true) { if (String.isNullOrUndefined(result)) { result = null; break; } if (result.nodeName.toLocaleLowerCase() == "form") { break; } result = result.parentNode; } return result; } /** * Push form element value to array. */ function buildFormValueSet(form, ...tagNames){ let result = { }; for (let x=0; x