for (var i=0; i 0) { allStyles = allStyles.concat(allStylesTmp); } while (existingStyles.hasChildNodes() && existingStyles.childElementCount > 1) { existingStyles.removeChild(existingStyles.lastChild); } for (var i = 0; i < allStyles.length; i++) { var listItem = document.createElement('option'); listItem.id = 'option_' + i; listItem.className = 'cssEditor-chapter-item'; listItem.value = 'option_' + i; listItem.innerText = allStyles[i].title; if (currentStyle && (allStyles[i].title === currentStyle.title)) { listItem.selected = 'selected'; } existingStyles.appendChild(listItem); } } function editCurrentStyle() { if (!currentStyle) { return; } showStyleEditor(); showRemoveStyle(); showSaveStyle(); document.getElementById('cssEditor-styleName').value = currentStyle.title; document.getElementById('cssEditor-matchUrl').value = currentStyle.url; document.getElementById('cssEditor-styleContent').value = currentStyle.style; } function resetFields() { document.getElementById('cssEditor-styleName').value = ''; document.getElementById('cssEditor-matchUrl').value = ''; document.getElementById('cssEditor-styleContent').value = ''; } function hideStyleEditor() { document.getElementById('cssEditor-styleEditor').style.display = 'none'; } function showStyleEditor() { document.getElementById('cssEditor-styleEditor').style.display = 'flex'; } function showRemoveStyle() { document.getElementById('cssEditor-removeStyle').style.display = 'inline-block'; } function hideRemoveStyle() { document.getElementById('cssEditor-removeStyle').style.display = 'none'; } function showSaveStyle() { document.getElementById('cssEditor-saveStyle').style.display = 'inline-block'; } function hideSaveStyle() { document.getElementById('cssEditor-saveStyle').style.display = 'none'; } function saveStyle() { var isRegexValid = checkRegex(); if (!isRegexValid) { alert(chrome.i18n.getMessage('invalidRegex')); return; } var tmpValue = { title: document.getElementById('cssEditor-styleName').value, url: document.getElementById('cssEditor-matchUrl').value, style: document.getElementById('cssEditor-styleContent').value } if (currentStyle === null) { allStyles.push(tmpValue); currentStyle = tmpValue; currentStyleIndex = allStyles.length - 1; } else { currentStyle = tmpValue; allStyles[currentStyleIndex] = currentStyle; } setStyles(allStyles); createStyleList(); showRemoveStyle(); alert(chrome.i18n.getMessage('styleSaved')); } function checkRegex() { var regexContent = document.getElementById('cssEditor-matchUrl').value; var isValid = true; try { new RegExp(regexContent); } catch(e) { isValid = false; } return isValid; } function removeStyle() { if (confirm(chrome.i18n.getMessage('confirmDeleteStyle')) == true) { allStyles.splice(currentStyleIndex, 1); setStyles(allStyles); hideSaveStyle(); hideRemoveStyle(); hideStyleEditor(); createStyleList(); } } ///////////////////// var modal = document.createElement('div'); modal.id = 'cssEditor-Modal'; modalContent.appendChild(modalHeader); modalContent.appendChild(modalList); modalContent.appendChild(modalFooter); modal.appendChild(modalContent); body.appendChild(modal); modal.style.display = "none"; modal.style.position = 'fixed'; modal.style.zIndex = '1'; modal.style.left = '0'; modal.style.top = '0'; modal.style.width = '100%'; modal.style.height = '100%'; modal.style.overflow = 'auto'; modal.style.backgroundColor = 'rgba(210, 210, 210, 1)'; modalContent.style.zIndex = '2'; modalContent.style.backgroundColor = '#fff'; modalContent.style.margin = '5% auto'; modalContent.style.padding = '0'; modalContent.style.width = '70%'; window.onclick = function(event) { if (event.target == modal) { closeModal(); } }; modal.style.display = "block"; document.onkeydown = function(evt) { evt = evt || window.event; if (evt.keyCode == 27) { closeModal(); } }; function closeModal() { for (var i=0; i