mirror of
https://github.com/janeczku/calibre-web
synced 2024-11-19 08:14:53 +00:00
Code cosmetics
Bugfix "Error load settings"
This commit is contained in:
parent
378a0ca662
commit
0405cec4ac
@ -30,20 +30,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_offset The offset into the ArrayBuffer
|
* @param {Number} optOffset The offset into the ArrayBuffer
|
||||||
* @param {Number} opt_length The length of this BitStream
|
* @param {Number} optLength The length of this BitStream
|
||||||
*/
|
*/
|
||||||
bitjs.io.BitStream = function(ab, rtl, opt_offset, opt_length) {
|
bitjs.io.BitStream = function(ab, rtl, optOffset, optLength) {
|
||||||
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_offset || 0;
|
var offset = optOffset || 0;
|
||||||
var length = opt_length || ab.byteLength;
|
var length = optLength || 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_ltr;
|
this.peekBits = rtl ? this.peekBitsRtl : this.peekBitsLtr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -57,12 +57,12 @@ 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_ltr = function(n, movePointers) {
|
bitjs.io.BitStream.prototype.peekBitsLtr = function(n, movePointers) {
|
||||||
if (n <= 0 || typeof n != typeof 1) {
|
if (n <= 0 || typeof n != typeof 1) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
var movePointers = movePointers || false,
|
movePointers = movePointers || false,
|
||||||
bytePtr = this.bytePtr,
|
bytePtr = this.bytePtr,
|
||||||
bitPtr = this.bitPtr,
|
bitPtr = this.bitPtr,
|
||||||
result = 0,
|
result = 0,
|
||||||
@ -77,21 +77,20 @@ 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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++;
|
||||||
bitPtr = 0;
|
bitPtr = 0;
|
||||||
bitsIn += numBitsLeftInThisByte;
|
bitsIn += numBitsLeftInThisByte;
|
||||||
n -= numBitsLeftInThisByte;
|
n -= numBitsLeftInThisByte;
|
||||||
}
|
} else {
|
||||||
else {
|
mask = (BITMASK[n] << bitPtr);
|
||||||
var mask = (BITMASK[n] << bitPtr);
|
|
||||||
result |= (((bytes[bytePtr] & mask) >> bitPtr) << bitsIn);
|
result |= (((bytes[bytePtr] & mask) >> bitPtr) << bitsIn);
|
||||||
|
|
||||||
bitPtr += n;
|
bitPtr += n;
|
||||||
@ -119,7 +118,7 @@ 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_rtl = function(n, movePointers) {
|
bitjs.io.BitStream.prototype.peekBitsRtl = function(n, movePointers) {
|
||||||
if (n <= 0 || typeof n != typeof 1) {
|
if (n <= 0 || typeof n != typeof 1) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -173,8 +172,8 @@ bitjs.io = bitjs.io || {};
|
|||||||
*/
|
*/
|
||||||
bitjs.io.BitStream.prototype.getBits = function() {
|
bitjs.io.BitStream.prototype.getBits = function() {
|
||||||
return (((((this.bytes[this.bytePtr] & 0xff) << 16) +
|
return (((((this.bytes[this.bytePtr] & 0xff) << 16) +
|
||||||
((this.bytes[this.bytePtr+1] & 0xff) << 8) +
|
((this.bytes[this.bytePtr + 1] & 0xff) << 8) +
|
||||||
((this.bytes[this.bytePtr+2] & 0xff))) >>> (8-this.bitPtr)) & 0xffff);
|
((this.bytes[this.bytePtr + 2] & 0xff))) >>> (8 - this.bitPtr)) & 0xffff);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -203,11 +202,11 @@ bitjs.io = bitjs.io || {};
|
|||||||
|
|
||||||
// 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;
|
movePointers = movePointers || false;
|
||||||
var bytePtr = this.bytePtr,
|
var bytePtr = this.bytePtr,
|
||||||
bitPtr = this.bitPtr;
|
bitPtr = this.bitPtr;
|
||||||
|
|
||||||
@ -235,13 +234,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_offset The offset into the ArrayBuffer
|
* @param {number=} optOffset The offset into the ArrayBuffer
|
||||||
* @param {number=} opt_length The length of this BitStream
|
* @param {number=} optLength The length of this BitStream
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
bitjs.io.ByteStream = function(ab, opt_offset, opt_length) {
|
bitjs.io.ByteStream = function(ab, optOffset, optLength) {
|
||||||
var offset = opt_offset || 0;
|
var offset = optOffset || 0;
|
||||||
var length = opt_length || ab.byteLength;
|
var length = optLength || ab.byteLength;
|
||||||
this.bytes = new Uint8Array(ab, offset, length);
|
this.bytes = new Uint8Array(ab, offset, length);
|
||||||
this.ptr = 0;
|
this.ptr = 0;
|
||||||
};
|
};
|
||||||
@ -256,8 +255,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
|
||||||
@ -382,7 +382,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);
|
||||||
@ -447,12 +447,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.
|
||||||
@ -474,7 +474,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);
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
* Typed Arrays: http://www.khronos.org/registry/typedarray/specs/latest/#6
|
* Typed Arrays: http://www.khronos.org/registry/typedarray/specs/latest/#6
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
/* global bitjs */
|
||||||
|
|
||||||
if (window.opera) {
|
if (window.opera) {
|
||||||
window.console.log = function(str) {
|
window.console.log = function(str) {
|
||||||
@ -77,7 +78,8 @@ kthoom.saveSettings = function() {
|
|||||||
|
|
||||||
kthoom.loadSettings = function() {
|
kthoom.loadSettings = function() {
|
||||||
try {
|
try {
|
||||||
if (localStorage.kthoomSettings.length < 10) return;
|
if (localStorage.kthoomSettings.length < 10)
|
||||||
|
return;
|
||||||
var s = JSON.parse(localStorage.kthoomSettings);
|
var s = JSON.parse(localStorage.kthoomSettings);
|
||||||
kthoom.rotateTimes = s.rotateTimes;
|
kthoom.rotateTimes = s.rotateTimes;
|
||||||
hflip = s.hflip;
|
hflip = s.hflip;
|
||||||
@ -86,31 +88,31 @@ kthoom.loadSettings = function() {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert("Error load settings");
|
alert("Error load settings");
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
var createURLFromArray = function(array, mimeType) {
|
var createURLFromArray = function(array, mimeType) {
|
||||||
var offset = array.byteOffset, len = array.byteLength;
|
var offset = array.byteOffset, len = array.byteLength;
|
||||||
var bb, url;
|
var url;
|
||||||
var blob;
|
var blob;
|
||||||
|
|
||||||
// TODO: Move all this browser support testing to a common place
|
// TODO: Move all this browser support testing to a common place
|
||||||
// and do it just once.
|
// and do it just once.
|
||||||
|
|
||||||
// Blob constructor, see http://dev.w3.org/2006/webapi/FileAPI/#dfn-Blob.
|
// Blob constructor, see http://dev.w3.org/2006/webapi/FileAPI/#dfn-Blob.
|
||||||
if (typeof Blob == "function") {
|
if (typeof Blob === "function") {
|
||||||
blob = new Blob([array], {type: mimeType});
|
blob = new Blob([array], {type: mimeType});
|
||||||
} else {
|
} else {
|
||||||
throw "Browser support for Blobs is missing."
|
throw "Browser support for Blobs is missing.";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blob.slice) {
|
if (blob.slice) {
|
||||||
blob = blob.slice(offset, offset + len, mimeType);
|
blob = blob.slice(offset, offset + len, mimeType);
|
||||||
} else {
|
} else {
|
||||||
throw "Browser support for Blobs is missing."
|
throw "Browser support for Blobs is missing.";
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((typeof URL != "function" && typeof URL != "object") ||
|
if ((typeof URL !== "function" && typeof URL != "object") ||
|
||||||
typeof URL.createObjectURL != "function") {
|
typeof URL.createObjectURL !== "function") {
|
||||||
throw "Browser support for Object URLs is missing";
|
throw "Browser support for Object URLs is missing";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +219,7 @@ kthoom.initProgressMeter = function() {
|
|||||||
|
|
||||||
svg.appendChild(g);
|
svg.appendChild(g);
|
||||||
pdiv.appendChild(svg);
|
pdiv.appendChild(svg);
|
||||||
|
var l;
|
||||||
svg.onclick = function(e) {
|
svg.onclick = function(e) {
|
||||||
for (var x = pdiv, l = 0; x !== document.documentElement; x = x.parentNode) l += x.offsetLeft;
|
for (var x = pdiv, l = 0; x !== document.documentElement; x = x.parentNode) l += x.offsetLeft;
|
||||||
var page = Math.max(1, Math.ceil(((e.clientX - l) / pdiv.offsetWidth) * totalImages)) - 1;
|
var page = Math.max(1, Math.ceil(((e.clientX - l) / pdiv.offsetWidth) * totalImages)) - 1;
|
||||||
@ -231,7 +233,7 @@ kthoom.setProgressMeter = function(pct, optLabel) {
|
|||||||
var part = 1 / totalImages;
|
var part = 1 / totalImages;
|
||||||
var remain = ((pct - lastCompletion) / 100) / part;
|
var remain = ((pct - lastCompletion) / 100) / part;
|
||||||
var fract = Math.min(1, remain);
|
var fract = Math.min(1, remain);
|
||||||
var smartpct = ((imageFiles.length / totalImages) + (fract * part))* 100;
|
var smartpct = ((imageFiles.length / totalImages) + (fract * part)) * 100;
|
||||||
if (totalImages === 0) smartpct = pct;
|
if (totalImages === 0) smartpct = pct;
|
||||||
|
|
||||||
// + Math.min((pct - lastCompletion), 100/totalImages * 0.9 + (pct - lastCompletion - 100/totalImages)/2, 100/totalImages);
|
// + Math.min((pct - lastCompletion), 100/totalImages * 0.9 + (pct - lastCompletion - 100/totalImages)/2, 100/totalImages);
|
||||||
@ -239,7 +241,7 @@ kthoom.setProgressMeter = function(pct, optLabel) {
|
|||||||
if (isNaN(oldval)) oldval = 0;
|
if (isNaN(oldval)) oldval = 0;
|
||||||
var weight = 0.5;
|
var weight = 0.5;
|
||||||
smartpct = ((weight * smartpct) + ((1 - weight) * oldval));
|
smartpct = ((weight * smartpct) + ((1 - weight) * oldval));
|
||||||
if (pct == 100) smartpct = 100;
|
if (pct === 100) smartpct = 100;
|
||||||
|
|
||||||
if (!isNaN(smartpct)) {
|
if (!isNaN(smartpct)) {
|
||||||
getElem("meter").setAttribute("width", smartpct + "%");
|
getElem("meter").setAttribute("width", smartpct + "%");
|
||||||
@ -254,15 +256,15 @@ kthoom.setProgressMeter = function(pct, optLabel) {
|
|||||||
title.appendChild(document.createTextNode(labelText));
|
title.appendChild(document.createTextNode(labelText));
|
||||||
|
|
||||||
getElem("meter2").setAttribute("width",
|
getElem("meter2").setAttribute("width",
|
||||||
100 * (totalImages == 0 ? 0 : ((currentImage+1) / totalImages)) + "%");
|
100 * (totalImages === 0 ? 0 : ((currentImage + 1) / totalImages)) + "%");
|
||||||
|
|
||||||
var title = getElem("page");
|
var titlePage = getElem("page");
|
||||||
while (title.firstChild) title.removeChild(title.firstChild);
|
while (titlePage.firstChild) titlePage.removeChild(titlePage.firstChild);
|
||||||
title.appendChild(document.createTextNode( (currentImage+1) + '/' + totalImages ));
|
titlePage.appendChild(document.createTextNode( (currentImage + 1) + "/" + totalImages ));
|
||||||
|
|
||||||
if (pct > 0) {
|
if (pct > 0) {
|
||||||
//getElem('nav').className = '';
|
//getElem('nav').className = '';
|
||||||
getElem("progress").className = '';
|
getElem("progress").className = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,9 +272,9 @@ 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/";
|
var pathToBitJS = "../../static/js/";
|
||||||
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
|
||||||
unarchiver = new bitjs.archive.Untarrer(ab, pathToBitJS);
|
unarchiver = new bitjs.archive.Untarrer(ab, pathToBitJS);
|
||||||
@ -293,7 +295,7 @@ function loadFromArrayBuffer(ab) {
|
|||||||
if (e.unarchivedFile) {
|
if (e.unarchivedFile) {
|
||||||
var f = e.unarchivedFile;
|
var f = e.unarchivedFile;
|
||||||
// add any new pages based on the filename
|
// add any new pages based on the filename
|
||||||
if (imageFilenames.indexOf(f.filename) == -1) {
|
if (imageFilenames.indexOf(f.filename) === -1) {
|
||||||
imageFilenames.push(f.filename);
|
imageFilenames.push(f.filename);
|
||||||
imageFiles.push(new kthoom.ImageFile(f));
|
imageFiles.push(new kthoom.ImageFile(f));
|
||||||
}
|
}
|
||||||
@ -304,8 +306,8 @@ function loadFromArrayBuffer(ab) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.FINISH,
|
unarchiver.addEventListener(bitjs.archive.UnarchiveEvent.Type.FINISH,
|
||||||
function(e) {
|
function() {
|
||||||
var diff = ((new Date).getTime() - start)/1000;
|
var diff = ((new Date).getTime() - start) / 1000;
|
||||||
console.log("Unarchiving done in " + diff + "s");
|
console.log("Unarchiving done in " + diff + "s");
|
||||||
});
|
});
|
||||||
unarchiver.start();
|
unarchiver.start();
|
||||||
@ -318,10 +320,10 @@ function loadFromArrayBuffer(ab) {
|
|||||||
function updatePage() {
|
function updatePage() {
|
||||||
var title = getElem("page");
|
var title = getElem("page");
|
||||||
while (title.firstChild) title.removeChild(title.firstChild);
|
while (title.firstChild) title.removeChild(title.firstChild);
|
||||||
title.appendChild(document.createTextNode( (currentImage+1) + "/" + totalImages ));
|
title.appendChild(document.createTextNode( (currentImage +1 ) + "/" + totalImages ));
|
||||||
|
|
||||||
getElem('meter2').setAttribute('width',
|
getElem("meter2").setAttribute("width",
|
||||||
100 * (totalImages == 0 ? 0 : ((currentImage+1)/totalImages)) + "%");
|
100 * (totalImages == 0 ? 0 : ((currentImage +1 ) / totalImages)) + "%");
|
||||||
if (imageFiles[currentImage]) {
|
if (imageFiles[currentImage]) {
|
||||||
setImage(imageFiles[currentImage].dataURI);
|
setImage(imageFiles[currentImage].dataURI);
|
||||||
} else {
|
} else {
|
||||||
@ -333,43 +335,42 @@ function setImage(url) {
|
|||||||
var canvas = $("#mainImage")[0];
|
var canvas = $("#mainImage")[0];
|
||||||
var x = $("#mainImage")[0].getContext("2d");
|
var x = $("#mainImage")[0].getContext("2d");
|
||||||
$("#mainText").hide();
|
$("#mainText").hide();
|
||||||
if (url == "loading") {
|
if (url === "loading") {
|
||||||
updateScale(true);
|
updateScale(true);
|
||||||
canvas.width = innerWidth - 100;
|
canvas.width = innerWidth - 100;
|
||||||
canvas.height = 200;
|
canvas.height = 200;
|
||||||
x.fillStyle = "red";
|
x.fillStyle = "red";
|
||||||
x.font = "50px sans-serif";
|
x.font = "50px sans-serif";
|
||||||
x.strokeStyle = "black";
|
x.strokeStyle = "black";
|
||||||
x.fillText("Loading Page #" + (currentImage + 1), 100, 100)
|
x.fillText("Loading Page #" + (currentImage + 1), 100, 100);
|
||||||
} else {
|
} else {
|
||||||
if ($("body").css("scrollHeight")/innerHeight > 1) {
|
if ($("body").css("scrollHeight")/innerHeight > 1) {
|
||||||
$("body").css("overflowY", "scroll");
|
$("body").css("overflowY", "scroll");
|
||||||
}
|
}
|
||||||
|
|
||||||
var img = new Image();
|
var img = new Image();
|
||||||
img.onerror = function(e) {
|
img.onerror = function() {
|
||||||
canvas.width = innerWidth - 100;
|
canvas.width = innerWidth - 100;
|
||||||
canvas.height = 300;
|
canvas.height = 300;
|
||||||
updateScale(true);
|
updateScale(true);
|
||||||
x.fillStyle = "orange";
|
x.fillStyle = "orange";
|
||||||
x.font = "50px sans-serif";
|
x.font = "50px sans-serif";
|
||||||
x.strokeStyle = "black";
|
x.strokeStyle = "black";
|
||||||
x.fillText("Page #" + (currentImage+1) + " (" +
|
x.fillText("Page #" + (currentImage + 1) + " (" +
|
||||||
imageFiles[currentImage].filename + ")", 100, 100)
|
imageFiles[currentImage].filename + ")", 100, 100);
|
||||||
x.fillStyle = "red";
|
x.fillStyle = "red";
|
||||||
x.fillText("Is corrupt or not an image", 100, 200);
|
x.fillText("Is corrupt or not an image", 100, 200);
|
||||||
|
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
if (/(html|htm)$/.test(imageFiles[currentImage].filename)) {
|
if (/(html|htm)$/.test(imageFiles[currentImage].filename)) {
|
||||||
var xhr = new XMLHttpRequest();
|
|
||||||
xhr.open("GET", url, true);
|
xhr.open("GET", url, true);
|
||||||
xhr.onload = function() {
|
xhr.onload = function() {
|
||||||
//document.getElementById('mainText').style.display = '';
|
//document.getElementById('mainText').style.display = '';
|
||||||
$("#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) {
|
||||||
var xhr = new XMLHttpRequest();
|
|
||||||
xhr.open("GET", url, true);
|
xhr.open("GET", url, true);
|
||||||
xhr.onload = function() {
|
xhr.onload = function() {
|
||||||
$("#mainText").css("display", "");
|
$("#mainText").css("display", "");
|
||||||
@ -392,20 +393,20 @@ function setImage(url) {
|
|||||||
x.rotate(Math.PI/2 * kthoom.rotateTimes);
|
x.rotate(Math.PI/2 * kthoom.rotateTimes);
|
||||||
x.translate(-w/2, -h/2);
|
x.translate(-w/2, -h/2);
|
||||||
if (vflip) {
|
if (vflip) {
|
||||||
x.scale(1, -1)
|
x.scale(1, -1);
|
||||||
x.translate(0, -h);
|
x.translate(0, -h);
|
||||||
}
|
}
|
||||||
if (hflip) {
|
if (hflip) {
|
||||||
x.scale(-1, 1)
|
x.scale(-1, 1);
|
||||||
x.translate(-w, 0);
|
x.translate(-w, 0);
|
||||||
}
|
}
|
||||||
canvas.style.display = "none";
|
canvas.style.display = "none";
|
||||||
scrollTo(0,0);
|
scrollTo(0, 0);
|
||||||
x.drawImage(img, 0, 0);
|
x.drawImage(img, 0, 0);
|
||||||
|
|
||||||
updateScale();
|
updateScale();
|
||||||
|
|
||||||
canvas.style.display = '';
|
canvas.style.display = "";
|
||||||
$("body").css("overflowY", "");
|
$("body").css("overflowY", "");
|
||||||
x.restore();
|
x.restore();
|
||||||
};
|
};
|
||||||
@ -434,23 +435,23 @@ function showNextPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function updateScale(clear) {
|
function updateScale(clear) {
|
||||||
var mainImageStyle = getElem('mainImage').style;
|
var mainImageStyle = getElem("mainImage").style;
|
||||||
mainImageStyle.width = '';
|
mainImageStyle.width = "";
|
||||||
mainImageStyle.height = '';
|
mainImageStyle.height = "";
|
||||||
mainImageStyle.maxWidth = '';
|
mainImageStyle.maxWidth = "";
|
||||||
mainImageStyle.maxHeight = '';
|
mainImageStyle.maxHeight = "";
|
||||||
var maxheight = innerHeight - 15;
|
var maxheight = innerHeight - 15;
|
||||||
if (!/main/.test(getElem('titlebar').className)) {
|
if (!/main/.test(getElem("titlebar").className)) {
|
||||||
maxheight -= 25;
|
maxheight -= 25;
|
||||||
}
|
}
|
||||||
if (clear || fitMode == kthoom.Key.N) {
|
if (clear || fitMode == kthoom.Key.N) {
|
||||||
} else if (fitMode == kthoom.Key.B) {
|
} else if (fitMode == kthoom.Key.B) {
|
||||||
mainImageStyle.maxWidth = '100%';
|
mainImageStyle.maxWidth = "100%";
|
||||||
mainImageStyle.maxHeight = maxheight + 'px';
|
mainImageStyle.maxHeight = maxheight + "px";
|
||||||
} else if (fitMode == kthoom.Key.H) {
|
} else if (fitMode == kthoom.Key.H) {
|
||||||
mainImageStyle.height = maxheight + 'px';
|
mainImageStyle.height = maxheight + "px";
|
||||||
} else if (fitMode == kthoom.Key.W) {
|
} else if (fitMode == kthoom.Key.W) {
|
||||||
mainImageStyle.width = '100%';
|
mainImageStyle.width = "100%";
|
||||||
}
|
}
|
||||||
kthoom.saveSettings();
|
kthoom.saveSettings();
|
||||||
}
|
}
|
||||||
@ -458,9 +459,9 @@ function updateScale(clear) {
|
|||||||
function keyHandler(evt) {
|
function keyHandler(evt) {
|
||||||
var code = evt.keyCode;
|
var code = evt.keyCode;
|
||||||
|
|
||||||
if ($("#progress").css('display') == "none")
|
if ($("#progress").css("display") == "none")
|
||||||
return;
|
return;
|
||||||
canKeyNext = (($("body").css("offsetWidth")+$("body").css("scrollLeft"))/ $("body").css("scrollWidth")) >= 1;
|
canKeyNext = (($("body").css("offsetWidth")+$("body").css("scrollLeft")) / $("body").css("scrollWidth")) >= 1;
|
||||||
canKeyPrev = (scrollX <= 0);
|
canKeyPrev = (scrollX <= 0);
|
||||||
|
|
||||||
if (evt.ctrlKey || evt.shiftKey || evt.metaKey) return;
|
if (evt.ctrlKey || evt.shiftKey || evt.metaKey) return;
|
||||||
@ -537,6 +538,7 @@ function init(filename) {
|
|||||||
request.send();
|
request.send();
|
||||||
kthoom.initProgressMeter();
|
kthoom.initProgressMeter();
|
||||||
document.body.className += /AppleWebKit/.test(navigator.userAgent) ? " webkit" : "";
|
document.body.className += /AppleWebKit/.test(navigator.userAgent) ? " webkit" : "";
|
||||||
|
updateScale(true);
|
||||||
kthoom.loadSettings();
|
kthoom.loadSettings();
|
||||||
$(document).keydown(keyHandler);
|
$(document).keydown(keyHandler);
|
||||||
|
|
||||||
|
@ -82,127 +82,127 @@ var RarVolumeHeader = function(bstream) {
|
|||||||
|
|
||||||
info(" flags=" + twoByteValueToHexString(this.flags.value));
|
info(" flags=" + twoByteValueToHexString(this.flags.value));
|
||||||
switch (this.headType) {
|
switch (this.headType) {
|
||||||
case MAIN_HEAD:
|
case MAIN_HEAD:
|
||||||
this.flags.MHD_VOLUME = !!bstream.readBits(1);
|
this.flags.MHD_VOLUME = !!bstream.readBits(1);
|
||||||
this.flags.MHD_COMMENT = !!bstream.readBits(1);
|
this.flags.MHD_COMMENT = !!bstream.readBits(1);
|
||||||
this.flags.MHD_LOCK = !!bstream.readBits(1);
|
this.flags.MHD_LOCK = !!bstream.readBits(1);
|
||||||
this.flags.MHD_SOLID = !!bstream.readBits(1);
|
this.flags.MHD_SOLID = !!bstream.readBits(1);
|
||||||
this.flags.MHD_PACK_COMMENT = !!bstream.readBits(1);
|
this.flags.MHD_PACK_COMMENT = !!bstream.readBits(1);
|
||||||
this.flags.MHD_NEWNUMBERING = this.flags.MHD_PACK_COMMENT;
|
this.flags.MHD_NEWNUMBERING = this.flags.MHD_PACK_COMMENT;
|
||||||
this.flags.MHD_AV = !!bstream.readBits(1);
|
this.flags.MHD_AV = !!bstream.readBits(1);
|
||||||
this.flags.MHD_PROTECT = !!bstream.readBits(1);
|
this.flags.MHD_PROTECT = !!bstream.readBits(1);
|
||||||
this.flags.MHD_PASSWORD = !!bstream.readBits(1);
|
this.flags.MHD_PASSWORD = !!bstream.readBits(1);
|
||||||
this.flags.MHD_FIRSTVOLUME = !!bstream.readBits(1);
|
this.flags.MHD_FIRSTVOLUME = !!bstream.readBits(1);
|
||||||
this.flags.MHD_ENCRYPTVER = !!bstream.readBits(1);
|
this.flags.MHD_ENCRYPTVER = !!bstream.readBits(1);
|
||||||
bstream.readBits(6); // unused
|
bstream.readBits(6); // unused
|
||||||
break;
|
break;
|
||||||
case FILE_HEAD:
|
case FILE_HEAD:
|
||||||
this.flags.LHD_SPLIT_BEFORE = !!bstream.readBits(1); // 0x0001
|
this.flags.LHD_SPLIT_BEFORE = !!bstream.readBits(1); // 0x0001
|
||||||
this.flags.LHD_SPLIT_AFTER = !!bstream.readBits(1); // 0x0002
|
this.flags.LHD_SPLIT_AFTER = !!bstream.readBits(1); // 0x0002
|
||||||
this.flags.LHD_PASSWORD = !!bstream.readBits(1); // 0x0004
|
this.flags.LHD_PASSWORD = !!bstream.readBits(1); // 0x0004
|
||||||
this.flags.LHD_COMMENT = !!bstream.readBits(1); // 0x0008
|
this.flags.LHD_COMMENT = !!bstream.readBits(1); // 0x0008
|
||||||
this.flags.LHD_SOLID = !!bstream.readBits(1); // 0x0010
|
this.flags.LHD_SOLID = !!bstream.readBits(1); // 0x0010
|
||||||
bstream.readBits(3); // unused
|
bstream.readBits(3); // unused
|
||||||
this.flags.LHD_LARGE = !!bstream.readBits(1); // 0x0100
|
this.flags.LHD_LARGE = !!bstream.readBits(1); // 0x0100
|
||||||
this.flags.LHD_UNICODE = !!bstream.readBits(1); // 0x0200
|
this.flags.LHD_UNICODE = !!bstream.readBits(1); // 0x0200
|
||||||
this.flags.LHD_SALT = !!bstream.readBits(1); // 0x0400
|
this.flags.LHD_SALT = !!bstream.readBits(1); // 0x0400
|
||||||
this.flags.LHD_VERSION = !!bstream.readBits(1); // 0x0800
|
this.flags.LHD_VERSION = !!bstream.readBits(1); // 0x0800
|
||||||
this.flags.LHD_EXTTIME = !!bstream.readBits(1); // 0x1000
|
this.flags.LHD_EXTTIME = !!bstream.readBits(1); // 0x1000
|
||||||
this.flags.LHD_EXTFLAGS = !!bstream.readBits(1); // 0x2000
|
this.flags.LHD_EXTFLAGS = !!bstream.readBits(1); // 0x2000
|
||||||
bstream.readBits(2); // unused
|
bstream.readBits(2); // unused
|
||||||
info(" LHD_SPLIT_BEFORE = " + this.flags.LHD_SPLIT_BEFORE);
|
info(" LHD_SPLIT_BEFORE = " + this.flags.LHD_SPLIT_BEFORE);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
bstream.readBits(16);
|
bstream.readBits(16);
|
||||||
}
|
}
|
||||||
|
|
||||||
// byte 6,7
|
// byte 6,7
|
||||||
this.headSize = bstream.readBits(16);
|
this.headSize = bstream.readBits(16);
|
||||||
info(" headSize=" + this.headSize);
|
info(" headSize=" + this.headSize);
|
||||||
switch (this.headType) {
|
switch (this.headType) {
|
||||||
case MAIN_HEAD:
|
case MAIN_HEAD:
|
||||||
this.highPosAv = bstream.readBits(16);
|
this.highPosAv = bstream.readBits(16);
|
||||||
this.posAv = bstream.readBits(32);
|
this.posAv = bstream.readBits(32);
|
||||||
if (this.flags.MHD_ENCRYPTVER) {
|
if (this.flags.MHD_ENCRYPTVER) {
|
||||||
this.encryptVer = bstream.readBits(8);
|
this.encryptVer = bstream.readBits(8);
|
||||||
}
|
|
||||||
info("Found MAIN_HEAD with highPosAv=" + this.highPosAv + ", posAv=" + this.posAv);
|
|
||||||
break;
|
|
||||||
case FILE_HEAD:
|
|
||||||
this.packSize = bstream.readBits(32);
|
|
||||||
this.unpackedSize = bstream.readBits(32);
|
|
||||||
this.hostOS = bstream.readBits(8);
|
|
||||||
this.fileCRC = bstream.readBits(32);
|
|
||||||
this.fileTime = bstream.readBits(32);
|
|
||||||
this.unpVer = bstream.readBits(8);
|
|
||||||
this.method = bstream.readBits(8);
|
|
||||||
this.nameSize = bstream.readBits(16);
|
|
||||||
this.fileAttr = bstream.readBits(32);
|
|
||||||
|
|
||||||
if (this.flags.LHD_LARGE) {
|
|
||||||
info("Warning: Reading in LHD_LARGE 64-bit size values");
|
|
||||||
this.HighPackSize = bstream.readBits(32);
|
|
||||||
this.HighUnpSize = bstream.readBits(32);
|
|
||||||
} else {
|
|
||||||
this.HighPackSize = 0;
|
|
||||||
this.HighUnpSize = 0;
|
|
||||||
if (this.unpackedSize == 0xffffffff) {
|
|
||||||
this.HighUnpSize = 0x7fffffff
|
|
||||||
this.unpackedSize = 0xffffffff;
|
|
||||||
}
|
}
|
||||||
}
|
info("Found MAIN_HEAD with highPosAv=" + this.highPosAv + ", posAv=" + this.posAv);
|
||||||
this.fullPackSize = 0;
|
break;
|
||||||
this.fullUnpackSize = 0;
|
case FILE_HEAD:
|
||||||
this.fullPackSize |= this.HighPackSize;
|
this.packSize = bstream.readBits(32);
|
||||||
this.fullPackSize <<= 32;
|
this.unpackedSize = bstream.readBits(32);
|
||||||
this.fullPackSize |= this.packSize;
|
this.hostOS = bstream.readBits(8);
|
||||||
|
this.fileCRC = bstream.readBits(32);
|
||||||
|
this.fileTime = bstream.readBits(32);
|
||||||
|
this.unpVer = bstream.readBits(8);
|
||||||
|
this.method = bstream.readBits(8);
|
||||||
|
this.nameSize = bstream.readBits(16);
|
||||||
|
this.fileAttr = bstream.readBits(32);
|
||||||
|
|
||||||
// read in filename
|
if (this.flags.LHD_LARGE) {
|
||||||
|
info("Warning: Reading in LHD_LARGE 64-bit size values");
|
||||||
this.filename = bstream.readBytes(this.nameSize);
|
this.HighPackSize = bstream.readBits(32);
|
||||||
for (var _i = 0, _s = ''; _i < this.filename.length; _i++) {
|
this.HighUnpSize = bstream.readBits(32);
|
||||||
_s += String.fromCharCode(this.filename[_i]);
|
} else {
|
||||||
}
|
this.HighPackSize = 0;
|
||||||
|
this.HighUnpSize = 0;
|
||||||
this.filename = _s;
|
if (this.unpackedSize == 0xffffffff) {
|
||||||
|
this.HighUnpSize = 0x7fffffff
|
||||||
if (this.flags.LHD_SALT) {
|
this.unpackedSize = 0xffffffff;
|
||||||
info("Warning: Reading in 64-bit salt value");
|
}
|
||||||
this.salt = bstream.readBits(64); // 8 bytes
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.flags.LHD_EXTTIME) {
|
|
||||||
// 16-bit flags
|
|
||||||
var extTimeFlags = bstream.readBits(16);
|
|
||||||
|
|
||||||
// this is adapted straight out of arcread.cpp, Archive::ReadHeader()
|
|
||||||
for (var I = 0; I < 4; ++I) {
|
|
||||||
var rmode = extTimeFlags >> ((3-I)*4);
|
|
||||||
if ((rmode & 8)==0)
|
|
||||||
continue;
|
|
||||||
if (I!=0)
|
|
||||||
bstream.readBits(16);
|
|
||||||
var count = (rmode&3);
|
|
||||||
for (var J = 0; J < count; ++J)
|
|
||||||
bstream.readBits(8);
|
|
||||||
}
|
}
|
||||||
}
|
this.fullPackSize = 0;
|
||||||
|
this.fullUnpackSize = 0;
|
||||||
|
this.fullPackSize |= this.HighPackSize;
|
||||||
|
this.fullPackSize <<= 32;
|
||||||
|
this.fullPackSize |= this.packSize;
|
||||||
|
|
||||||
if (this.flags.LHD_COMMENT) {
|
// read in filename
|
||||||
info("Found a LHD_COMMENT");
|
|
||||||
}
|
this.filename = bstream.readBytes(this.nameSize);
|
||||||
|
for (var _i = 0, _s = ''; _i < this.filename.length; _i++) {
|
||||||
|
_s += String.fromCharCode(this.filename[_i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.filename = _s;
|
||||||
|
|
||||||
|
if (this.flags.LHD_SALT) {
|
||||||
|
info("Warning: Reading in 64-bit salt value");
|
||||||
|
this.salt = bstream.readBits(64); // 8 bytes
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.flags.LHD_EXTTIME) {
|
||||||
|
// 16-bit flags
|
||||||
|
var extTimeFlags = bstream.readBits(16);
|
||||||
|
|
||||||
|
// this is adapted straight out of arcread.cpp, Archive::ReadHeader()
|
||||||
|
for (var I = 0; I < 4; ++I) {
|
||||||
|
var rmode = extTimeFlags >> ((3-I)*4);
|
||||||
|
if ((rmode & 8)==0)
|
||||||
|
continue;
|
||||||
|
if (I!=0)
|
||||||
|
bstream.readBits(16);
|
||||||
|
var count = (rmode&3);
|
||||||
|
for (var J = 0; J < count; ++J)
|
||||||
|
bstream.readBits(8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.flags.LHD_COMMENT) {
|
||||||
|
info("Found a LHD_COMMENT");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
while(headPos + this.headSize > bstream.bytePtr) bstream.readBits(1);
|
while(headPos + this.headSize > bstream.bytePtr) bstream.readBits(1);
|
||||||
|
|
||||||
info("Found FILE_HEAD with packSize=" + this.packSize + ", unpackedSize= " + this.unpackedSize + ", hostOS=" + this.hostOS + ", unpVer=" + this.unpVer + ", method=" + this.method + ", filename=" + this.filename);
|
info("Found FILE_HEAD with packSize=" + this.packSize + ", unpackedSize= " + this.unpackedSize + ", hostOS=" + this.hostOS + ", unpVer=" + this.unpVer + ", method=" + this.method + ", filename=" + this.filename);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
info("Found a header of type 0x" + byteValueToHexString(this.headType));
|
info("Found a header of type 0x" + byteValueToHexString(this.headType));
|
||||||
// skip the rest of the header bytes (for now)
|
// skip the rest of the header bytes (for now)
|
||||||
bstream.readBytes( this.headSize - 7 );
|
bstream.readBytes( this.headSize - 7 );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user