forked from jpetazzo/container.training
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slidechecker.js
executable file
·71 lines (66 loc) · 2.16 KB
/
slidechecker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env phantomjs
var system = require('system');
var filename = system.args[1];
var url = 'file://' + system.env.PWD + '/' + filename;
var page = require('webpage').create();
page.onResourceError = function(resourceError) {
console.log('ResourceError: ' + resourceError.url);
}
page.onConsoleMessage = function(msg) {
//console.log('Console: ' +msg);
}
console.log('DEBUG Loading: ' + url);
page.open(url, function(status) {
console.log('DEBUG Loaded: ' + url + '(' + status + ')');
/* analyze will be an object with:
*
* titles
* A dict with all the titles that are too high
* (i.e. because they have been broken across multiple
* lines because they are too long)
*
* slides
* A dict with the slides that are too high
*
* n_slides
* Number of slides found
*/
var analyze = page.evaluate(function() {
var ret = {}, i, n = slideshow.getSlideCount();
ret = [];
for (i=1; i<=n; i++) {
console.log('DEBUG Current slide: ' + i + '/' + n);
var visible_slide = document.getElementsByClassName('remark-visible')[0];
var debug = visible_slide.getElementsByClassName('debug');
if (debug.length==0) {
debug = '?';
}
else {
debug = debug[0].textContent;
}
var slide_desc = 'Slide ' + i + '/' + n + ' (' + debug + ')';
['h1', 'h2'].forEach(function(tag) {
var titles = visible_slide.getElementsByTagName(tag);
console.log('DEBUG Found ' + titles.length + ' titles with tag ' + tag);
titles.forEach(function(t) {
if (t.clientHeight>60) {
ret.push(slide_desc + ' has a long title: ' + t.textContent);
}
});
});
var scaler = visible_slide.getElementsByClassName('remark-slide-scaler')[0];
var slide = scaler.getElementsByClassName('remark-slide')[0];
if (slide.clientHeight > scaler.clientHeight) {
ret.push(slide_desc + ' is too long');
}
slideshow.gotoNextSlide();
}
ret.push('Deck has ' + n + ' slides');
return ret;
});
analyze.forEach(function(msg) {
console.log(msg);
});
console.log('DEBUG Done: ' + url + '(' + status + ')');
phantom.exit();
});