function insertValueToNode(target, value) { let nodeList = [] switch (target) { case 'personal_id': nodeList = document.querySelectorAll('*[name*="personal_id"]') break case 'iban': nodeList = document.querySelectorAll('.user-bank-account__fake') for (const node of nodeList) { node.value = value.substr(2) } 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 } } );