Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
cd546eb6
Commit
cd546eb6
authored
Jun 17, 2019
by
Ozzieisaacs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update comic reader js
parent
e67d7078
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
311 additions
and
292 deletions
+311
-292
archive.js
cps/static/js/archive/archive.js
+23
-24
rarvm.js
cps/static/js/archive/rarvm.js
+112
-106
unrar.js
cps/static/js/archive/unrar.js
+68
-65
untar.js
cps/static/js/archive/untar.js
+13
-10
unzip.js
cps/static/js/archive/unzip.js
+15
-21
bitstream.js
cps/static/js/io/bitstream.js
+23
-19
bytebuffer.js
cps/static/js/io/bytebuffer.js
+12
-9
bytestream.js
cps/static/js/io/bytestream.js
+12
-8
kthoom.js
cps/static/js/kthoom.js
+33
-30
No files found.
cps/static/js/archive/archive.js
View file @
cd546eb6
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
* Copyright(c) 2011 Google Inc.
* Copyright(c) 2011 Google Inc.
*/
*/
/* global bitjs */
/* global bitjs
, Uint8Array
*/
var
bitjs
=
bitjs
||
{};
var
bitjs
=
bitjs
||
{};
bitjs
.
archive
=
bitjs
.
archive
||
{};
bitjs
.
archive
=
bitjs
.
archive
||
{};
...
@@ -17,7 +17,7 @@ bitjs.archive = bitjs.archive || {};
...
@@ -17,7 +17,7 @@ bitjs.archive = bitjs.archive || {};
// ===========================================================================
// ===========================================================================
// Stolen from Closure because it's the best way to do Java-like inheritance.
// Stolen from Closure because it's the best way to do Java-like inheritance.
bitjs
.
base
=
function
(
me
,
opt
_methodName
,
var_a
rgs
)
{
bitjs
.
base
=
function
(
me
,
opt
MethodName
,
varA
rgs
)
{
var
caller
=
arguments
.
callee
.
caller
;
var
caller
=
arguments
.
callee
.
caller
;
if
(
caller
.
superClass_
)
{
if
(
caller
.
superClass_
)
{
// This is a constructor. Call the superclass constructor.
// This is a constructor. Call the superclass constructor.
...
@@ -28,10 +28,10 @@ bitjs.archive = bitjs.archive || {};
...
@@ -28,10 +28,10 @@ bitjs.archive = bitjs.archive || {};
var
args
=
Array
.
prototype
.
slice
.
call
(
arguments
,
2
);
var
args
=
Array
.
prototype
.
slice
.
call
(
arguments
,
2
);
var
foundCaller
=
false
;
var
foundCaller
=
false
;
for
(
var
ctor
=
me
.
constructor
;
ctor
;
ctor
=
ctor
.
superClass_
&&
ctor
.
superClass_
.
constructor
)
{
for
(
var
ctor
=
me
.
constructor
;
ctor
;
ctor
=
ctor
.
superClass_
&&
ctor
.
superClass_
.
constructor
)
{
if
(
ctor
.
prototype
[
opt
_m
ethodName
]
===
caller
)
{
if
(
ctor
.
prototype
[
opt
M
ethodName
]
===
caller
)
{
foundCaller
=
true
;
foundCaller
=
true
;
}
else
if
(
foundCaller
)
{
}
else
if
(
foundCaller
)
{
return
ctor
.
prototype
[
opt
_m
ethodName
].
apply
(
me
,
args
);
return
ctor
.
prototype
[
opt
M
ethodName
].
apply
(
me
,
args
);
}
}
}
}
...
@@ -39,8 +39,8 @@ bitjs.archive = bitjs.archive || {};
...
@@ -39,8 +39,8 @@ bitjs.archive = bitjs.archive || {};
// then one of two things happened:
// then one of two things happened:
// 1) The caller is an instance method.
// 1) The caller is an instance method.
// 2) This method was not called by the right caller.
// 2) This method was not called by the right caller.
if
(
me
[
opt
_m
ethodName
]
===
caller
)
{
if
(
me
[
opt
M
ethodName
]
===
caller
)
{
return
me
.
constructor
.
prototype
[
opt
_m
ethodName
].
apply
(
me
,
args
);
return
me
.
constructor
.
prototype
[
opt
M
ethodName
].
apply
(
me
,
args
);
}
else
{
}
else
{
throw
Error
(
throw
Error
(
"goog.base called from a method of one name "
+
"goog.base called from a method of one name "
+
...
@@ -49,10 +49,10 @@ bitjs.archive = bitjs.archive || {};
...
@@ -49,10 +49,10 @@ bitjs.archive = bitjs.archive || {};
};
};
bitjs
.
inherits
=
function
(
childCtor
,
parentCtor
)
{
bitjs
.
inherits
=
function
(
childCtor
,
parentCtor
)
{
/** @constructor */
/** @constructor */
function
tempCtor
()
{};
function
TempCtor
()
{}
t
empCtor
.
prototype
=
parentCtor
.
prototype
;
T
empCtor
.
prototype
=
parentCtor
.
prototype
;
childCtor
.
superClass_
=
parentCtor
.
prototype
;
childCtor
.
superClass_
=
parentCtor
.
prototype
;
childCtor
.
prototype
=
new
t
empCtor
();
childCtor
.
prototype
=
new
T
empCtor
();
childCtor
.
prototype
.
constructor
=
childCtor
;
childCtor
.
prototype
.
constructor
=
childCtor
;
};
};
// ===========================================================================
// ===========================================================================
...
@@ -188,10 +188,10 @@ bitjs.archive = bitjs.archive || {};
...
@@ -188,10 +188,10 @@ bitjs.archive = bitjs.archive || {};
* Base class for all Unarchivers.
* Base class for all Unarchivers.
*
*
* @param {ArrayBuffer} arrayBuffer The Array Buffer.
* @param {ArrayBuffer} arrayBuffer The Array Buffer.
* @param {string} opt
_p
athToBitJS Optional string for where the BitJS files are located.
* @param {string} opt
P
athToBitJS Optional string for where the BitJS files are located.
* @constructor
* @constructor
*/
*/
bitjs
.
archive
.
Unarchiver
=
function
(
arrayBuffer
,
opt
_p
athToBitJS
)
{
bitjs
.
archive
.
Unarchiver
=
function
(
arrayBuffer
,
opt
P
athToBitJS
)
{
/**
/**
* The ArrayBuffer object.
* The ArrayBuffer object.
* @type {ArrayBuffer}
* @type {ArrayBuffer}
...
@@ -204,7 +204,7 @@ bitjs.archive = bitjs.archive || {};
...
@@ -204,7 +204,7 @@ bitjs.archive = bitjs.archive || {};
* @type {string}
* @type {string}
* @private
* @private
*/
*/
this
.
pathToBitJS_
=
opt
_p
athToBitJS
||
"/"
;
this
.
pathToBitJS_
=
opt
P
athToBitJS
||
"/"
;
/**
/**
* A map from event type to an array of listeners.
* A map from event type to an array of listeners.
...
@@ -319,8 +319,8 @@ bitjs.archive = bitjs.archive || {};
...
@@ -319,8 +319,8 @@ bitjs.archive = bitjs.archive || {};
* @extends {bitjs.archive.Unarchiver}
* @extends {bitjs.archive.Unarchiver}
* @constructor
* @constructor
*/
*/
bitjs
.
archive
.
Unzipper
=
function
(
arrayBuffer
,
opt
_p
athToBitJS
)
{
bitjs
.
archive
.
Unzipper
=
function
(
arrayBuffer
,
opt
P
athToBitJS
)
{
bitjs
.
base
(
this
,
arrayBuffer
,
opt
_p
athToBitJS
);
bitjs
.
base
(
this
,
arrayBuffer
,
opt
P
athToBitJS
);
};
};
bitjs
.
inherits
(
bitjs
.
archive
.
Unzipper
,
bitjs
.
archive
.
Unarchiver
);
bitjs
.
inherits
(
bitjs
.
archive
.
Unzipper
,
bitjs
.
archive
.
Unarchiver
);
bitjs
.
archive
.
Unzipper
.
prototype
.
getScriptFileName
=
function
()
{
bitjs
.
archive
.
Unzipper
.
prototype
.
getScriptFileName
=
function
()
{
...
@@ -332,8 +332,8 @@ bitjs.archive = bitjs.archive || {};
...
@@ -332,8 +332,8 @@ bitjs.archive = bitjs.archive || {};
* @extends {bitjs.archive.Unarchiver}
* @extends {bitjs.archive.Unarchiver}
* @constructor
* @constructor
*/
*/
bitjs
.
archive
.
Unrarrer
=
function
(
arrayBuffer
,
opt
_p
athToBitJS
)
{
bitjs
.
archive
.
Unrarrer
=
function
(
arrayBuffer
,
opt
P
athToBitJS
)
{
bitjs
.
base
(
this
,
arrayBuffer
,
opt
_p
athToBitJS
);
bitjs
.
base
(
this
,
arrayBuffer
,
opt
P
athToBitJS
);
};
};
bitjs
.
inherits
(
bitjs
.
archive
.
Unrarrer
,
bitjs
.
archive
.
Unarchiver
);
bitjs
.
inherits
(
bitjs
.
archive
.
Unrarrer
,
bitjs
.
archive
.
Unarchiver
);
bitjs
.
archive
.
Unrarrer
.
prototype
.
getScriptFileName
=
function
()
{
bitjs
.
archive
.
Unrarrer
.
prototype
.
getScriptFileName
=
function
()
{
...
@@ -345,8 +345,8 @@ bitjs.archive = bitjs.archive || {};
...
@@ -345,8 +345,8 @@ bitjs.archive = bitjs.archive || {};
* @extends {bitjs.archive.Unarchiver}
* @extends {bitjs.archive.Unarchiver}
* @constructor
* @constructor
*/
*/
bitjs
.
archive
.
Untarrer
=
function
(
arrayBuffer
,
opt
_p
athToBitJS
)
{
bitjs
.
archive
.
Untarrer
=
function
(
arrayBuffer
,
opt
P
athToBitJS
)
{
bitjs
.
base
(
this
,
arrayBuffer
,
opt
_p
athToBitJS
);
bitjs
.
base
(
this
,
arrayBuffer
,
opt
P
athToBitJS
);
};
};
bitjs
.
inherits
(
bitjs
.
archive
.
Untarrer
,
bitjs
.
archive
.
Unarchiver
);
bitjs
.
inherits
(
bitjs
.
archive
.
Untarrer
,
bitjs
.
archive
.
Unarchiver
);
bitjs
.
archive
.
Untarrer
.
prototype
.
getScriptFileName
=
function
()
{
bitjs
.
archive
.
Untarrer
.
prototype
.
getScriptFileName
=
function
()
{
...
@@ -357,20 +357,19 @@ bitjs.archive = bitjs.archive || {};
...
@@ -357,20 +357,19 @@ bitjs.archive = bitjs.archive || {};
* Factory method that creates an unarchiver based on the byte signature found
* Factory method that creates an unarchiver based on the byte signature found
* in the arrayBuffer.
* in the arrayBuffer.
* @param {ArrayBuffer} ab
* @param {ArrayBuffer} ab
* @param {string=} opt
_p
athToBitJS Path to the unarchiver script files.
* @param {string=} opt
P
athToBitJS Path to the unarchiver script files.
* @return {bitjs.archive.Unarchiver}
* @return {bitjs.archive.Unarchiver}
*/
*/
bitjs
.
archive
.
GetUnarchiver
=
function
(
ab
,
opt
_p
athToBitJS
)
{
bitjs
.
archive
.
GetUnarchiver
=
function
(
ab
,
opt
P
athToBitJS
)
{
var
unarchiver
=
null
;
var
unarchiver
=
null
;
var
pathToBitJS
=
opt
_pathToBitJS
||
''
;
var
pathToBitJS
=
opt
PathToBitJS
||
""
;
var
h
=
new
Uint8Array
(
ab
,
0
,
10
);
var
h
=
new
Uint8Array
(
ab
,
0
,
10
);
if
(
h
[
0
]
==
0x52
&&
h
[
1
]
==
0x61
&&
h
[
2
]
==
0x72
&&
h
[
3
]
==
0x21
)
{
// Rar!
if
(
h
[
0
]
==
=
0x52
&&
h
[
1
]
===
0x61
&&
h
[
2
]
===
0x72
&&
h
[
3
]
=
==
0x21
)
{
// Rar!
unarchiver
=
new
bitjs
.
archive
.
Unrarrer
(
ab
,
pathToBitJS
);
unarchiver
=
new
bitjs
.
archive
.
Unrarrer
(
ab
,
pathToBitJS
);
}
else
if
(
h
[
0
]
==
80
&&
h
[
1
]
==
75
)
{
// PK (Zip)
}
else
if
(
h
[
0
]
==
=
80
&&
h
[
1
]
=
==
75
)
{
// PK (Zip)
unarchiver
=
new
bitjs
.
archive
.
Unzipper
(
ab
,
pathToBitJS
);
unarchiver
=
new
bitjs
.
archive
.
Unzipper
(
ab
,
pathToBitJS
);
}
else
{
// Try with tar
}
else
{
// Try with tar
console
.
log
(
'geter'
);
unarchiver
=
new
bitjs
.
archive
.
Untarrer
(
ab
,
pathToBitJS
);
unarchiver
=
new
bitjs
.
archive
.
Untarrer
(
ab
,
pathToBitJS
);
}
}
return
unarchiver
;
return
unarchiver
;
...
...
cps/static/js/archive/rarvm.js
View file @
cd546eb6
This diff is collapsed.
Click to expand it.
cps/static/js/archive/unrar.js
View file @
cd546eb6
This diff is collapsed.
Click to expand it.
cps/static/js/archive/untar.js
View file @
cd546eb6
...
@@ -10,9 +10,11 @@
...
@@ -10,9 +10,11 @@
* TAR format: http://www.gnu.org/software/automake/manual/tar/Standard.html
* TAR format: http://www.gnu.org/software/automake/manual/tar/Standard.html
*/
*/
/* global bitjs, importScripts, Uint8Array */
// This file expects to be invoked as a Worker (see onmessage below).
// This file expects to be invoked as a Worker (see onmessage below).
importScripts
(
'../io/bytestream.js'
);
importScripts
(
"../io/bytestream.js"
);
importScripts
(
'archive.js'
);
importScripts
(
"archive.js"
);
// Progress variables.
// Progress variables.
var
currentFilename
=
""
;
var
currentFilename
=
""
;
...
@@ -21,6 +23,7 @@ var currentBytesUnarchivedInFile = 0;
...
@@ -21,6 +23,7 @@ var currentBytesUnarchivedInFile = 0;
var
currentBytesUnarchived
=
0
;
var
currentBytesUnarchived
=
0
;
var
totalUncompressedBytesInArchive
=
0
;
var
totalUncompressedBytesInArchive
=
0
;
var
totalFilesInArchive
=
0
;
var
totalFilesInArchive
=
0
;
var
allLocalFiles
=
[];
// Helper functions.
// Helper functions.
var
info
=
function
(
str
)
{
var
info
=
function
(
str
)
{
...
@@ -44,7 +47,7 @@ var postProgress = function() {
...
@@ -44,7 +47,7 @@ var postProgress = function() {
currentBytesUnarchivedInFile
,
currentBytesUnarchivedInFile
,
currentBytesUnarchived
,
currentBytesUnarchived
,
totalUncompressedBytesInArchive
,
totalUncompressedBytesInArchive
,
totalFilesInArchive
,
totalFilesInArchive
));
));
};
};
...
@@ -66,7 +69,7 @@ var TarLocalFile = function(bstream) {
...
@@ -66,7 +69,7 @@ var TarLocalFile = function(bstream) {
this
.
linkname
=
readCleanString
(
bstream
,
100
);
this
.
linkname
=
readCleanString
(
bstream
,
100
);
this
.
maybeMagic
=
readCleanString
(
bstream
,
6
);
this
.
maybeMagic
=
readCleanString
(
bstream
,
6
);
if
(
this
.
maybeMagic
==
"ustar"
)
{
if
(
this
.
maybeMagic
==
=
"ustar"
)
{
this
.
version
=
readCleanString
(
bstream
,
2
);
this
.
version
=
readCleanString
(
bstream
,
2
);
this
.
uname
=
readCleanString
(
bstream
,
32
);
this
.
uname
=
readCleanString
(
bstream
,
32
);
this
.
gname
=
readCleanString
(
bstream
,
32
);
this
.
gname
=
readCleanString
(
bstream
,
32
);
...
@@ -103,14 +106,14 @@ var TarLocalFile = function(bstream) {
...
@@ -103,14 +106,14 @@ var TarLocalFile = function(bstream) {
}
}
// Round up to 512-byte blocks.
// Round up to 512-byte blocks.
var
remaining
=
512
-
bytesRead
%
512
;
var
remaining
=
512
-
(
bytesRead
%
512
)
;
if
(
remaining
>
0
&&
remaining
<
512
)
{
if
(
remaining
>
0
&&
remaining
<
512
)
{
bstream
.
readBytes
(
remaining
);
bstream
.
readBytes
(
remaining
);
}
}
}
else
if
(
this
.
typeflag
==
5
)
{
}
else
if
(
this
.
typeflag
==
5
)
{
info
(
" This is a directory."
);
info
(
" This is a directory."
);
}
}
}
}
;
var
untar
=
function
(
arrayBuffer
)
{
var
untar
=
function
(
arrayBuffer
)
{
postMessage
(
new
bitjs
.
archive
.
UnarchiveStartEvent
());
postMessage
(
new
bitjs
.
archive
.
UnarchiveStartEvent
());
...
@@ -125,7 +128,7 @@ var untar = function(arrayBuffer) {
...
@@ -125,7 +128,7 @@ var untar = function(arrayBuffer) {
var
bstream
=
new
bitjs
.
io
.
ByteStream
(
arrayBuffer
);
var
bstream
=
new
bitjs
.
io
.
ByteStream
(
arrayBuffer
);
postProgress
();
postProgress
();
// While we don't encounter an empty block, keep making TarLocalFiles.
// While we don't encounter an empty block, keep making TarLocalFiles.
while
(
bstream
.
peekNumber
(
4
)
!=
0
)
{
while
(
bstream
.
peekNumber
(
4
)
!=
=
0
)
{
var
oneLocalFile
=
new
TarLocalFile
(
bstream
);
var
oneLocalFile
=
new
TarLocalFile
(
bstream
);
if
(
oneLocalFile
&&
oneLocalFile
.
isValid
)
{
if
(
oneLocalFile
&&
oneLocalFile
.
isValid
)
{
// If we make it to this point and haven't thrown an error, we have successfully
// If we make it to this point and haven't thrown an error, we have successfully
...
@@ -159,8 +162,8 @@ onmessage = function(event) {
...
@@ -159,8 +162,8 @@ onmessage = function(event) {
// Overrun the buffer.
// Overrun the buffer.
// unarchiveState = UnarchiveState.WAITING;
// unarchiveState = UnarchiveState.WAITING;
}
else
{
}
else
{
console
.
erro
r
(
"Found an error while untarring"
);
er
r
(
"Found an error while untarring"
);
console
.
log
(
e
);
err
(
e
);
throw
e
;
throw
e
;
}
}
}
}
...
...
cps/static/js/archive/unzip.js
View file @
cd546eb6
...
@@ -14,10 +14,10 @@
...
@@ -14,10 +14,10 @@
/* global bitjs, importScripts, Uint8Array*/
/* global bitjs, importScripts, Uint8Array*/
// This file expects to be invoked as a Worker (see onmessage below).
// This file expects to be invoked as a Worker (see onmessage below).
importScripts
(
'../io/bitstream.js'
);
importScripts
(
"../io/bitstream.js"
);
importScripts
(
'../io/bytebuffer.js'
);
importScripts
(
"../io/bytebuffer.js"
);
importScripts
(
'../io/bytestream.js'
);
importScripts
(
"../io/bytestream.js"
);
importScripts
(
'archive.js'
);
importScripts
(
"archive.js"
);
// Progress variables.
// Progress variables.
var
currentFilename
=
""
;
var
currentFilename
=
""
;
...
@@ -118,13 +118,11 @@ ZipLocalFile.prototype.unzip = function() {
...
@@ -118,13 +118,11 @@ ZipLocalFile.prototype.unzip = function() {
currentBytesUnarchivedInFile
=
this
.
compressedSize
;
currentBytesUnarchivedInFile
=
this
.
compressedSize
;
currentBytesUnarchived
+=
this
.
compressedSize
;
currentBytesUnarchived
+=
this
.
compressedSize
;
this
.
fileData
=
zeroCompression
(
this
.
fileData
,
this
.
uncompressedSize
);
this
.
fileData
=
zeroCompression
(
this
.
fileData
,
this
.
uncompressedSize
);
}
}
else
if
(
this
.
compressionMethod
===
8
)
{
// version == 20, compression method == 8 (DEFLATE)
// version == 20, compression method == 8 (DEFLATE)
else
if
(
this
.
compressionMethod
===
8
)
{
info
(
"ZIP v2.0, DEFLATE: "
+
this
.
filename
+
" ("
+
this
.
compressedSize
+
" bytes)"
);
info
(
"ZIP v2.0, DEFLATE: "
+
this
.
filename
+
" ("
+
this
.
compressedSize
+
" bytes)"
);
this
.
fileData
=
inflate
(
this
.
fileData
,
this
.
uncompressedSize
);
this
.
fileData
=
inflate
(
this
.
fileData
,
this
.
uncompressedSize
);
}
}
else
{
else
{
err
(
"UNSUPPORTED VERSION/FORMAT: ZIP v"
+
this
.
version
+
", compression method="
+
this
.
compressionMethod
+
": "
+
this
.
filename
+
" ("
+
this
.
compressedSize
+
" bytes)"
);
err
(
"UNSUPPORTED VERSION/FORMAT: ZIP v"
+
this
.
version
+
", compression method="
+
this
.
compressionMethod
+
": "
+
this
.
filename
+
" ("
+
this
.
compressedSize
+
" bytes)"
);
this
.
fileData
=
null
;
this
.
fileData
=
null
;
}
}
...
@@ -497,13 +495,11 @@ function inflateBlockData(bstream, hcLiteralTable, hcDistanceTable, buffer) {
...
@@ -497,13 +495,11 @@ function inflateBlockData(bstream, hcLiteralTable, hcDistanceTable, buffer) {
// copy literal byte to output
// copy literal byte to output
buffer
.
insertByte
(
symbol
);
buffer
.
insertByte
(
symbol
);
blockSize
++
;
blockSize
++
;
}
}
else
{
else
{
// end of block reached
// end of block reached
if
(
symbol
===
256
)
{
if
(
symbol
===
256
)
{
break
;
break
;
}
}
else
{
else
{
var
lengthLookup
=
LengthLookupTable
[
symbol
-
257
],
var
lengthLookup
=
LengthLookupTable
[
symbol
-
257
],
length
=
lengthLookup
[
1
]
+
bstream
.
readBits
(
lengthLookup
[
0
]),
length
=
lengthLookup
[
1
]
+
bstream
.
readBits
(
lengthLookup
[
0
]),
distLookup
=
DistLookupTable
[
decodeSymbol
(
bstream
,
hcDistanceTable
)],
distLookup
=
DistLookupTable
[
decodeSymbol
(
bstream
,
hcDistanceTable
)],
...
@@ -566,7 +562,7 @@ function inflate(compressedData, numDecompressedBytes) {
...
@@ -566,7 +562,7 @@ function inflate(compressedData, numDecompressedBytes) {
blockSize
=
0
;
blockSize
=
0
;
// ++numBlocks;
// ++numBlocks;
// no compression
// no compression
if
(
bType
==
0
)
{
if
(
bType
==
=
0
)
{
// skip remaining bits in this byte
// skip remaining bits in this byte
while
(
bstream
.
bitPtr
!==
0
)
bstream
.
readBits
(
1
);
while
(
bstream
.
bitPtr
!==
0
)
bstream
.
readBits
(
1
);
var
len
=
bstream
.
readBits
(
16
);
var
len
=
bstream
.
readBits
(
16
);
...
@@ -575,13 +571,11 @@ function inflate(compressedData, numDecompressedBytes) {
...
@@ -575,13 +571,11 @@ function inflate(compressedData, numDecompressedBytes) {
if
(
len
>
0
)
buffer
.
insertBytes
(
bstream
.
readBytes
(
len
));
if
(
len
>
0
)
buffer
.
insertBytes
(
bstream
.
readBytes
(
len
));
blockSize
=
len
;
blockSize
=
len
;
}
}
else
if
(
bType
===
1
)
{
// fixed Huffman codes
// fixed Huffman codes
else
if
(
bType
===
1
)
{
blockSize
=
inflateBlockData
(
bstream
,
getFixedLiteralTable
(),
getFixedDistanceTable
(),
buffer
);
blockSize
=
inflateBlockData
(
bstream
,
getFixedLiteralTable
(),
getFixedDistanceTable
(),
buffer
);
}
}
else
if
(
bType
===
2
)
{
// dynamic Huffman codes
// dynamic Huffman codes
else
if
(
bType
===
2
)
{
var
numLiteralLengthCodes
=
bstream
.
readBits
(
5
)
+
257
;
var
numLiteralLengthCodes
=
bstream
.
readBits
(
5
)
+
257
;
var
numDistanceCodes
=
bstream
.
readBits
(
5
)
+
1
,
var
numDistanceCodes
=
bstream
.
readBits
(
5
)
+
1
,
numCodeLengthCodes
=
bstream
.
readBits
(
4
)
+
4
;
numCodeLengthCodes
=
bstream
.
readBits
(
4
)
+
4
;
...
...
cps/static/js/io/bitstream.js
100644 → 100755
View file @
cd546eb6
...
@@ -8,6 +8,9 @@
...
@@ -8,6 +8,9 @@
* Copyright(c) 2011 Google Inc.
* Copyright(c) 2011 Google Inc.
* Copyright(c) 2011 antimatter15
* Copyright(c) 2011 antimatter15
*/
*/
/* global bitjs, Uint8Array */
var
bitjs
=
bitjs
||
{};
var
bitjs
=
bitjs
||
{};
bitjs
.
io
=
bitjs
.
io
||
{};
bitjs
.
io
=
bitjs
.
io
||
{};
...
@@ -30,20 +33,20 @@ bitjs.io = bitjs.io || {};
...
@@ -30,20 +33,20 @@ bitjs.io = bitjs.io || {};
* @param {ArrayBuffer} ab An ArrayBuffer object or a Uint8Array.
* @param {ArrayBuffer} ab An ArrayBuffer object or a Uint8Array.
* @param {boolean} rtl Whether the stream reads bits from the byte starting
* @param {boolean} rtl Whether the stream reads bits from the byte starting
* from bit 7 to 0 (true) or bit 0 to 7 (false).
* from bit 7 to 0 (true) or bit 0 to 7 (false).
* @param {Number} opt
_o
ffset The offset into the ArrayBuffer
* @param {Number} opt
O
ffset The offset into the ArrayBuffer
* @param {Number} opt
_l
ength The length of this BitStream
* @param {Number} opt
L
ength The length of this BitStream
*/
*/
bitjs
.
io
.
BitStream
=
function
(
ab
,
rtl
,
opt
_offset
,
opt_l
ength
)
{
bitjs
.
io
.
BitStream
=
function
(
ab
,
rtl
,
opt
Offset
,
optL
ength
)
{
if
(
!
ab
||
!
ab
.
toString
||
ab
.
toString
()
!==
"[object ArrayBuffer]"
)
{
if
(
!
ab
||
!
ab
.
toString
||
ab
.
toString
()
!==
"[object ArrayBuffer]"
)
{
throw
"Error! BitArray constructed with an invalid ArrayBuffer object"
;
throw
"Error! BitArray constructed with an invalid ArrayBuffer object"
;
}
}
var
offset
=
opt
_o
ffset
||
0
;
var
offset
=
opt
O
ffset
||
0
;
var
length
=
opt
_l
ength
||
ab
.
byteLength
;
var
length
=
opt
L
ength
||
ab
.
byteLength
;
this
.
bytes
=
new
Uint8Array
(
ab
,
offset
,
length
);
this
.
bytes
=
new
Uint8Array
(
ab
,
offset
,
length
);
this
.
bytePtr
=
0
;
// tracks which byte we are on
this
.
bytePtr
=
0
;
// tracks which byte we are on
this
.
bitPtr
=
0
;
// tracks which bit we are on (can have values 0 through 7)
this
.
bitPtr
=
0
;
// tracks which bit we are on (can have values 0 through 7)
this
.
peekBits
=
rtl
?
this
.
peekBits
_rtl
:
this
.
peekBits_l
tr
;
this
.
peekBits
=
rtl
?
this
.
peekBits
Rtl
:
this
.
peekBitsL
tr
;
};
};
...
@@ -57,8 +60,8 @@ bitjs.io = bitjs.io || {};
...
@@ -57,8 +60,8 @@ bitjs.io = bitjs.io || {};
* @param {boolean=} movePointers Whether to move the pointer, defaults false.
* @param {boolean=} movePointers Whether to move the pointer, defaults false.
* @return {number} The peeked bits, as an unsigned number.
* @return {number} The peeked bits, as an unsigned number.
*/
*/
bitjs
.
io
.
BitStream
.
prototype
.
peekBits
_l
tr
=
function
(
n
,
movePointers
)
{
bitjs
.
io
.
BitStream
.
prototype
.
peekBits
L
tr
=
function
(
n
,
movePointers
)
{
if
(
n
<=
0
||
typeof
n
!=
typeof
1
)
{
if
(
n
<=
0
||
typeof
n
!=
=
typeof
1
)
{
return
0
;
return
0
;
}
}
...
@@ -77,12 +80,13 @@ bitjs.io = bitjs.io || {};
...
@@ -77,12 +80,13 @@ bitjs.io = bitjs.io || {};
if
(
bytePtr
>=
bytes
.
length
)
{
if
(
bytePtr
>=
bytes
.
length
)
{
throw
"Error! Overflowed the bit stream! n="
+
n
+
", bytePtr="
+
bytePtr
+
", bytes.length="
+
throw
"Error! Overflowed the bit stream! n="
+
n
+
", bytePtr="
+
bytePtr
+
", bytes.length="
+
bytes
.
length
+
", bitPtr="
+
bitPtr
;
bytes
.
length
+
", bitPtr="
+
bitPtr
;
return
-
1
;
//
return -1;
}
}
var
numBitsLeftInThisByte
=
(
8
-
bitPtr
);
var
numBitsLeftInThisByte
=
(
8
-
bitPtr
);
var
mask
;
if
(
n
>=
numBitsLeftInThisByte
)
{
if
(
n
>=
numBitsLeftInThisByte
)
{
var
mask
=
(
BITMASK
[
numBitsLeftInThisByte
]
<<
bitPtr
);
mask
=
(
BITMASK
[
numBitsLeftInThisByte
]
<<
bitPtr
);
result
|=
(((
bytes
[
bytePtr
]
&
mask
)
>>
bitPtr
)
<<
bitsIn
);
result
|=
(((
bytes
[
bytePtr
]
&
mask
)
>>
bitPtr
)
<<
bitsIn
);
bytePtr
++
;
bytePtr
++
;
...
@@ -90,7 +94,7 @@ bitjs.io = bitjs.io || {};
...
@@ -90,7 +94,7 @@ bitjs.io = bitjs.io || {};
bitsIn
+=
numBitsLeftInThisByte
;
bitsIn
+=
numBitsLeftInThisByte
;
n
-=
numBitsLeftInThisByte
;
n
-=
numBitsLeftInThisByte
;
}
else
{
}
else
{
var
mask
=
(
BITMASK
[
n
]
<<
bitPtr
);
mask
=
(
BITMASK
[
n
]
<<
bitPtr
);
result
|=
(((
bytes
[
bytePtr
]
&
mask
)
>>
bitPtr
)
<<
bitsIn
);
result
|=
(((
bytes
[
bytePtr
]
&
mask
)
>>
bitPtr
)
<<
bitsIn
);
bitPtr
+=
n
;
bitPtr
+=
n
;
...
@@ -118,8 +122,8 @@ bitjs.io = bitjs.io || {};
...
@@ -118,8 +122,8 @@ bitjs.io = bitjs.io || {};
* @param {boolean=} movePointers Whether to move the pointer, defaults false.
* @param {boolean=} movePointers Whether to move the pointer, defaults false.
* @return {number} The peeked bits, as an unsigned number.
* @return {number} The peeked bits, as an unsigned number.
*/
*/
bitjs
.
io
.
BitStream
.
prototype
.
peekBits
_r
tl
=
function
(
n
,
movePointers
)
{
bitjs
.
io
.
BitStream
.
prototype
.
peekBits
R
tl
=
function
(
n
,
movePointers
)
{
if
(
n
<=
0
||
typeof
n
!=
typeof
1
)
{
if
(
n
<=
0
||
typeof
n
!=
=
typeof
1
)
{
return
0
;
return
0
;
}
}
...
@@ -138,7 +142,7 @@ bitjs.io = bitjs.io || {};
...
@@ -138,7 +142,7 @@ bitjs.io = bitjs.io || {};
if
(
bytePtr
>=
bytes
.
length
)
{
if
(
bytePtr
>=
bytes
.
length
)
{
throw
"Error! Overflowed the bit stream! n="
+
n
+
", bytePtr="
+
bytePtr
+
", bytes.length="
+
throw
"Error! Overflowed the bit stream! n="
+
n
+
", bytePtr="
+
bytePtr
+
", bytes.length="
+
bytes
.
length
+
", bitPtr="
+
bitPtr
;
bytes
.
length
+
", bitPtr="
+
bitPtr
;
return
-
1
;
//
return -1;
}
}
var
numBitsLeftInThisByte
=
(
8
-
bitPtr
);
var
numBitsLeftInThisByte
=
(
8
-
bitPtr
);
...
@@ -198,19 +202,19 @@ bitjs.io = bitjs.io || {};
...
@@ -198,19 +202,19 @@ bitjs.io = bitjs.io || {};
* @return {Uint8Array} The subarray.
* @return {Uint8Array} The subarray.
*/
*/
bitjs
.
io
.
BitStream
.
prototype
.
peekBytes
=
function
(
n
,
movePointers
)
{
bitjs
.
io
.
BitStream
.
prototype
.
peekBytes
=
function
(
n
,
movePointers
)
{
if
(
n
<=
0
||
typeof
n
!=
typeof
1
)
{
if
(
n
<=
0
||
typeof
n
!=
=
typeof
1
)
{
return
0
;
return
0
;
}
}
// from http://tools.ietf.org/html/rfc1951#page-11
// from http://tools.ietf.org/html/rfc1951#page-11
// "Any bits of input up to the next byte boundary are ignored."
// "Any bits of input up to the next byte boundary are ignored."
while
(
this
.
bitPtr
!=
0
)
{
while
(
this
.
bitPtr
!=
=
0
)
{
this
.
readBits
(
1
);
this
.
readBits
(
1
);
}
}
var
movePointers
=
movePointers
||
false
;
var
movePointers
=
movePointers
||
false
;
var
bytePtr
=
this
.
bytePtr
,
var
bytePtr
=
this
.
bytePtr
;
bitPtr
=
this
.
bitPtr
;
//
bitPtr = this.bitPtr;
var
result
=
this
.
bytes
.
subarray
(
bytePtr
,
bytePtr
+
n
);
var
result
=
this
.
bytes
.
subarray
(
bytePtr
,
bytePtr
+
n
);
...
...
cps/static/js/io/bytebuffer.js
View file @
cd546eb6
...
@@ -8,6 +8,9 @@
...
@@ -8,6 +8,9 @@
* Copyright(c) 2011 Google Inc.
* Copyright(c) 2011 Google Inc.
* Copyright(c) 2011 antimatter15
* Copyright(c) 2011 antimatter15
*/
*/
/* global bitjs, Uint8Array */
var
bitjs
=
bitjs
||
{};
var
bitjs
=
bitjs
||
{};
bitjs
.
io
=
bitjs
.
io
||
{};
bitjs
.
io
=
bitjs
.
io
||
{};
...
@@ -20,7 +23,7 @@ bitjs.io = bitjs.io || {};
...
@@ -20,7 +23,7 @@ bitjs.io = bitjs.io || {};
* @constructor
* @constructor
*/
*/
bitjs
.
io
.
ByteBuffer
=
function
(
numBytes
)
{
bitjs
.
io
.
ByteBuffer
=
function
(
numBytes
)
{
if
(
typeof
numBytes
!=
typeof
1
||
numBytes
<=
0
)
{
if
(
typeof
numBytes
!=
=
typeof
1
||
numBytes
<=
0
)
{
throw
"Error! ByteBuffer initialized with '"
+
numBytes
+
"'"
;
throw
"Error! ByteBuffer initialized with '"
+
numBytes
+
"'"
;
}
}
this
.
data
=
new
Uint8Array
(
numBytes
);
this
.
data
=
new
Uint8Array
(
numBytes
);
...
@@ -55,14 +58,14 @@ bitjs.io = bitjs.io || {};
...
@@ -55,14 +58,14 @@ bitjs.io = bitjs.io || {};
*/
*/
bitjs
.
io
.
ByteBuffer
.
prototype
.
writeNumber
=
function
(
num
,
numBytes
)
{
bitjs
.
io
.
ByteBuffer
.
prototype
.
writeNumber
=
function
(
num
,
numBytes
)
{
if
(
numBytes
<
1
)
{
if
(
numBytes
<
1
)
{
throw
'Trying to write into too few bytes: '
+
numBytes
;
throw
"Trying to write into too few bytes: "
+
numBytes
;
}
}
if
(
num
<
0
)
{
if
(
num
<
0
)
{
throw
'Trying to write a negative number ('
+
num
+
throw
"Trying to write a negative number ("
+
num
+
') as an unsigned number to an ArrayBuffer'
;
") as an unsigned number to an ArrayBuffer"
;
}
}
if
(
num
>
(
Math
.
pow
(
2
,
numBytes
*
8
)
-
1
))
{
if
(
num
>
(
Math
.
pow
(
2
,
numBytes
*
8
)
-
1
))
{
throw
'Trying to write '
+
num
+
' into only '
+
numBytes
+
' bytes'
;
throw
"Trying to write "
+
num
+
" into only "
+
numBytes
+
" bytes"
;
}
}
// Roll 8-bits at a time into an array of bytes.
// Roll 8-bits at a time into an array of bytes.
...
@@ -85,12 +88,12 @@ bitjs.io = bitjs.io || {};
...
@@ -85,12 +88,12 @@ bitjs.io = bitjs.io || {};
*/
*/
bitjs
.
io
.
ByteBuffer
.
prototype
.
writeSignedNumber
=
function
(
num
,
numBytes
)
{
bitjs
.
io
.
ByteBuffer
.
prototype
.
writeSignedNumber
=
function
(
num
,
numBytes
)
{
if
(
numBytes
<
1
)
{
if
(
numBytes
<
1
)
{
throw
'Trying to write into too few bytes: '
+
numBytes
;
throw
"Trying to write into too few bytes: "
+
numBytes
;
}
}
var
HALF
=
Math
.
pow
(
2
,
(
numBytes
*
8
)
-
1
);
var
HALF
=
Math
.
pow
(
2
,
(
numBytes
*
8
)
-
1
);
if
(
num
>=
HALF
||
num
<
-
HALF
)
{
if
(
num
>=
HALF
||
num
<
-
HALF
)
{
throw
'Trying to write '
+
num
+
' into only '
+
numBytes
+
' bytes'
;
throw
"Trying to write "
+
num
+
" into only "
+
numBytes
+
" bytes"
;
}
}
// Roll 8-bits at a time into an array of bytes.
// Roll 8-bits at a time into an array of bytes.
...
@@ -112,7 +115,7 @@ bitjs.io = bitjs.io || {};
...
@@ -112,7 +115,7 @@ bitjs.io = bitjs.io || {};
for
(
var
i
=
0
;
i
<
str
.
length
;
++
i
)
{
for
(
var
i
=
0
;
i
<
str
.
length
;
++
i
)
{
var
curByte
=
str
.
charCodeAt
(
i
);
var
curByte
=
str
.
charCodeAt
(
i
);
if
(
curByte
<
0
||
curByte
>
255
)
{
if
(
curByte
<
0
||
curByte
>
255
)
{
throw
'Trying to write a non-ASCII string!'
;
throw
"Trying to write a non-ASCII string!"
;
}
}
this
.
insertByte
(
curByte
);
this
.
insertByte
(
curByte
);
}
}
...
...
cps/static/js/io/bytestream.js
View file @
cd546eb6
...
@@ -8,6 +8,9 @@
...
@@ -8,6 +8,9 @@
* Copyright(c) 2011 Google Inc.
* Copyright(c) 2011 Google Inc.
* Copyright(c) 2011 antimatter15
* Copyright(c) 2011 antimatter15
*/
*/
/* global bitjs, Uint8Array */
var
bitjs
=
bitjs
||
{};
var
bitjs
=
bitjs
||
{};
bitjs
.
io
=
bitjs
.
io
||
{};
bitjs
.
io
=
bitjs
.
io
||
{};
...
@@ -19,13 +22,13 @@ bitjs.io = bitjs.io || {};
...
@@ -19,13 +22,13 @@ bitjs.io = bitjs.io || {};
* out of an ArrayBuffer. In this buffer, everything must be byte-aligned.
* out of an ArrayBuffer. In this buffer, everything must be byte-aligned.
*
*
* @param {ArrayBuffer} ab The ArrayBuffer object.
* @param {ArrayBuffer} ab The ArrayBuffer object.
* @param {number=} opt
_o
ffset The offset into the ArrayBuffer
* @param {number=} opt
O
ffset The offset into the ArrayBuffer
* @param {number=} opt
_l
ength The length of this BitStream
* @param {number=} opt
L
ength The length of this BitStream
* @constructor
* @constructor
*/
*/
bitjs
.
io
.
ByteStream
=
function
(
ab
,
opt
_offset
,
opt_l
ength
)
{
bitjs
.
io
.
ByteStream
=
function
(
ab
,
opt
Offset
,
optL
ength
)
{
var
offset
=
opt
_o
ffset
||
0
;
var
offset
=
opt
O
ffset
||
0
;
var
length
=
opt
_l
ength
||
ab
.
byteLength
;
var
length
=
opt
L
ength
||
ab
.
byteLength
;
this
.
bytes
=
new
Uint8Array
(
ab
,
offset
,
length
);
this
.
bytes
=
new
Uint8Array
(
ab
,
offset
,
length
);
this
.
ptr
=
0
;
this
.
ptr
=
0
;
};
};
...
@@ -40,8 +43,9 @@ bitjs.io = bitjs.io || {};
...
@@ -40,8 +43,9 @@ bitjs.io = bitjs.io || {};
*/
*/
bitjs
.
io
.
ByteStream
.
prototype
.
peekNumber
=
function
(
n
)
{
bitjs
.
io
.
ByteStream
.
prototype
.
peekNumber
=
function
(
n
)
{
// TODO: return error if n would go past the end of the stream?
// TODO: return error if n would go past the end of the stream?
if
(
n
<=
0
||
typeof
n
!=
typeof
1
)
if
(
n
<=
0
||
typeof
n
!=
=
typeof
1
)
{
return
-
1
;
return
-
1
;
}
var
result
=
0
;
var
result
=
0
;
// read from last byte to first byte and roll them in
// read from last byte to first byte and roll them in
...
@@ -105,7 +109,7 @@ bitjs.io = bitjs.io || {};
...
@@ -105,7 +109,7 @@ bitjs.io = bitjs.io || {};
* @return {Uint8Array} The subarray.
* @return {Uint8Array} The subarray.
*/
*/
bitjs
.
io
.
ByteStream
.
prototype
.
peekBytes
=
function
(
n
,
movePointers
)
{
bitjs
.
io
.
ByteStream
.
prototype
.
peekBytes
=
function
(
n
,
movePointers
)
{
if
(
n
<=
0
||
typeof
n
!=
typeof
1
)
{
if
(
n
<=
0
||
typeof
n
!=
=
typeof
1
)
{
return
null
;
return
null
;
}
}
...
@@ -135,7 +139,7 @@ bitjs.io = bitjs.io || {};
...
@@ -135,7 +139,7 @@ bitjs.io = bitjs.io || {};
* @return {string} The next n bytes as a string.
* @return {string} The next n bytes as a string.
*/
*/
bitjs
.
io
.
ByteStream
.
prototype
.
peekString
=
function
(
n
)
{
bitjs
.
io
.
ByteStream
.
prototype
.
peekString
=
function
(
n
)
{
if
(
n
<=
0
||
typeof
n
!=
typeof
1
)
{
if
(
n
<=
0
||
typeof
n
!=
=
typeof
1
)
{
return
""
;
return
""
;
}
}
...
...
cps/static/js/kthoom.js
View file @
cd546eb6
...
@@ -15,7 +15,10 @@
...
@@ -15,7 +15,10 @@
* Typed Arrays: http://www.khronos.org/registry/typedarray/specs/latest/#6
* Typed Arrays: http://www.khronos.org/registry/typedarray/specs/latest/#6
*/
*/
/* global screenfull, bitjs */
/* global screenfull, bitjs, Uint8Array, opera */
/* exported init, event */
if
(
window
.
opera
)
{
if
(
window
.
opera
)
{
window
.
console
.
log
=
function
(
str
)
{
window
.
console
.
log
=
function
(
str
)
{
opera
.
postError
(
str
);
opera
.
postError
(
str
);
...
@@ -101,12 +104,12 @@ kthoom.setSettings = function() {
...
@@ -101,12 +104,12 @@ kthoom.setSettings = function() {
var
createURLFromArray
=
function
(
array
,
mimeType
)
{
var
createURLFromArray
=
function
(
array
,
mimeType
)
{
var
offset
=
array
.
byteOffset
;
var
offset
=
array
.
byteOffset
;
var
len
=
array
.
byteLength
;
var
len
=
array
.
byteLength
;
var
url
;
//
var url;
var
blob
;
var
blob
;
if
(
mimeType
===
'image/xml+svg'
)
{
if
(
mimeType
===
"image/xml+svg"
)
{
const
xmlStr
=
new
TextDecoder
(
'utf-8'
).
decode
(
array
);
var
xmlStr
=
new
TextDecoder
(
"utf-8"
).
decode
(
array
);
return
'data:image/svg+xml;UTF-8,'
+
encodeURIComponent
(
xmlStr
);
return
"data:image/svg+xml;UTF-8,"
+
encodeURIComponent
(
xmlStr
);
}
}
// TODO: Move all this browser support testing to a common place
// TODO: Move all this browser support testing to a common place
...
@@ -140,7 +143,7 @@ kthoom.ImageFile = function(file) {
...
@@ -140,7 +143,7 @@ kthoom.ImageFile = function(file) {
var
fileExtension
=
file
.
filename
.
split
(
"."
).
pop
().
toLowerCase
();
var
fileExtension
=
file
.
filename
.
split
(
"."
).
pop
().
toLowerCase
();
this
.
mimeType
=
fileExtension
===
"png"
?
"image/png"
:
this
.
mimeType
=
fileExtension
===
"png"
?
"image/png"
:
(
fileExtension
===
"jpg"
||
fileExtension
===
"jpeg"
)
?
"image/jpeg"
:
(
fileExtension
===
"jpg"
||
fileExtension
===
"jpeg"
)
?
"image/jpeg"
:
fileExtension
===
"gif"
?
"image/gif"
:
fileExtension
==
'svg'
?
'image/xml+svg'
:
undefined
;
fileExtension
===
"gif"
?
"image/gif"
:
fileExtension
==
=
"svg"
?
"image/xml+svg"
:
undefined
;
if
(
this
.
mimeType
!==
undefined
)
{
if
(
this
.
mimeType
!==
undefined
)
{
this
.
dataURI
=
createURLFromArray
(
file
.
fileData
,
this
.
mimeType
);
this
.
dataURI
=
createURLFromArray
(
file
.
fileData
,
this
.
mimeType
);
this
.
data
=
file
;
this
.
data
=
file
;
...
@@ -154,17 +157,18 @@ function initProgressClick() {
...
@@ -154,17 +157,18 @@ function initProgressClick() {
currentImage
=
page
;
currentImage
=
page
;
updatePage
();
updatePage
();
});
});
}
;
}
function
loadFromArrayBuffer
(
ab
)
{
function
loadFromArrayBuffer
(
ab
)
{
var
start
=
(
new
Date
).
getTime
();
var
start
=
(
new
Date
).
getTime
();
var
h
=
new
Uint8Array
(
ab
,
0
,
10
);
var
h
=
new
Uint8Array
(
ab
,
0
,
10
);
var
pathToBitJS
=
"../../static/js/archive/"
;
var
pathToBitJS
=
"../../static/js/archive/"
;
var
lastCompletion
=
0
;
if
(
h
[
0
]
===
0x52
&&
h
[
1
]
===
0x61
&&
h
[
2
]
===
0x72
&&
h
[
3
]
===
0x21
)
{
//Rar!
if
(
h
[
0
]
===
0x52
&&
h
[
1
]
===
0x61
&&
h
[
2
]
===
0x72
&&
h
[
3
]
===
0x21
)
{
//Rar!
unarchiver
=
new
bitjs
.
archive
.
Unrarrer
(
ab
,
pathToBitJS
);
unarchiver
=
new
bitjs
.
archive
.
Unrarrer
(
ab
,
pathToBitJS
);
}
else
if
(
h
[
0
]
===
80
&&
h
[
1
]
===
75
)
{
//PK (Zip)
}
else
if
(
h
[
0
]
===
80
&&
h
[
1
]
===
75
)
{
//PK (Zip)
unarchiver
=
new
bitjs
.
archive
.
Unzipper
(
ab
,
pathToBitJS
);
unarchiver
=
new
bitjs
.
archive
.
Unzipper
(
ab
,
pathToBitJS
);
}
else
if
(
h
[
0
]
==
255
&&
h
[
1
]
==
216
)
{
// JPEG
}
else
if
(
h
[
0
]
==
=
255
&&
h
[
1
]
=
==
216
)
{
// JPEG
// ToDo: check
// ToDo: check
updateProgress
(
100
);
updateProgress
(
100
);
lastCompletion
=
100
;
lastCompletion
=
100
;
...
@@ -180,12 +184,12 @@ function loadFromArrayBuffer(ab) {
...
@@ -180,12 +184,12 @@ function loadFromArrayBuffer(ab) {
if
(
totalImages
===
0
)
{
if
(
totalImages
===
0
)
{
totalImages
=
e
.
totalFilesInArchive
;
totalImages
=
e
.
totalFilesInArchive
;
}
}
updateProgress
(
percentage
*
100
);
updateProgress
(
percentage
*
100
);
lastCompletion
=
percentage
*
100
;
lastCompletion
=
percentage
*
100
;
});
});
unarchiver
.
addEventListener
(
bitjs
.
archive
.
UnarchiveEvent
.
Type
.
INFO
,
unarchiver
.
addEventListener
(
bitjs
.
archive
.
UnarchiveEvent
.
Type
.
INFO
,
function
(
e
)
{
function
(
e
)
{
// console.log(e.msg);
77
Enable debug output here
// console.log(e.msg);
//
Enable debug output here
});
});
unarchiver
.
addEventListener
(
bitjs
.
archive
.
UnarchiveEvent
.
Type
.
EXTRACT
,
unarchiver
.
addEventListener
(
bitjs
.
archive
.
UnarchiveEvent
.
Type
.
EXTRACT
,
function
(
e
)
{
function
(
e
)
{
...
@@ -211,8 +215,7 @@ function loadFromArrayBuffer(ab) {
...
@@ -211,8 +215,7 @@ function loadFromArrayBuffer(ab) {
if
(
imageFiles
.
length
===
currentImage
+
1
)
{
if
(
imageFiles
.
length
===
currentImage
+
1
)
{
updatePage
(
lastCompletion
);
updatePage
(
lastCompletion
);
}
}
}
}
else
{
else
{
totalImages
--
;
totalImages
--
;
}
}
}
}
...
@@ -231,22 +234,22 @@ function loadFromArrayBuffer(ab) {
...
@@ -231,22 +234,22 @@ function loadFromArrayBuffer(ab) {
function
scrollTocToActive
()
{
function
scrollTocToActive
()
{
// Scroll to the thumbnail in the TOC on page change
// Scroll to the thumbnail in the TOC on page change
$
(
'#tocView'
).
stop
().
animate
({
$
(
"#tocView"
).
stop
().
animate
({
scrollTop
:
$
(
'#tocView a.active'
).
position
().
top
scrollTop
:
$
(
"#tocView a.active"
).
position
().
top
},
200
);
},
200
);
}
}
function
updatePage
()
{
function
updatePage
()
{
$
(
'.page'
).
text
((
currentImage
+
1
)
+
"/"
+
totalImages
);
$
(
".page"
).
text
((
currentImage
+
1
)
+
"/"
+
totalImages
);
// Mark the current page in the TOC
// Mark the current page in the TOC
$
(
'#tocView a[data-page]'
)
$
(
"#tocView a[data-page]"
)
// Remove the currently active thumbnail
// Remove the currently active thumbnail
.
removeClass
(
'active'
)
.
removeClass
(
"active"
)
// Find the new one
// Find the new one
.
filter
(
'[data-page='
+
(
currentImage
+
1
)
+
']'
)
.
filter
(
"[data-page="
+
(
currentImage
+
1
)
+
"]"
)
// Set it to active
// Set it to active
.
addClass
(
'active'
);
.
addClass
(
"active"
);
scrollTocToActive
();
scrollTocToActive
();
updateProgress
();
updateProgress
();
...
@@ -270,8 +273,8 @@ function updateProgress(loadPercentage) {
...
@@ -270,8 +273,8 @@ function updateProgress(loadPercentage) {
if
(
loadPercentage
===
100
)
{
if
(
loadPercentage
===
100
)
{
$
(
"#progress"
)
$
(
"#progress"
)
.
removeClass
(
'loading'
)
.
removeClass
(
"loading"
)
.
find
(
".load"
).
text
(
''
);
.
find
(
".load"
).
text
(
""
);
}
}
}
}
...
@@ -326,7 +329,7 @@ function setImage(url) {
...
@@ -326,7 +329,7 @@ function setImage(url) {
xhr
.
onload
=
function
()
{
xhr
.
onload
=
function
()
{
$
(
"#mainText"
).
css
(
"display"
,
""
);
$
(
"#mainText"
).
css
(
"display"
,
""
);
$
(
"#mainText"
).
innerHTML
(
"<iframe style=
\"
width:100%;height:700px;border:0
\"
src=
\"
data:text/html,"
+
escape
(
xhr
.
responseText
)
+
"
\"
></iframe>"
);
$
(
"#mainText"
).
innerHTML
(
"<iframe style=
\"
width:100%;height:700px;border:0
\"
src=
\"
data:text/html,"
+
escape
(
xhr
.
responseText
)
+
"
\"
></iframe>"
);
}
}
;
xhr
.
send
(
null
);
xhr
.
send
(
null
);
}
else
if
(
!
/
(
jpg|jpeg|png|gif
)
$/
.
test
(
imageFiles
[
currentImage
].
filename
)
&&
imageFiles
[
currentImage
].
data
.
uncompressedSize
<
10
*
1024
)
{
}
else
if
(
!
/
(
jpg|jpeg|png|gif
)
$/
.
test
(
imageFiles
[
currentImage
].
filename
)
&&
imageFiles
[
currentImage
].
data
.
uncompressedSize
<
10
*
1024
)
{
xhr
.
open
(
"GET"
,
url
,
true
);
xhr
.
open
(
"GET"
,
url
,
true
);
...
@@ -378,17 +381,17 @@ function setImage(url) {
...
@@ -378,17 +381,17 @@ function setImage(url) {
function
showLeftPage
()
{
function
showLeftPage
()
{
if
(
settings
.
direction
===
0
)
{
if
(
settings
.
direction
===
0
)
{
showPrevPage
()
showPrevPage
()
;
}
else
{
}
else
{
showNextPage
()
showNextPage
()
;
}
}
}
}
function
showRightPage
()
{
function
showRightPage
()
{
if
(
settings
.
direction
===
0
)
{
if
(
settings
.
direction
===
0
)
{
showNextPage
()
showNextPage
()
;
}
else
{
}
else
{
showPrevPage
()
showPrevPage
()
;
}
}
}
}
...
@@ -504,7 +507,7 @@ function keyHandler(evt) {
...
@@ -504,7 +507,7 @@ function keyHandler(evt) {
updateScale
(
false
);
updateScale
(
false
);
break
;
break
;
case
kthoom
.
Key
.
SPACE
:
case
kthoom
.
Key
.
SPACE
:
var
container
=
$
(
'#mainContent'
);
var
container
=
$
(
"#mainContent"
);
var
atTop
=
container
.
scrollTop
()
===
0
;
var
atTop
=
container
.
scrollTop
()
===
0
;
var
atBottom
=
container
.
scrollTop
()
>=
container
[
0
].
scrollHeight
-
container
.
height
();
var
atBottom
=
container
.
scrollTop
()
>=
container
[
0
].
scrollHeight
-
container
.
height
();
...
@@ -577,9 +580,9 @@ function init(filename) {
...
@@ -577,9 +580,9 @@ function init(filename) {
$
(
this
).
toggleClass
(
"icon-menu icon-right"
);
$
(
this
).
toggleClass
(
"icon-menu icon-right"
);
// We need this in a timeout because if we call it during the CSS transition, IE11 shakes the page ¯\_(ツ)_/¯
// We need this in a timeout because if we call it during the CSS transition, IE11 shakes the page ¯\_(ツ)_/¯
setTimeout
(
function
(){
setTimeout
(
function
()
{
// Focus on the TOC or the main content area, depending on which is open
// Focus on the TOC or the main content area, depending on which is open
$
(
'#main:not(.closed) #mainContent, #sidebar.open #tocView'
).
focus
();
$
(
"#main:not(.closed) #mainContent, #sidebar.open #tocView"
).
focus
();
scrollTocToActive
();
scrollTocToActive
();
},
500
);
},
500
);
});
});
...
@@ -630,7 +633,7 @@ function init(filename) {
...
@@ -630,7 +633,7 @@ function init(filename) {
}
}
// Focus the scrollable area so that keyboard scrolling work as expected
// Focus the scrollable area so that keyboard scrolling work as expected
$
(
'#mainContent'
).
focus
();
$
(
"#mainContent"
).
focus
();
$
(
"#mainImage"
).
click
(
function
(
evt
)
{
$
(
"#mainImage"
).
click
(
function
(
evt
)
{
// Firefox does not support offsetX/Y so we have to manually calculate
// Firefox does not support offsetX/Y so we have to manually calculate
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment