-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
82 lines (61 loc) · 1.81 KB
/
index.html
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
72
73
74
75
76
77
78
79
80
81
82
<html>
<head>
<script type="text/javascript" src="node_modules/aw-parser/dist/aw-parser.amd.js"></script>
<script type="text/javascript" src="dist/aw-fquery.amd.js"></script>
</head>
<body>
<textarea id="editor">
Title: Test Script
Author: John Doe
INT. TEST - DAY
Action test. Action test. Action test. Action test. Action test. Action test. Action test. Action test. Action test.
HERO 1
Hello --
Hello!
HERO 2
Hello
</textarea>
<p id="results"></p>
<script type="text/javascript">
var CHARACTERS_QUERY, FQ;
function getEditor() {
return document.getElementById('editor');
}
function getResults() {
return document.getElementById('results');
}
function createQuery() {
CHARACTERS_QUERY = FQ.factory('name', {occurrences: 0});
CHARACTERS_QUERY.enter(FQ.ops.is('character'), function(item, fq) {
var selector = fq.select(item.name());
selector.occurrences++;
});
}
function parse() {
var script, result;
getResults().innerHTML = '';
script = getEditor().value;
result = awParser.parser.parse(script, {
print_actions: true,
print_dialogues: true,
print_synopsis: true,
print_sections: true,
print_headers: true,
print_notes: true
});
var characters = CHARACTERS_QUERY.run(result.tokens);
var html = '';
for (var character in characters) {
html += characters[character].name + ' (occurrences: ' + characters[character].occurrences + ')<br />';
}
getResults().innerHTML = html;
}
window.onload = function() {
FQ = awFquery(awParser.helpers);
createQuery();
getEditor().onkeyup = parse;
parse();
}
</script>
</body>
</html>