mirror of
https://github.com/alexadam/save-as-ebook.git
synced 2025-09-10 17:34:47 +00:00
miisc
This commit is contained in:
parent
aee4df3cc6
commit
14bdf5fec4
5 changed files with 39 additions and 53 deletions
|
@ -33,6 +33,7 @@
|
|||
<script src="filesaver.js" charset="utf-8"></script>
|
||||
<script src="jszip.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="menu.js" charset="utf-8"></script>
|
||||
</body>
|
||||
|
|
|
@ -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({
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
19
chapter-editor/utils.js
Normal file
19
chapter-editor/utils.js
Normal 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));
|
||||
}
|
|
@ -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');
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue