diff --git a/chapter-editor/menu.html b/chapter-editor/menu.html index 9344764..b0b6773 100644 --- a/chapter-editor/menu.html +++ b/chapter-editor/menu.html @@ -33,6 +33,7 @@ + diff --git a/chapter-editor/menu.js b/chapter-editor/menu.js index b1d715f..0e8d4b3 100644 --- a/chapter-editor/menu.js +++ b/chapter-editor/menu.js @@ -5,26 +5,6 @@ document.getElementById("editChapters").onclick = function() { win.focus(); }; - -function getEbookPages() { // TODO add as utils - try { - var allPages = localStorage.getItem('ebook'); - if (!allPages) { - allPages = []; - } else { - allPages = JSON.parse(allPages); - } - return allPages; - } catch (e) { - console.log(e); - return []; - } -} - -function saveEbookPages(pages) { - localStorage.setItem('ebook', JSON.stringify(pages)); -} - document.getElementById('savePage').onclick = function() { localStorage.removeItem('ebook'); chrome.tabs.query({ diff --git a/chapter-editor/saveEbook.js b/chapter-editor/saveEbook.js index d7139b9..29e17ac 100644 --- a/chapter-editor/saveEbook.js +++ b/chapter-editor/saveEbook.js @@ -2,28 +2,13 @@ var cssFileName = 'ebook.css'; var pageName = 'ebook.xhtml'; var ebookName = "ebook-" + document.title + ".epub"; -function getEbookPages() { - try { - var allPages = localStorage.getItem('ebook'); - if (!allPages) { - allPages = []; - } else { - allPages = JSON.parse(allPages); - } - return allPages; - } catch (e) { - console.log(e); - return []; - } - -} - function getImgDownloadUrl(baseUrl, imgSrc) { + if (imgSrc.indexOf('//') === 0) { + return baseUrl.split('//')[0] + imgSrc; + } if (imgSrc.indexOf('http') !== 0) { - console.log(baseUrl + '/' + imgSrc); return baseUrl + '/' + imgSrc; } - console.log(imgSrc); return imgSrc; } @@ -207,7 +192,6 @@ function buildEbook() { var imgsPromises = []; allPages.forEach(function(page) { Object.keys(page.imgs).forEach(function(imgSrc, index) { - console.log('AICI', imgSrc, getImgDownloadUrl(page.baseUrl, imgSrc)); var tmpDeffered = deferredAddZip(getImgDownloadUrl(page.baseUrl, imgSrc), page.imgs[imgSrc], imgs); imgsPromises.push(tmpDeffered); }); diff --git a/chapter-editor/utils.js b/chapter-editor/utils.js new file mode 100644 index 0000000..29d06c6 --- /dev/null +++ b/chapter-editor/utils.js @@ -0,0 +1,19 @@ + +function getEbookPages() { + try { + var allPages = localStorage.getItem('ebook'); + if (!allPages) { + allPages = []; + } else { + allPages = JSON.parse(allPages); + } + return allPages; + } catch (e) { + console.log(e); + return []; + } +} + +function saveEbookPages(pages) { + localStorage.setItem('ebook', JSON.stringify(pages)); +} diff --git a/extractHtml.js b/extractHtml.js index 3efe559..25a97b1 100644 --- a/extractHtml.js +++ b/extractHtml.js @@ -230,29 +230,31 @@ function getSelectedNodes() { chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { console.log('Extract Html...'); + allImgSrc = {}; var result = {}; var pageSrc = ''; + var tmpConent = ''; if (request.type === 'extract-page') { pageSrc = document.getElementsByTagName('body')[0]; - result = { - url: getPageUrl(document.title), - title: getPageTitle(document.title), //gatPageTitle(document.title), - baseUrl: getCurrentUrl(), - imgs: allImgSrc, - content: getContent(pageSrc) - }; + tmpConent = getContent(pageSrc); } else if (request.type === 'extract-selection') { pageSrc = getSelectedNodes(); - result = { - url: getPageUrl(document.title), - title: getPageTitle(document.title), - baseUrl: getCurrentUrl(), - imgs: allImgSrc, - content: getContent(pageSrc) - }; + tmpConent = getContent(pageSrc); } + if (tmpConent.trim() === '') { + return; + } + + result = { + url: getPageUrl(document.title), + title: getPageTitle(document.title), //gatPageTitle(document.title), + baseUrl: getCurrentUrl(), + imgs: allImgSrc, + content: tmpConent + }; + sendResponse(result); console.log('Html Extracted'); });