mirror of
https://github.com/alexadam/save-as-ebook.git
synced 2025-09-16 04:09:53 +00:00
misc
This commit is contained in:
parent
da4f3eb7f8
commit
3a16cb82a1
5 changed files with 123 additions and 125 deletions
|
@ -2,26 +2,6 @@ var allImgSrc = {};
|
|||
var allImgsData = {};
|
||||
//////
|
||||
|
||||
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) {
|
||||
var tmpFileName = fileName.split('.').pop();
|
||||
if (tmpFileName.indexOf('?') > 0) {
|
||||
tmpFileName = tmpFileName.split('?')[0];
|
||||
}
|
||||
if (tmpFileName.trim() === '') {
|
||||
return 'jpg'; //TODO
|
||||
}
|
||||
return tmpFileName;
|
||||
}
|
||||
|
||||
function getImageSrc(srcTxt) {
|
||||
if (!srcTxt) {
|
||||
return '';
|
||||
|
@ -30,20 +10,6 @@ function getImageSrc(srcTxt) {
|
|||
return '../images/' + allImgSrc[srcTxt];
|
||||
}
|
||||
|
||||
function getHref(hrefTxt) {
|
||||
if (!hrefTxt) {
|
||||
return '';
|
||||
}
|
||||
if (hrefTxt.indexOf('#') === 0) {
|
||||
hrefTxt = window.location.href + hrefTxt;
|
||||
}
|
||||
if (hrefTxt.indexOf('/') === 0) {
|
||||
hrefTxt = window.location.protocol + '//' + window.location.hostname + hrefTxt;
|
||||
}
|
||||
// hrefTxt = escape(hrefTxt); // TODO
|
||||
return hrefTxt;
|
||||
}
|
||||
|
||||
function force(contentString) {
|
||||
try {
|
||||
var tagOpen = '@@@';
|
||||
|
@ -296,18 +262,20 @@ function deferredAddZip(url, filename, zip) {
|
|||
return deferred;
|
||||
}
|
||||
|
||||
function getImgDownloadUrl(baseUrl, imgSrc) {
|
||||
function getImgDownloadUrl(imgSrc) {
|
||||
var baseUrl = getOriginUrl();
|
||||
if (imgSrc.indexOf('//') === 0) {
|
||||
return baseUrl.split('//')[0] + imgSrc;
|
||||
}
|
||||
if (imgSrc.indexOf('http') !== 0) {
|
||||
if (imgSrc.indexOf('/') === 0) {
|
||||
return baseUrl + imgSrc;
|
||||
}
|
||||
return baseUrl + '/' + imgSrc;
|
||||
}
|
||||
return imgSrc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
|
||||
console.log('Extract Html...');
|
||||
var imgsPromises = [];
|
||||
|
@ -333,7 +301,7 @@ chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
|
|||
|
||||
Object.keys(allImgSrc).forEach(function(imgSrc, index) {
|
||||
try {
|
||||
var tmpDeffered = deferredAddZip(getImgDownloadUrl(getCurrentUrl(), imgSrc), allImgSrc[imgSrc]);
|
||||
var tmpDeffered = deferredAddZip(getImgDownloadUrl(imgSrc), allImgSrc[imgSrc]);
|
||||
imgsPromises.push(tmpDeffered);
|
||||
} catch (e) {
|
||||
alert(e);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue