Skip to content

Commit 85c1a4d

Browse files
committed
Merge pull request #35 from Cortys/2.2.0
Version 2.2.0 Fixes #34
2 parents 8da84c5 + ca1215d commit 85c1a4d

File tree

14 files changed

+782
-532
lines changed

14 files changed

+782
-532
lines changed

.jsbeautifyrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"js": {
3+
"indent_level": 0,
4+
"indent_with_tabs": true,
5+
"brace_style": "end-expand",
6+
"space_after_anon_function": false,
7+
"space_before_conditional": false,
8+
"preserve_newlines": true,
9+
"max_preserve_newlines": 2,
10+
"end_with_newline": true
11+
}
12+
}

.jshintrc

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,30 @@
22
"scripturl": true,
33
"eqnull": true,
44
"loopfunc": true,
5-
"node": true
5+
"browser": true,
6+
"globalstrict": true,
7+
"esnext": true,
8+
"globals": {
9+
"div": true,
10+
"addTopBar": true,
11+
"updateDialog": true,
12+
"checkVersion": true,
13+
"linkStyle": true,
14+
"diff_match_patch": true,
15+
"sanitizeFilename": true,
16+
"rgbToHsl": true,
17+
"hslToRgb": true,
18+
"dataURLtoBlob": true,
19+
"zip": true,
20+
"getSettings": true,
21+
"connector": true,
22+
"downloadFile": true,
23+
"nullFill": true,
24+
"settings": true,
25+
"updateDialog": true,
26+
"randomString": true,
27+
"Queue": true,
28+
"chrome": true,
29+
"TEMPORARY": true
30+
}
631
}

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ The installation is slightly complicated (since I don't want to add this to the
1616
There are two ways of installing the extension.
1717

1818
### *IMPORTANT* for Windows users
19-
If you are using Chrome 35+ on Windows you have to use the [second possibility](#second-possibility)! Using packed extensions, that aren't from the Chrome Web Store, does not work anymore.
19+
If you are using Chrome on Windows you have to use the [second possibility](#second-possibility)! Using packed extensions, that aren't from the Chrome Web Store, does not work anymore.
2020

2121
### First possibility
2222

23-
The first way is [by this help page](https://support.google.com/chrome_webstore/answer/2664769?hl=en). **This does not work on Windows with Chrome version 35+.**
23+
The first way is [by this help page](https://support.google.com/chrome_webstore/answer/2664769?hl=en). **This does not work on Windows.**
2424

2525
- In Chrome, click on the settings icon on the right (looks like three vertical lines on top of each other)
2626
- Select Tools > Extensions
@@ -31,7 +31,7 @@ The first way is [by this help page](https://support.google.com/chrome_webstore/
3131

3232
The second way is without drag-and-drop, https://developer.chrome.com/extensions/getstarted#unpacked
3333

34-
**This works for Windows with Chrome version 35+!**
34+
**This works on Windows!**
3535

3636
- In Chrome, click on the settings icon on the right (looks like three vertical lines on top of each other)
3737
- Select Tools > Extensions

download.zip

502 Bytes
Binary file not shown.

extension.crx

245 Bytes
Binary file not shown.

source/backgroundManager.js

Lines changed: 74 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ var ports = { // stores all opened connections of tabs to bg page: key = tab id,
2727
if(typeof openers[sender] !== "undefined") {
2828
var opener = ports.controller[openers[sender]];
2929
if(opener) {
30-
opener.send({ what:"child_message", tab:sender, message:{ what:"closed_background_tab" } });
30+
opener.send({
31+
what: "child_message",
32+
tab: sender,
33+
message: {
34+
what: "closed_background_tab"
35+
}
36+
});
3137
delete opener.children[sender];
3238
}
3339
delete openers[sender];
@@ -38,15 +44,16 @@ var ports = { // stores all opened connections of tabs to bg page: key = tab id,
3844
getWriter = function(callback) {
3945
var tmpName, run;
4046
if(!settings.tempMemory || !requestFileSystem) {
41-
callback(new zip.BlobWriter("application/"+(settings.container?"zip":"x-cbz")));
47+
callback(new zip.BlobWriter("application/" + (settings.container ? "zip" : "x-cbz")));
4248
fs = null;
4349
}
4450
else {
4551
run = function() {
46-
tmpName = "tmp"+(Date.now())+".zip";
52+
tmpName = "tmp" + (Date.now()) + ".zip";
53+
4754
function create() {
4855
fs.root.getFile(tmpName, {
49-
create : true
56+
create: true
5057
}, function(zipFile) {
5158
callback(new zip.FileWriter(zipFile), zipFile);
5259
});
@@ -57,7 +64,7 @@ var ports = { // stores all opened connections of tabs to bg page: key = tab id,
5764
};
5865

5966
if(!fs)
60-
requestFileSystem(TEMPORARY, 4 * 1024 * 1024 * 1024, function (f) {
67+
requestFileSystem(TEMPORARY, 4 * 1024 * 1024 * 1024, function(f) {
6168
fs = f;
6269
run();
6370
});
@@ -85,41 +92,54 @@ getSettings(function() {
8592
port.children = {}; // each connection stores the ids of the tabs it opened as children; key = tab id, value always true
8693

8794
/* ZIPPING logic
88-
* moved to background script to have a dedicated tab/thread for compression so
89-
* that it doesn't make the reader tab itself slow
90-
*/
95+
* moved to background script to have a dedicated tab/thread for compression so
96+
* that it doesn't make the reader tab itself slow
97+
*/
9198
if(port.name == "reader")
9299
port.receive(function(request, callback) {
93100
if(request.what == "new_zip") {
94-
getWriter(function (writer, zipFile) {
101+
getWriter(function(writer, zipFile) {
95102
port.zipFile = zipFile;
96103
zip.createWriter(writer, function(writer) {
97104
port.zip = writer;
98105
port.user = request.user;
99-
writer.add(".meta.asc", new zip.TextReader("This is a ComiXology backup.\nPlease do not distribute it.\nBackup created by "+(request.user||"[UNKNOWN USER]")));
100-
callback({ what:"new_zip_created", error:false });
106+
writer.add(".meta.asc", new zip.TextReader("This is a ComiXology backup.\nPlease do not distribute it.\nBackup created by " + (request.user || "[UNKNOWN USER]")));
107+
callback({
108+
what: "new_zip_created",
109+
error: false
110+
});
101111
}, function() {
102-
callback({ what:"zip_creation_failed", error:true });
112+
callback({
113+
what: "zip_creation_failed",
114+
error: true
115+
});
103116
}, !settings.compression);
104117
});
105118
return true;
106119
}
107120
else if(request.what == "add_page") {
108-
var name = "page"+nullFill(request.i, request.len)+"."+request.extension,
109-
d = callback.bind(null, { what:"page_added", name:name });
121+
var name = "page" + nullFill(request.i, request.len) + "." + request.extension,
122+
d = callback.bind(null, {
123+
what: "page_added",
124+
name: name
125+
});
110126
if(request.toZip && port.zip) {
111127
port.zip.add(name, new zip.Data64URIReader(request.page), function() {
112128
d();
113-
}, undefined, { comment: port.user });
129+
}, undefined, {
130+
comment: port.user
131+
});
114132
return true;
115133
}
116134
d();
117135
}
118136
else if(request.what == "start_zipping" && port.zip) {
119137
port.zip.close(function(result) {
120138
port.zip = null;
121-
port.zipUrl = port.zipFile?port.zipFile.toURL():URL.createObjectURL(result);
122-
callback({ what:"completed_zipping" });
139+
port.zipUrl = port.zipFile ? port.zipFile.toURL() : URL.createObjectURL(result);
140+
callback({
141+
what: "completed_zipping"
142+
});
123143
});
124144
return true;
125145
}
@@ -131,17 +151,27 @@ getSettings(function() {
131151
port.zipFile.remove(function() {
132152
port.zipFile = null;
133153
});
134-
callback({ what:"download_complete" });
154+
callback({
155+
what: "download_complete"
156+
});
135157
});
136158
return true;
137159
}
138160
else if(request.what == "message_to_opener" && openers[sender] !== "undefined" && ports.controller[openers[sender]]) {
139-
ports.controller[openers[sender]].send({ what:"child_message", tab:sender, message:request.message }, callback);
161+
ports.controller[openers[sender]].send({
162+
what: "child_message",
163+
tab: sender,
164+
message: request.message
165+
}, callback);
140166
return true;
141167
}
142168
else if(request.what == "broadcast_to_openers") {
143169
for(var tab in ports.controller) {
144-
ports.controller[tab].send({ what:"child_broadcast", tab:sender, message:request.message }, callback);
170+
ports.controller[tab].send({
171+
what: "child_broadcast",
172+
tab: sender,
173+
message: request.message
174+
}, callback);
145175
}
146176
return true;
147177
}
@@ -151,13 +181,16 @@ getSettings(function() {
151181
port.unlinked = true;
152182
});
153183
/*
154-
* TAB HANDLING logic
155-
* for the controller tabs (like "My Books")
156-
*/
184+
* TAB HANDLING logic
185+
* for the controller tabs (like "My Books")
186+
*/
157187
else if(port.name == "controller")
158188
port.receive(function(request, callback) {
159189
if(request.what == "open_background_tab") {
160-
chrome.tabs.create({ url:request.url, active:request.active }, function(tab) {
190+
chrome.tabs.create({
191+
url: request.url,
192+
active: request.active
193+
}, function(tab) {
161194
openers[tab.id] = sender;
162195
port.children[tab.id] = true;
163196
ports.reader[tab.id] = true; // fake a reader port, as long as reader wasn't loaded, boolean to make it easy to check for "real" port objects
@@ -167,23 +200,26 @@ getSettings(function() {
167200
}
168201
else if(request.what == "close_background_tab")
169202
chrome.tabs.remove(request.tab, function() {
170-
chrome.runtime.lastError;
203+
return chrome.runtime.lastError;
171204
});
172205
else if(request.what == "message_to_child" && typeof ports.reader[request.tab] === "object") {
173-
ports.reader[request.tab].send({ what:"opener_message", message:request.message }, callback);
206+
ports.reader[request.tab].send({
207+
what: "opener_message",
208+
message: request.message
209+
}, callback);
174210
return true;
175211
}
176212
});
177213

178-
var disconnectAction = port.name == "controller"?function() {
179-
for (var tab in port.children)
180-
// only not YET estabished or established linked port connections are allowed:
181-
// children that once had a port are not closed (if the user started surfing in a backup tab)
214+
var disconnectAction = port.name == "controller" ? function() {
215+
for(var tab in port.children)
216+
// only not YET estabished or established linked port connections are allowed:
217+
// children that once had a port are not closed (if the user started surfing in a backup tab)
182218
if(typeof ports.reader[tab] === "object" && !ports.reader[tab].unlinked)
183-
chrome.tabs.remove(tab*1, function() {
184-
chrome.runtime.lastError;
185-
});
186-
}:closedReader;
219+
chrome.tabs.remove(tab * 1, function() {
220+
return chrome.runtime.lastError;
221+
});
222+
} : closedReader;
187223

188224
port.onDisconnect.addListener(function() {
189225
delete ports[port.name][sender];
@@ -196,7 +232,10 @@ getSettings(function() {
196232

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

202241
// Old communication channel to options page. Separated from the port system to reduce memory and logic overhead.

0 commit comments

Comments
 (0)