This commit is contained in:
alexadam 2016-07-29 12:13:04 +03:00
parent aee4df3cc6
commit 14bdf5fec4
5 changed files with 39 additions and 53 deletions

View file

@ -33,6 +33,7 @@
<script src="filesaver.js" charset="utf-8"></script> <script src="filesaver.js" charset="utf-8"></script>
<script src="jszip.js" charset="utf-8"></script> <script src="jszip.js" charset="utf-8"></script>
<script src="jszip-utils.js" charset="utf-8"></script> <script src="jszip-utils.js" charset="utf-8"></script>
<script src="utils.js" charset="utf-8"></script>
<script src="saveEbook.js" charset="utf-8"></script> <script src="saveEbook.js" charset="utf-8"></script>
<script src="menu.js" charset="utf-8"></script> <script src="menu.js" charset="utf-8"></script>
</body> </body>

View file

@ -5,26 +5,6 @@ document.getElementById("editChapters").onclick = function() {
win.focus(); 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() { document.getElementById('savePage').onclick = function() {
localStorage.removeItem('ebook'); localStorage.removeItem('ebook');
chrome.tabs.query({ chrome.tabs.query({

View file

@ -2,28 +2,13 @@ var cssFileName = 'ebook.css';
var pageName = 'ebook.xhtml'; var pageName = 'ebook.xhtml';
var ebookName = "ebook-" + document.title + ".epub"; 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) { function getImgDownloadUrl(baseUrl, imgSrc) {
if (imgSrc.indexOf('//') === 0) {
return baseUrl.split('//')[0] + imgSrc;
}
if (imgSrc.indexOf('http') !== 0) { if (imgSrc.indexOf('http') !== 0) {
console.log(baseUrl + '/' + imgSrc);
return baseUrl + '/' + imgSrc; return baseUrl + '/' + imgSrc;
} }
console.log(imgSrc);
return imgSrc; return imgSrc;
} }
@ -207,7 +192,6 @@ function buildEbook() {
var imgsPromises = []; var imgsPromises = [];
allPages.forEach(function(page) { allPages.forEach(function(page) {
Object.keys(page.imgs).forEach(function(imgSrc, index) { 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); var tmpDeffered = deferredAddZip(getImgDownloadUrl(page.baseUrl, imgSrc), page.imgs[imgSrc], imgs);
imgsPromises.push(tmpDeffered); imgsPromises.push(tmpDeffered);
}); });

19
chapter-editor/utils.js Normal file
View file

@ -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));
}

View file

@ -230,29 +230,31 @@ function getSelectedNodes() {
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) { chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
console.log('Extract Html...'); console.log('Extract Html...');
allImgSrc = {};
var result = {}; var result = {};
var pageSrc = ''; var pageSrc = '';
var tmpConent = '';
if (request.type === 'extract-page') { if (request.type === 'extract-page') {
pageSrc = document.getElementsByTagName('body')[0]; pageSrc = document.getElementsByTagName('body')[0];
result = { tmpConent = getContent(pageSrc);
url: getPageUrl(document.title),
title: getPageTitle(document.title), //gatPageTitle(document.title),
baseUrl: getCurrentUrl(),
imgs: allImgSrc,
content: getContent(pageSrc)
};
} else if (request.type === 'extract-selection') { } else if (request.type === 'extract-selection') {
pageSrc = getSelectedNodes(); pageSrc = getSelectedNodes();
result = { tmpConent = getContent(pageSrc);
url: getPageUrl(document.title),
title: getPageTitle(document.title),
baseUrl: getCurrentUrl(),
imgs: allImgSrc,
content: 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); sendResponse(result);
console.log('Html Extracted'); console.log('Html Extracted');
}); });