mirror of
https://github.com/alexadam/save-as-ebook.git
synced 2025-09-09 17:04:39 +00:00
check for regex errors & misc ui changes
This commit is contained in:
parent
a867a88550
commit
e4f6940ecc
4 changed files with 38 additions and 33 deletions
|
@ -121,7 +121,11 @@ function showEditor() {
|
|||
var urlLabel = document.createElement('label');
|
||||
urlLabel.className = 'cssEditor-field-label';
|
||||
urlLabel.innerText = 'URL Regex'; // TODO addd link to regex tutorial
|
||||
var regexHelp = document.createElement('a');
|
||||
regexHelp.innerText = 'How to write a regular expression pattern';
|
||||
regexHelp.setAttribute('href', 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions');
|
||||
urlLabelHolder.appendChild(urlLabel);
|
||||
urlLabelHolder.appendChild(regexHelp);
|
||||
editorHolderLeft.appendChild(urlLabelHolder);
|
||||
|
||||
var urlInputHolder = document.createElement('div');
|
||||
|
@ -242,6 +246,11 @@ function showEditor() {
|
|||
}
|
||||
|
||||
function saveStyle() {
|
||||
var isRegexValid = checkRegex();
|
||||
if (!isRegexValid) {
|
||||
alert("Invalid regular expression");
|
||||
return;
|
||||
}
|
||||
var tmpValue = {
|
||||
title: document.getElementById('cssEditor-styleName').value,
|
||||
url: document.getElementById('cssEditor-matchUrl').value,
|
||||
|
@ -261,6 +270,17 @@ function showEditor() {
|
|||
alert('Style saved!');
|
||||
}
|
||||
|
||||
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('Are you sure you want to delete this style?') == true) {
|
||||
allStyles.splice(currentStyleIndex, 1);
|
||||
|
@ -325,32 +345,6 @@ function showEditor() {
|
|||
modal.parentNode.removeChild(modal);
|
||||
}
|
||||
|
||||
function removeListItem(atIndex) {
|
||||
return function() {
|
||||
allPagesRef[atIndex].removed = true;
|
||||
var tmpListElem = document.getElementById('li' + atIndex);
|
||||
tmpListElem.style.display = 'none';
|
||||
};
|
||||
}
|
||||
|
||||
function previewListItem(atIndex) {
|
||||
return function() {
|
||||
alert(allPagesRef[atIndex].content.trim().replace(/<[^>]+>/gi, '').replace(/\s+/g, ' ').substring(0, 1000) + ' ...');
|
||||
};
|
||||
}
|
||||
|
||||
function prepareEbook(newChapters) {
|
||||
try {
|
||||
if (newChapters.length === 0) {
|
||||
alert('Can\'t generate an empty eBook!');
|
||||
return;
|
||||
}
|
||||
buildEbookFromChapters();
|
||||
} catch (e) {
|
||||
console.log('Error:', e);
|
||||
}
|
||||
}
|
||||
|
||||
function saveChanges() {
|
||||
var newChapters = [];
|
||||
var newEbookTitle = ebookTilte.value;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue