@internetarchive/bookreader 5.0.0-64 → 5.0.0-65
Sign up to get free protection for your applications and to get access to all the features.
- package/BookReader/BookReader.css +2 -1
- package/BookReader/BookReader.js +1 -1
- package/BookReader/BookReader.js.map +1 -1
- package/BookReader/ia-bookreader-bundle.js +2 -2
- package/BookReader/ia-bookreader-bundle.js.map +1 -1
- package/BookReader/plugins/plugin.search.js +1 -1
- package/BookReader/plugins/plugin.search.js.map +1 -1
- package/BookReader/plugins/plugin.tts.js +1 -1
- package/BookReader/plugins/plugin.tts.js.map +1 -1
- package/BookReader/plugins/plugin.url.js +1 -1
- package/BookReader/plugins/plugin.url.js.map +1 -1
- package/CHANGELOG.md +5 -0
- package/package.json +13 -13
- package/src/BookReader.js +0 -5
- package/src/BookReader/DebugConsole.js +0 -54
- package/tests/jest/BookReader/DebugConsole.test.js +0 -25
@@ -1,54 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Displays a console on the document for debugging devices where remote
|
3
|
-
* debugging is not feasible, and forwards all console.log's to be displayed
|
4
|
-
* on screen.
|
5
|
-
*/
|
6
|
-
export class DebugConsole {
|
7
|
-
constructor() {
|
8
|
-
/** How many times we've seen the same line in a row */
|
9
|
-
this.currentRun = 0;
|
10
|
-
}
|
11
|
-
|
12
|
-
init() {
|
13
|
-
this.$log = $(`<div id="_debugLog" style="width: 100%; height: 300px; overflow: auto" />`);
|
14
|
-
$(document.body).prepend(this.$log);
|
15
|
-
|
16
|
-
this.$form = $(`
|
17
|
-
<form>
|
18
|
-
<input style="width:100%; font-family: monospace;" id="_debugLogInput">
|
19
|
-
</form>`);
|
20
|
-
this.$log.append(this.$form);
|
21
|
-
|
22
|
-
this.$form.on("submit", ev => {
|
23
|
-
ev.preventDefault();
|
24
|
-
const result = eval(this.$form.find('input').val());
|
25
|
-
this.logToScreen([result]);
|
26
|
-
});
|
27
|
-
|
28
|
-
const _realLog = console.log.bind(console);
|
29
|
-
console.log = (...args) => {
|
30
|
-
_realLog(...args);
|
31
|
-
this.logToScreen(args);
|
32
|
-
};
|
33
|
-
|
34
|
-
window.onerror = (...args) => this.logToScreen(args);
|
35
|
-
}
|
36
|
-
|
37
|
-
/**
|
38
|
-
* Log the provided array onto the on screen console
|
39
|
-
* @param {Array} args
|
40
|
-
*/
|
41
|
-
logToScreen(args) {
|
42
|
-
const html = args.map(JSON.stringify).join(',');
|
43
|
-
const $lastEntry = this.$log.children('.log-entry:last-child');
|
44
|
-
if ($lastEntry.find('.entry-code').html() == html) {
|
45
|
-
$lastEntry.find('.count').text(`(${++this.currentRun})`);
|
46
|
-
} else {
|
47
|
-
this.currentRun = 1;
|
48
|
-
this.$log.append($(`
|
49
|
-
<div class="log-entry">
|
50
|
-
<code class="count"></code> <code class="entry-code">${html}</code>
|
51
|
-
</div>`));
|
52
|
-
}
|
53
|
-
}
|
54
|
-
}
|
@@ -1,25 +0,0 @@
|
|
1
|
-
import sinon from 'sinon';
|
2
|
-
import { DebugConsole } from '@/src/BookReader/DebugConsole.js';
|
3
|
-
|
4
|
-
beforeEach(() => {
|
5
|
-
sinon.stub(console, 'log');
|
6
|
-
});
|
7
|
-
afterEach(() => {
|
8
|
-
sinon.restore();
|
9
|
-
});
|
10
|
-
|
11
|
-
test('hijacks console.log', () => {
|
12
|
-
const _realLog = console.log;
|
13
|
-
expect(_realLog).toBe(console.log);
|
14
|
-
new DebugConsole().init();
|
15
|
-
expect(_realLog).not.toBe(console.log);
|
16
|
-
});
|
17
|
-
|
18
|
-
test('logging the same thing twice does not create more entries', () => {
|
19
|
-
const dc = new DebugConsole();
|
20
|
-
dc.init();
|
21
|
-
dc.logToScreen(['hello']);
|
22
|
-
dc.logToScreen(['hello']);
|
23
|
-
expect(dc.$log.children('.log-entry')).toHaveLength(1);
|
24
|
-
expect(dc.$log.find('.count').text()).toBe('(2)');
|
25
|
-
});
|