diff --git a/popup/options/options-list.js b/popup/options/options-list.js index cb8d8f4..69cf7d8 100644 --- a/popup/options/options-list.js +++ b/popup/options/options-list.js @@ -152,6 +152,10 @@ function setListButtonsState(selectId, inputId, btnAddId, btnModId, btnDelId) { const lstSelect = document.querySelector(selectId); const inputValue = document.querySelector(inputId).value; + if (lstSelect.selectedIndex < 0 && inputValue && _listItemExist(lstSelect, inputValue)) { + _selectItemInList(lstSelect, inputValue); + } + if (lstSelect.selectedIndex < 0 || !inputValue) { if (inputValue) { btnAdd.removeAttribute("disabled"); @@ -183,3 +187,12 @@ function _listItemExist(selectElm, optionValue) { } return exist; } + +function _selectItemInList(selectElm, optionValue) { + const options = selectElm.options; + for(let i = 0; i < options.length; i++) { + if (options[i].textContent === optionValue) { + selectElm.selectedIndex = i; + } + } +} diff --git a/popup/options/options.js b/popup/options/options.js index 0048fd9..5e58932 100644 --- a/popup/options/options.js +++ b/popup/options/options.js @@ -90,10 +90,12 @@ document.addEventListener("DOMContentLoaded", function() { }); document.querySelector('#domainlist').addEventListener("change", domainlistChanged); document.querySelector('#domainListItem').addEventListener("keyup", domainlistInputChanged); + document.querySelector('#domainListItem').addEventListener("paste", domainlistInputPasted); document.querySelectorAll('.domainbutton').forEach(btn => {btn.addEventListener("click", listButtonClicked)}); document.querySelector('#fieldlist').addEventListener("change", fieldlistChanged); document.querySelector('#fieldListItem').addEventListener("keyup", fieldlistInputChanged); + document.querySelector('#fieldListItem').addEventListener("paste", fieldlistInputPasted); document.querySelector("#buttonClose").addEventListener("click", closeThisPopup); document.addEventListener("keyup", onKeyClicked); @@ -357,6 +359,9 @@ function domainlistChanged() { function domainlistInputChanged() { setListButtonsState("#domainlist", "#domainListItem", "#listAdd", "#listModify", "#listDelete"); } +function domainlistInputPasted(event) { + window.setTimeout(() => {domainlistInputChanged(); }, 10); +} function fieldlistChanged() { copySelectedItemToInput("#fieldlist", "#fieldListItem"); @@ -366,6 +371,9 @@ function fieldlistChanged() { function fieldlistInputChanged() { setListButtonsState("#fieldlist", "#fieldListItem", "#fieldAdd", "#fieldModify", "#fieldDelete"); } +function fieldlistInputPasted(event) { + window.setTimeout(() => {fieldlistInputChanged(); }, 10); +} function shortcutKeyEnableChanged(event) { const commandName = event.target.getAttribute('data-cmd');