mirror of
https://github.com/alexadam/save-as-ebook.git
synced 2025-09-11 18:04:41 +00:00
msic - problems
This commit is contained in:
parent
8147350ce8
commit
aee4df3cc6
4 changed files with 36 additions and 24 deletions
|
@ -26,11 +26,11 @@ function saveEbookPages(pages) {
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById('savePage').onclick = function() {
|
document.getElementById('savePage').onclick = function() {
|
||||||
|
localStorage.removeItem('ebook');
|
||||||
chrome.tabs.query({
|
chrome.tabs.query({
|
||||||
currentWindow: true,
|
currentWindow: true,
|
||||||
active: true
|
active: true
|
||||||
}, function(tab) {
|
}, function(tab) {
|
||||||
console.log('aiai');
|
|
||||||
chrome.tabs.sendMessage(
|
chrome.tabs.sendMessage(
|
||||||
tab[0].id,
|
tab[0].id,
|
||||||
{
|
{
|
||||||
|
@ -47,6 +47,7 @@ document.getElementById('savePage').onclick = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
document.getElementById('saveSelection').onclick = function() {
|
document.getElementById('saveSelection').onclick = function() {
|
||||||
|
localStorage.removeItem('ebook');
|
||||||
chrome.tabs.query({
|
chrome.tabs.query({
|
||||||
currentWindow: true,
|
currentWindow: true,
|
||||||
active: true
|
active: true
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
var cssFileName = 'ebook.css';
|
var cssFileName = 'ebook.css';
|
||||||
var pageName = 'ebook.xhtml';
|
var pageName = 'ebook.xhtml';
|
||||||
var ebookName = "ebook-" + document.title + ".epub";
|
var ebookName = "ebook-" + document.title + ".epub";
|
||||||
|
@ -19,6 +18,15 @@ function getEbookPages() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getImgDownloadUrl(baseUrl, imgSrc) {
|
||||||
|
if (imgSrc.indexOf('http') !== 0) {
|
||||||
|
console.log(baseUrl + '/' + imgSrc);
|
||||||
|
return baseUrl + '/' + imgSrc;
|
||||||
|
}
|
||||||
|
console.log(imgSrc);
|
||||||
|
return imgSrc;
|
||||||
|
}
|
||||||
|
|
||||||
function getImagesIndex(allImgSrc) {
|
function getImagesIndex(allImgSrc) {
|
||||||
return Object.keys(allImgSrc).reduce(function(prev, elem, index) {
|
return Object.keys(allImgSrc).reduce(function(prev, elem, index) {
|
||||||
return prev + '\n' + '<item href="images/' + allImgSrc[elem] + '" id="img' + index + '" media-type="image/' + getFileExtension(elem) + '"/>';
|
return prev + '\n' + '<item href="images/' + allImgSrc[elem] + '" id="img' + index + '" media-type="image/' + getFileExtension(elem) + '"/>';
|
||||||
|
@ -111,7 +119,7 @@ function buildEbook() {
|
||||||
'<h1 class="frontmatter">Table of Contents</h1>' +
|
'<h1 class="frontmatter">Table of Contents</h1>' +
|
||||||
'<ol class="contents">' +
|
'<ol class="contents">' +
|
||||||
// '<li><a href="pages/' + pageName + '">' + ebookName + '</a></li>' + // TODO remove
|
// '<li><a href="pages/' + pageName + '">' + ebookName + '</a></li>' + // TODO remove
|
||||||
allPages.reduce(function (prev, page) {
|
allPages.reduce(function(prev, page) {
|
||||||
return prev + '\n' + '<li><a href="pages/' + page.url + '">' + page.title + '</a></li>';
|
return prev + '\n' + '<li><a href="pages/' + page.url + '">' + page.title + '</a></li>';
|
||||||
}, '') +
|
}, '') +
|
||||||
'</ol>' +
|
'</ol>' +
|
||||||
|
@ -132,12 +140,12 @@ function buildEbook() {
|
||||||
'</docTitle>' +
|
'</docTitle>' +
|
||||||
'<navMap>' +
|
'<navMap>' +
|
||||||
// '<content src="pages/' + pageName + '" />' + // TODO remove
|
// '<content src="pages/' + pageName + '" />' + // TODO remove
|
||||||
allPages.reduce(function (prev, page, index) {
|
allPages.reduce(function(prev, page, index) {
|
||||||
return prev + '\n' +
|
return prev + '\n' +
|
||||||
'<navPoint id="ebook' + index + '" playOrder="' + (index+1) + '">' +
|
'<navPoint id="ebook' + index + '" playOrder="' + (index + 1) + '">' +
|
||||||
'<navLabel><text>' + page.title + '</text></navLabel>' +
|
'<navLabel><text>' + page.title + '</text></navLabel>' +
|
||||||
'<content src="pages/' + page.url + '" />' +
|
'<content src="pages/' + page.url + '" />' +
|
||||||
'</navPoint>';
|
'</navPoint>';
|
||||||
}, '') +
|
}, '') +
|
||||||
'</navMap>' +
|
'</navMap>' +
|
||||||
'</ncx>'
|
'</ncx>'
|
||||||
|
@ -146,7 +154,7 @@ function buildEbook() {
|
||||||
oebps.file(cssFileName, '');
|
oebps.file(cssFileName, '');
|
||||||
|
|
||||||
var pagesFolder = oebps.folder('pages');
|
var pagesFolder = oebps.folder('pages');
|
||||||
allPages.forEach(function (page) {
|
allPages.forEach(function(page) {
|
||||||
pagesFolder.file(page.url,
|
pagesFolder.file(page.url,
|
||||||
'<?xml version="1.0" encoding="utf-8"?>' +
|
'<?xml version="1.0" encoding="utf-8"?>' +
|
||||||
'<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">' +
|
'<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">' +
|
||||||
|
@ -173,17 +181,17 @@ function buildEbook() {
|
||||||
'<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml" />' +
|
'<item id="ncx" href="toc.ncx" media-type="application/x-dtbncx+xml" />' +
|
||||||
'<item id="template_css" href="' + cssFileName + '" media-type="text/css" />' +
|
'<item id="template_css" href="' + cssFileName + '" media-type="text/css" />' +
|
||||||
// '<item id="ebook" href="pages/' + pageName + '" media-type="application/xhtml+xml" />' + //properties="remote-resources" // TODO remove
|
// '<item id="ebook" href="pages/' + pageName + '" media-type="application/xhtml+xml" />' + //properties="remote-resources" // TODO remove
|
||||||
allPages.reduce(function (prev, page, index) {
|
allPages.reduce(function(prev, page, index) {
|
||||||
return prev + '\n' + '<item id="ebook' + index + '" href="pages/' + page.url + '" media-type="application/xhtml+xml" />';
|
return prev + '\n' + '<item id="ebook' + index + '" href="pages/' + page.url + '" media-type="application/xhtml+xml" />';
|
||||||
}, '') +
|
}, '') +
|
||||||
allPages.reduce(function (prev, page, index) {
|
allPages.reduce(function(prev, page, index) {
|
||||||
return prev + '\n' + getImagesIndex(page.imgs);
|
return prev + '\n' + getImagesIndex(page.imgs);
|
||||||
}, '') +
|
}, '') +
|
||||||
// getExternalLinksIndex() +
|
// getExternalLinksIndex() +
|
||||||
'</manifest>' +
|
'</manifest>' +
|
||||||
'<spine toc="ncx">' +
|
'<spine toc="ncx">' +
|
||||||
// '<itemref idref="ebook" />' + // TODO remove
|
// '<itemref idref="ebook" />' + // TODO remove
|
||||||
allPages.reduce(function (prev, page, index) {
|
allPages.reduce(function(prev, page, index) {
|
||||||
return prev + '\n' + '<itemref idref="ebook' + index + '" />';
|
return prev + '\n' + '<itemref idref="ebook' + index + '" />';
|
||||||
}, '') +
|
}, '') +
|
||||||
'</spine>' +
|
'</spine>' +
|
||||||
|
@ -197,9 +205,10 @@ function buildEbook() {
|
||||||
///////////////
|
///////////////
|
||||||
var imgs = oebps.folder("images");
|
var imgs = oebps.folder("images");
|
||||||
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) {
|
||||||
var tmpDeffered = deferredAddZip(imgSrc, page.imgs[imgSrc], imgs);
|
console.log('AICI', imgSrc, getImgDownloadUrl(page.baseUrl, imgSrc));
|
||||||
|
var tmpDeffered = deferredAddZip(getImgDownloadUrl(page.baseUrl, imgSrc), page.imgs[imgSrc], imgs);
|
||||||
imgsPromises.push(tmpDeffered);
|
imgsPromises.push(tmpDeffered);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,6 +2,15 @@ var allImgSrc = {};
|
||||||
|
|
||||||
//////
|
//////
|
||||||
|
|
||||||
|
function getCurrentUrl() {
|
||||||
|
var url = window.location.href;
|
||||||
|
if (url.indexOf('?') > 0) {
|
||||||
|
url = window.location.href.split('?')[0];
|
||||||
|
}
|
||||||
|
url = url.substring(0, url.lastIndexOf('/')+1);
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
function getFileExtension(fileName) {
|
function getFileExtension(fileName) {
|
||||||
var tmpFileName = fileName.split('.').pop();
|
var tmpFileName = fileName.split('.').pop();
|
||||||
if (tmpFileName.indexOf('?') > 0) {
|
if (tmpFileName.indexOf('?') > 0) {
|
||||||
|
@ -76,7 +85,7 @@ function force(contentString) {
|
||||||
|
|
||||||
// https://github.com/blowsie/Pure-JavaScript-HTML5-Parser
|
// https://github.com/blowsie/Pure-JavaScript-HTML5-Parser
|
||||||
function sanitize(rawContentString) {
|
function sanitize(rawContentString) {
|
||||||
|
allImgSrc = {};
|
||||||
var srcTxt = '';
|
var srcTxt = '';
|
||||||
var dirty = null;
|
var dirty = null;
|
||||||
try {
|
try {
|
||||||
|
@ -229,6 +238,7 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
|
||||||
result = {
|
result = {
|
||||||
url: getPageUrl(document.title),
|
url: getPageUrl(document.title),
|
||||||
title: getPageTitle(document.title), //gatPageTitle(document.title),
|
title: getPageTitle(document.title), //gatPageTitle(document.title),
|
||||||
|
baseUrl: getCurrentUrl(),
|
||||||
imgs: allImgSrc,
|
imgs: allImgSrc,
|
||||||
content: getContent(pageSrc)
|
content: getContent(pageSrc)
|
||||||
};
|
};
|
||||||
|
@ -237,6 +247,7 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
|
||||||
result = {
|
result = {
|
||||||
url: getPageUrl(document.title),
|
url: getPageUrl(document.title),
|
||||||
title: getPageTitle(document.title),
|
title: getPageTitle(document.title),
|
||||||
|
baseUrl: getCurrentUrl(),
|
||||||
imgs: allImgSrc,
|
imgs: allImgSrc,
|
||||||
content: getContent(pageSrc)
|
content: getContent(pageSrc)
|
||||||
};
|
};
|
||||||
|
|
9
gigi.js
9
gigi.js
|
@ -1,9 +0,0 @@
|
||||||
|
|
||||||
|
|
||||||
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
|
|
||||||
if (request.type === 'get-title') {
|
|
||||||
console.log("AAAAAAAA 2", document.title);
|
|
||||||
sendResponse({title: document.title});
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
});
|
|
Loading…
Add table
Add a link
Reference in a new issue