mirror of
https://github.com/alexadam/save-as-ebook.git
synced 2025-09-15 11:49:46 +00:00
misc bug fixes
This commit is contained in:
parent
bc8dfab9b3
commit
9237935f69
6 changed files with 105 additions and 34 deletions
|
@ -200,10 +200,27 @@ function dispatch(action, justAddToBuffer, appliedStyles) {
|
|||
}
|
||||
}
|
||||
|
||||
chrome.tabs.executeScript(tab[0].id, {file: '/jquery.js'});
|
||||
chrome.tabs.executeScript(tab[0].id, {file: '/utils.js'});
|
||||
chrome.tabs.executeScript(tab[0].id, {file: '/filesaver.js'});
|
||||
chrome.tabs.executeScript(tab[0].id, {file: '/jszip.js'});
|
||||
chrome.tabs.executeScript(tab[0].id, {file: '/jszip-utils.js'});
|
||||
chrome.tabs.executeScript(tab[0].id, {file: '/saveEbook.js'});
|
||||
|
||||
chrome.tabs.sendMessage(tab[0].id, {
|
||||
type: action,
|
||||
appliedStyles: appliedStyles
|
||||
}, (response) => {
|
||||
|
||||
if (!response) {
|
||||
isBusy = false;
|
||||
chrome.browserAction.setBadgeText({text: ""});
|
||||
chrome.tabs.sendMessage(tab[0].id, {'alert': 'Save as eBook does not work on this web site!'}, (r) => {
|
||||
console.log(r);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (response.length === 0) {
|
||||
if (justAddToBuffer) {
|
||||
// FIXME does not work on chrome ?
|
||||
|
@ -240,6 +257,9 @@ function dispatch(action, justAddToBuffer, appliedStyles) {
|
|||
})
|
||||
}
|
||||
});
|
||||
// FIXME set timeout
|
||||
// isBusy = false;
|
||||
// chrome.browserAction.setBadgeText({text: ""});
|
||||
// sendMessage(tab[0].id, action, justAddToBuffer, appliedStyles);
|
||||
});
|
||||
});
|
||||
|
@ -436,5 +456,8 @@ footer, canvas {
|
|||
if (request.type === 'is busy?') {
|
||||
sendResponse({isBusy: isBusy})
|
||||
}
|
||||
if (request.type === 'set is busy') {
|
||||
isBusy = request.isBusy
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
|
|
@ -81,9 +81,13 @@ function extractCanvasToImg($htmlObject) {
|
|||
function extractSvgToImg($htmlObject) {
|
||||
var serializer = new XMLSerializer();
|
||||
$htmlObject.find('svg').each(function (index, elem) {
|
||||
try {
|
||||
var svgXml = serializer.serializeToString(elem);
|
||||
var imgSrc = 'data:image/svg+xml;base64,' + window.btoa(svgXml);
|
||||
$(elem).replaceWith('<img src="' + imgSrc + '">' + '</img>');
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
} finally {}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -324,7 +328,7 @@ function extractCss(appliedStyles, callback) {
|
|||
if (!$pre.is(':visible')) {
|
||||
$pre.replaceWith('');
|
||||
} else {
|
||||
if (pre.tagName.roLowerCase() === 'svg') return;
|
||||
if (pre.tagName.toLowerCase() === 'svg') return;
|
||||
|
||||
var classNames = pre.getAttribute('class');
|
||||
if (!classNames) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"manifest_version": 2,
|
||||
"name": "__MSG_extName__",
|
||||
"version": "1.3",
|
||||
"version": "1.3.1",
|
||||
"default_locale": "en",
|
||||
"author": "Alex Adam",
|
||||
"homepage_url": "https://github.com/alexadam/save-as-ebook",
|
||||
|
@ -11,10 +11,10 @@
|
|||
},
|
||||
"content_scripts": [{
|
||||
"matches": ["<all_urls>"],
|
||||
"js": ["jquery.js", "jszip.js", "jszip-utils.js", "utils.js", "pure-parser.js", "cssjson.js", "extractHtml.js", "saveEbook.js" ]
|
||||
"js": ["jquery.js", "jszip.js", "jszip-utils.js", "utils.js", "pure-parser.js", "cssjson.js", "extractHtml.js"]
|
||||
}],
|
||||
"background": {
|
||||
"scripts": ["background.js", "saveEbook.js", "jszip.js", "jszip-utils.js", "filesaver.js", "utils.js"]
|
||||
"scripts": ["background.js", "utils.js"]
|
||||
},
|
||||
"browser_action": {
|
||||
"default_icon": "icons/book32.png",
|
||||
|
|
|
@ -158,7 +158,15 @@ function dispatch(action, justAddToBuffer) {
|
|||
}
|
||||
|
||||
if (!response) {
|
||||
chrome.tabs.executeScript(tab[0].id, {file: '/jquery.js'});
|
||||
// when first invoked, response will be undefined because extractHtml.js
|
||||
// was not executed yet
|
||||
chrome.tabs.executeScript(tab[0].id, {file: '/jquery.js'},
|
||||
function (result) {
|
||||
if (!result) {
|
||||
alert('Save as eBook does not work on this web site!');
|
||||
setIsBusy(false)
|
||||
document.getElementById('busy').style.display = 'none';
|
||||
} else {
|
||||
chrome.tabs.executeScript(tab[0].id, {file: '/utils.js'});
|
||||
chrome.tabs.executeScript(tab[0].id, {file: '/filesaver.js'});
|
||||
chrome.tabs.executeScript(tab[0].id, {file: '/jszip.js'});
|
||||
|
@ -171,6 +179,21 @@ function dispatch(action, justAddToBuffer) {
|
|||
}, function() {
|
||||
sendMessage(tab[0].id, action, justAddToBuffer, appliedStyles);
|
||||
});
|
||||
}
|
||||
});
|
||||
// FIXME
|
||||
// chrome.tabs.executeScript(tab[0].id, {file: '/utils.js'});
|
||||
// chrome.tabs.executeScript(tab[0].id, {file: '/filesaver.js'});
|
||||
// chrome.tabs.executeScript(tab[0].id, {file: '/jszip.js'});
|
||||
// chrome.tabs.executeScript(tab[0].id, {file: '/jszip-utils.js'});
|
||||
// chrome.tabs.executeScript(tab[0].id, {file: '/pure-parser.js'});
|
||||
// chrome.tabs.executeScript(tab[0].id, {file: '/cssjson.js'});
|
||||
//
|
||||
// chrome.tabs.executeScript(tab[0].id, {
|
||||
// file: 'extractHtml.js'
|
||||
// }, function() {
|
||||
// sendMessage(tab[0].id, action, justAddToBuffer, appliedStyles);
|
||||
// });
|
||||
} else if (response.echo) {
|
||||
sendMessage(tab[0].id, action, justAddToBuffer, appliedStyles);
|
||||
}
|
||||
|
@ -183,6 +206,12 @@ function sendMessage(tabId, action, justAddToBuffer, appliedStyles) {
|
|||
type: action,
|
||||
appliedStyles: appliedStyles
|
||||
}, function(response) {
|
||||
if (!response) {
|
||||
alert('Save as eBook does not work on this web site!');
|
||||
setIsBusy(false)
|
||||
document.getElementById('busy').style.display = 'none';
|
||||
return
|
||||
}
|
||||
if (response.length === 0) {
|
||||
if (justAddToBuffer) {
|
||||
alert('Cannot add an empty selection as chapter!');
|
||||
|
|
|
@ -181,19 +181,25 @@ function _buildEbook(allPages) {
|
|||
|
||||
|
||||
// FIXME
|
||||
var saveData = (function () {
|
||||
var a = document.createElement("a");
|
||||
document.body.appendChild(a);
|
||||
a.style = "display: none";
|
||||
return function (data, fileName) {
|
||||
var blob = new Blob([data], {type: "octet/stream"}),
|
||||
url = window.URL.createObjectURL(blob);
|
||||
a.href = url;
|
||||
a.download = fileName;
|
||||
a.click();
|
||||
window.URL.revokeObjectURL(url);
|
||||
};
|
||||
}());
|
||||
// var saveData = (function () {
|
||||
// // alert('in save data')
|
||||
// var a = document.createElement("a");
|
||||
// document.body.appendChild(a);
|
||||
// a.style = "display: none";
|
||||
// return function (data, fileName) {
|
||||
// var blob = new Blob([data], {type: "octet/stream"}),
|
||||
// url = window.URL.createObjectURL(blob);
|
||||
// // alert(url)
|
||||
// // console.log(url);
|
||||
//
|
||||
// // blob:chrome-extension://odnciljldfihdbbpbpdeehpejonicnmh/12789e3f-4ee2-4287-8203-69bc719c2ce8
|
||||
// // blob:https://uk.godaddy.com/d9cbd1a4-427d-4e55-a30a-80b9bea6547a
|
||||
// a.href = url;
|
||||
// a.download = fileName;
|
||||
// a.click();
|
||||
// window.URL.revokeObjectURL(url);
|
||||
// };
|
||||
// }());
|
||||
|
||||
zip.generateAsync({
|
||||
type: "blob"
|
||||
|
@ -201,9 +207,9 @@ function _buildEbook(allPages) {
|
|||
.then(function(content) {
|
||||
done = true;
|
||||
console.log("done !");
|
||||
// saveAs(content, ebookFileName);
|
||||
saveAs(content, ebookFileName);
|
||||
// FIXME
|
||||
saveData(content, ebookFileName);
|
||||
// saveData(content, ebookFileName);
|
||||
});
|
||||
|
||||
setTimeout(function() {
|
||||
|
|
|
@ -91,6 +91,13 @@ function checkIfBusy(callback) {
|
|||
});
|
||||
}
|
||||
|
||||
function setIsBusy(isBusy) {
|
||||
chrome.runtime.sendMessage({
|
||||
type: "set is busy",
|
||||
isBusy: isBusy
|
||||
}, function(response) {});
|
||||
}
|
||||
|
||||
/////
|
||||
function getCurrentUrl() {
|
||||
var url = window.location.href;
|
||||
|
@ -261,6 +268,8 @@ function getBase64ImgData(srcTxt) {
|
|||
}
|
||||
|
||||
function getXPath(elm) {
|
||||
if (!elm) return ''
|
||||
|
||||
var allNodes = document.getElementsByTagName('*');
|
||||
for (var segs = []; elm && elm.nodeType === 1; elm = elm.parentNode) {
|
||||
if (elm.hasAttribute('id')) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue