mirror of
https://github.com/alexadam/save-as-ebook.git
synced 2025-09-11 09:54: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) + '"/>';
|
||||||
|
@ -199,7 +207,8 @@ 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) {
|
||||||
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