check for regex errors & misc ui changes

This commit is contained in:
alexadam 2017-07-13 22:38:42 +03:00
parent a867a88550
commit e4f6940ecc
4 changed files with 38 additions and 33 deletions

View file

@ -33,10 +33,13 @@
margin-top: 10px; margin-top: 10px;
font-size: 15px; font-size: 15px;
font-family: "sans-serif"; font-family: "sans-serif";
display: flex;
justify-content: space-between;
width: 90%;
} }
.cssEditor-field-holder { .cssEditor-field-holder {
padding: 3px; padding: 3px;
width: 100%; width: 90%;
} }
.cssEditor-field-label { .cssEditor-field-label {
padding: 0 3px; padding: 0 3px;
@ -61,16 +64,16 @@
} }
#cssEditor-styleName { #cssEditor-styleName {
width: 90%; width: 100%;
min-width: 90%; min-width: 100%;
padding: 5px; padding: 5px;
border: solid rgba(0, 0, 0, 0.25) 1px; border: solid rgba(0, 0, 0, 0.25) 1px;
font-size: 15px; font-size: 15px;
font-family: "sans-serif"; font-family: "sans-serif";
} }
#cssEditor-matchUrl { #cssEditor-matchUrl {
width: 90%; width: 100%;
min-width: 90%; min-width: 100%;
padding: 5px; padding: 5px;
border: solid rgba(0, 0, 0, 0.25) 1px; border: solid rgba(0, 0, 0, 0.25) 1px;
font-size: 15px; font-size: 15px;

View file

@ -121,7 +121,11 @@ function showEditor() {
var urlLabel = document.createElement('label'); var urlLabel = document.createElement('label');
urlLabel.className = 'cssEditor-field-label'; urlLabel.className = 'cssEditor-field-label';
urlLabel.innerText = 'URL Regex'; // TODO addd link to regex tutorial 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(urlLabel);
urlLabelHolder.appendChild(regexHelp);
editorHolderLeft.appendChild(urlLabelHolder); editorHolderLeft.appendChild(urlLabelHolder);
var urlInputHolder = document.createElement('div'); var urlInputHolder = document.createElement('div');
@ -242,6 +246,11 @@ function showEditor() {
} }
function saveStyle() { function saveStyle() {
var isRegexValid = checkRegex();
if (!isRegexValid) {
alert("Invalid regular expression");
return;
}
var tmpValue = { var tmpValue = {
title: document.getElementById('cssEditor-styleName').value, title: document.getElementById('cssEditor-styleName').value,
url: document.getElementById('cssEditor-matchUrl').value, url: document.getElementById('cssEditor-matchUrl').value,
@ -261,6 +270,17 @@ function showEditor() {
alert('Style saved!'); 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() { function removeStyle() {
if (confirm('Are you sure you want to delete this style?') == true) { if (confirm('Are you sure you want to delete this style?') == true) {
allStyles.splice(currentStyleIndex, 1); allStyles.splice(currentStyleIndex, 1);
@ -325,32 +345,6 @@ function showEditor() {
modal.parentNode.removeChild(modal); 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() { function saveChanges() {
var newChapters = []; var newChapters = [];
var newEbookTitle = ebookTilte.value; var newEbookTitle = ebookTilte.value;

View file

@ -37,6 +37,9 @@
cursor: pointer; cursor: pointer;
} }
label {
font-size: 13px;
}
#busy { #busy {
background-color: rgba(0, 0, 0, 0.75); background-color: rgba(0, 0, 0, 0.75);
width: 100%; width: 100%;

View file

@ -32,9 +32,14 @@ function createStyleList(styles) {
currentUrl = currentUrl.replace(/(http[s]?:\/\/|www\.)/i, '').toLowerCase(); currentUrl = currentUrl.replace(/(http[s]?:\/\/|www\.)/i, '').toLowerCase();
var styleUrl = styles[i].url; var styleUrl = styles[i].url;
var styleUrlRegex = new RegExp('.*' + styleUrl + '.*', 'i'); var styleUrlRegex = null;
if (styleUrlRegex.test(currentUrl)) { try {
styleUrlRegex = new RegExp('.*' + styleUrl + '.*', 'i');
} catch (e) {
}
if (styleUrlRegex && styleUrlRegex.test(currentUrl)) {
allMatchingStyles.push({ allMatchingStyles.push({
index: i, index: i,
length: styleUrl.length length: styleUrl.length