Skip to content

Commit

Permalink
Merge pull request #31 from Cortys/2.1.1
Browse files Browse the repository at this point in the history
Version 2.1.1
  • Loading branch information
Cortys committed Jul 11, 2015
2 parents cf80d7d + 65a66c3 commit ee5ef10
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 36 deletions.
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"scripturl": true,
"eqnull": true,
"loopfunc": true
"loopfunc": true,
"node": true
}
Binary file modified download.zip
Binary file not shown.
Binary file modified extension.crx
Binary file not shown.
15 changes: 10 additions & 5 deletions source/backgroundManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//Code is under GNUGPLv3 - read http://www.gnu.org/licenses/gpl.html
"use strict";

zip.useWebWorkers = true;

Expand Down Expand Up @@ -165,8 +166,10 @@ getSettings(function() {
return true;
}
else if(request.what == "close_background_tab")
chrome.tabs.remove(request.tab);
else if(request.what == "message_to_child" && typeof ports.reader[request.tab] == "object") {
chrome.tabs.remove(request.tab, function() {
chrome.runtime.lastError;
});
else if(request.what == "message_to_child" && typeof ports.reader[request.tab] === "object") {
ports.reader[request.tab].send({ what:"opener_message", message:request.message }, callback);
return true;
}
Expand All @@ -176,8 +179,10 @@ getSettings(function() {
for (var tab in port.children)
// only not YET estabished or established linked port connections are allowed:
// children that once had a port are not closed (if the user started surfing in a backup tab)
if(ports.reader[tab] && !ports.reader[tab].unlinked)
chrome.tabs.remove(tab*1);
if(typeof ports.reader[tab] === "object" && !ports.reader[tab].unlinked)
chrome.tabs.remove(tab*1, function() {
chrome.runtime.lastError;
});
}:closedReader;

port.onDisconnect.addListener(function() {
Expand All @@ -190,7 +195,7 @@ getSettings(function() {
});

chrome.tabs.onRemoved.addListener(function(tab) {
if(!ports.reader[tab] && tab in openers) // tab is a backup-purpose reader but there is no port connection yet:
if(ports.reader[tab] === true && tab in openers) // tab is a backup-purpose reader but there is no port connection yet:
closedReader({ senderId:tab, fake:true }); // port disconnect wont fire, so it will be "faked".
});

Expand Down
35 changes: 24 additions & 11 deletions source/comicReader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//Code is under GNUGPLv3 - read http://www.gnu.org/licenses/gpl.html
"use strict";

var overlay = document.createElement("div");

Expand Down Expand Up @@ -573,16 +574,21 @@ function loadComic(callback, step) {
interval();
}, end = function() {
dom.getCanvasContainer().parentElement.removeEventListener("DOMNodeRemoved", rmListener, false);
step("zip");
zipImages(function() {
step("save");
downloadBlob(getName()+"."+(settings.container?"zip":"cbz"), function() {
document.documentElement.removeChild(div);
document.documentElement.removeChild(overlay);
realClick(firstPageFig);
callback();
function done() {
document.documentElement.removeChild(div);
document.documentElement.removeChild(overlay);
realClick(firstPageFig);
callback();
}
if(settings.container == 2)
done();
else {
step("zip");
zipImages(function() {
step("save");
downloadBlob(getName()+"."+(settings.container?"zip":"cbz"), done);
});
});
}
}, rmListener = function(e) {
clearTimeout(noChangeTimeout);
var container = dom.canvasContainer,
Expand Down Expand Up @@ -619,8 +625,15 @@ function getName() {
if(getName.title != null)
return getName.title;
var title = document.getElementsByTagName('title');
if(title[0])
return (getName.title = title[0].innerHTML.substr(0, title[0].innerHTML.lastIndexOf("-")).trim().replace(/\s/g, "_").replace(/[^a-z0-9#.()\[\]_-]/gi, ""));
if(title[0]) {
var spaceReplacement = {
1: "_",
2: ".",
3: "-",
4: ""
}[settings.filename];
return (getName.title = sanitizeFilename(title[0].innerHTML.substr(0, title[0].innerHTML.lastIndexOf("-")).trim(), spaceReplacement) || "comic");
}
return "comic";
}
getName.title = null;
Expand Down
19 changes: 18 additions & 1 deletion source/common.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var current_version = 114,
"use strict";

var current_version = 115,
div, linkStyle = "color:#ffffff;font-weight:bold;background:linear-gradient(to bottom, rgb(115, 152, 200) 0%,rgb(179, 206, 233) 1%,rgb(82, 142, 204) 5%,rgb(79, 137, 200) 20%,rgb(66, 120, 184) 50%,rgb(49, 97, 161) 100%);padding:3px;text-decoration:none;display:inline-block;width:70px;text-align:center;height:22px;box-sizing:border-box;line-height:14px;border:1px solid rgb(49,96,166);",
settings;

Expand All @@ -18,6 +20,21 @@ function randomString(min, max) { // generates random alphanumeric string with a
return r;
}

// Cleans up a string to be a valid cross platform filename.
// Inspired by https://github.com/parshap/node-sanitize-filename.
function sanitizeFilename(input, spaceReplacement) {
var result = input
.replace(/\s?[\/\\\|\?<>:\*\":]+\s?/g, " ")
.replace(/[\x00-\x1f\x80-\x9f]/g, "")
.replace(/(\.|\s)+$/g, "")
.replace(/^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i, "");

if(spaceReplacement != null)
result = result.replace(/\s/g, spaceReplacement);

return result;
}

function nullFill(num, len) {
num += "";
while(num.length < len)
Expand Down
30 changes: 14 additions & 16 deletions source/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"name": "Comixology Backup",
"description": "Save your Comixology comics as standard CBZ files.",
"version": "2.1.0",
"version": "2.1.1",
"minimum_chrome_version": "31",

"icons": {
Expand Down Expand Up @@ -31,21 +31,19 @@
"persistent": false
},

"content_scripts": [
{
"matches": ["*://www.comixology.com/comic-reader/*","*://www.comixology.eu/comic-reader/*","*://www.comixology.co.uk/comic-reader/*","*://www.comixology.fr/comic-reader/*","*://www.comixology.de/comic-reader/*"],
"js": ["common.js", "reactivateDom.js"],
"run_at": "document_start"
}, {
"matches": ["*://www.comixology.com/comic-reader/*","*://www.comixology.eu/comic-reader/*","*://www.comixology.co.uk/comic-reader/*","*://www.comixology.fr/comic-reader/*","*://www.comixology.de/comic-reader/*"],
"js": ["diffMatchPatch.js", "common.js", "comicReader.js"],
"run_at": "document_idle"
}, {
"matches": ["*://www.comixology.com/my-*","*://www.comixology.eu/my-*","*://www.comixology.co.uk/my-*","*://www.comixology.fr/my-*","*://www.comixology.de/my-*", "*://www.comixology.com/wishlists*","*://www.comixology.eu/wishlists","*://www.comixology.co.uk/wishlists","*://www.comixology.fr/wishlists","*://www.comixology.de/wishlists"],
"js": ["common.js", "myBooks.js"],
"run_at": "document_end"
}
],
"content_scripts": [{
"matches": ["*://www.comixology.com/comic-reader/*", "*://www.comixology.eu/comic-reader/*", "*://www.comixology.co.uk/comic-reader/*", "*://www.comixology.fr/comic-reader/*", "*://www.comixology.de/comic-reader/*"],
"js": ["common.js", "reactivateDom.js"],
"run_at": "document_start"
}, {
"matches": ["*://www.comixology.com/comic-reader/*", "*://www.comixology.eu/comic-reader/*", "*://www.comixology.co.uk/comic-reader/*", "*://www.comixology.fr/comic-reader/*", "*://www.comixology.de/comic-reader/*"],
"js": ["diffMatchPatch.js", "common.js", "comicReader.js"],
"run_at": "document_idle"
}, {
"matches": ["*://www.comixology.com/my-*", "*://www.comixology.eu/my-*", "*://www.comixology.co.uk/my-*", "*://www.comixology.fr/my-*", "*://www.comixology.de/my-*", "*://www.comixology.com/wishlists*", "*://www.comixology.eu/wishlists", "*://www.comixology.co.uk/wishlists", "*://www.comixology.fr/wishlists", "*://www.comixology.de/wishlists"],
"js": ["common.js", "myBooks.js"],
"run_at": "document_end"
}],

"options_page": "options.html",

Expand Down
2 changes: 2 additions & 0 deletions source/myBooks.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

getSettings(function() {

if(!settings.queueLength)
Expand Down
9 changes: 8 additions & 1 deletion source/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
</style>
</head>
<body>
<a href="https://github.com/Cortys" target="_blank" id="credits">v2.1.0 by <b>Cortys</b></a>
<a href="https://github.com/Cortys" target="_blank" id="credits">v2.1.1 by <b>Cortys</b></a>
<h1><img src="logoOptions@2x.png" alt="Comixology Backup Settings"></h1>
<div id="content">
<h2>Backup behaviour</h2>
Expand All @@ -144,6 +144,13 @@ <h2>Backup behaviour</h2>
<option value="0">first page</option>
<option value="1">currently opened page</option>
</select></div><br>
<div class="aligner">Filename convention:</div><div class="aligner r"><select id="filename">
<option value="0">All valid filenames</option>
<option value="1">Underscores instead of spaces</option>
<option value="2">Dots instead of spaces</option>
<option value="3">Dashes instead of spaces</option>
<option value="4">Remove spaces</option>
</select></div><br>
<div class="aligner">Max. parallel downloads per tab:</div><div class="aligner r"><select id="queueLength" data-message="update_queue">
<option value="1">1</option>
<option value="2">2</option>
Expand Down
2 changes: 2 additions & 0 deletions source/options.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

var selects = document.querySelectorAll("select, input");

for(var i = 0; i < selects.length; i++)
Expand Down
2 changes: 2 additions & 0 deletions source/reactivateDom.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict";

var script = document.createElement("script");
script.type = "text/javascript";
script.id = randomString(20,40);
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
114
115

0 comments on commit ee5ef10

Please sign in to comment.