function insertValueToNode(target, value) { let nodeList = [] switch (target) { case 'personal_id': nodeList = document.querySelectorAll('*[name*="personal_id"]') break case 'iban': nodeList = document.querySelectorAll('*[name*="bankaccount"]') break case 'phone': nodeList = document.querySelectorAll('*[name*="phone"]') break case 'first_name': nodeList = document.querySelectorAll('*[name*="first_name"]') break case 'last_name': nodeList = document.querySelectorAll('*[name*="last_name"]') break } for (const node of nodeList) { node.value = value } } chrome.runtime.onMessage.addListener( function(autocompleteDTO, sender, sendResponse) { switch (autocompleteDTO.action) { case 'insert': insertValueToNode(autocompleteDTO.target || null, autocompleteDTO.value || '') break case 'clean_notification': var elementList = document.querySelectorAll('.uk-notify-message'); elementList.forEach(function(elementItem) { elementItem.remove() }); break } } );