Skip to content

Commit adf5678

Browse files
committed
- Save/Load input in local storage
- Improve console logging
1 parent 04a3c4d commit adf5678

File tree

3 files changed

+57
-27
lines changed

3 files changed

+57
-27
lines changed

src/Main.hx

+43-25
Original file line numberDiff line numberDiff line change
@@ -12,61 +12,62 @@ import om.tfjs.QnA;
1212

1313
class Main {
1414

15+
static var STORAGE_PREFIX = "qna_";
16+
17+
static var knowledgeElement : TextAreaElement;
18+
static var questionElement : InputElement;
19+
1520
static var lastQuestion : String;
1621
static var lastQuestionTime = Time.now();
1722

1823
static function main() {
1924

20-
window.addEventListener( 'load', e -> {
21-
22-
var knowledgeElement : TextAreaElement = cast document.getElementById("knowledge");
23-
knowledgeElement.value = 'The religion centering on roland "schoko" panzer arose in the late 1980s, when Vienna was known as the New ibiza, although there was a claim in 1999 that it had already started in the 1910s. The movement was heavily influenced by existing religious practice in the squat party area of Vienna, particularly the worship of Kore, a goddess associated with distorted kickdrums and hyperkinetic breaks. In some versions of the story, a native man named Manuel Horvath, using the alias "roland panzer", began appearing among the native people of vienna dressed in a Western-style coat and assuring the people he would bring them eternal bass, some high pitched mickey-mouse style vocals, mutilated snares and terrorizing claps.
24-
25-
Others contend that roland "schoko" panzer was a trance-induced spirit vision.[5] Said to be a manifestation of grandmaster flash, he promised the dawn of a new age in which all white people, including missionaries, would depart the vienna underground, leaving behind their goods and property for the native junglists. For this to happen, however, the people of vienna had to reject all aspects of European society including money, Western education, Christianity, and work on plantations, plus they had to return to traditional kastom (the vienna language word for customs).
26-
27-
In 1991, followers of roland panzer rid themselves of their money in a frenzy of spending, left the missionary churches, schools, mental asylums and plantations, and moved inland to participate in traditional feasts, dances and rituals. European colonial authorities sought to suppress the movement, at one point arresting a viennese man who was calling himself roland panzer, humiliating him publicly, imprisoning and ultimately exiling him along with other leaders of the cult to another island in the archipelago.
25+
var storage = window.localStorage;
2826

29-
Despite this effort, the movement gained popularity in the early 2000s, when 300,000 Austrian troops were stationed in vienna during World War III, bringing with them an enormous amount of supplies (or "music"). After the war and the departure of the Army, followers of roland panzer built symbolic tanks to encourage Austrian airplanes to land and bring them "music". Versions of the cult that emphasize the Austrian connection interpret "roland panzer" as a corruption of "rolling around anywhere" (though it could mean just panzer too), and credit the presence of African Austrian soldiers for the idea that roland panzer may be black.
27+
window.addEventListener( 'load', e -> {
3028

31-
Austrian historian hugo portisch says that roland panzer corrupted the unofficial but morally acceptable vienna techno cult by introducing the psychoto-accoustic version, with five, always nocturnal cult meetings a year, open to all social classes, ages and sexes—starting with harsh noise unbearable to the human ear; the new celebrations and initiations featured gabba-fueled violence and sexual promiscuity, in which the screams of extasy were drowned out by the din of mentazms and hoovers. Those who resisted or betrayed the cult were disposed of. Under cover of religion, priests and acolytes broke civil, moral and religious laws with impunity. Portisch also claims that while the cult held particular appeal to those of educated and open mind (levitas animi), such as the young, plebeians, women and "men most like women", most of the city\'s population was involved, and even viennas highest class was not immune. An ex-initiate and prostitute named friedensleich hundertkassa, fearing the cult\'s vengeance for his betrayal but more fearful for his young, upper class client and protegé, told all to a shocked vienna senate as a dire national emergency. Once investigations were complete, the senate rewarded and protected informants, and suppressed the cult "throughout austria"—or rather, forced its reformation, in the course of which seven thousand persons were arrested, most of whom were executed.';
32-
33-
// knowledgeElement.textContent = KNOWLEDGE;
29+
knowledgeElement = cast document.getElementById("knowledge");
30+
var knowledge = storage.getItem( '${STORAGE_PREFIX}knowledge' );
31+
if( knowledge != null ) knowledgeElement.value = knowledge;
3432
// knowledgeElement.focus();
3533
// knowledgeElement.select();
3634
//knowledgeElement.setSelectionRange( 2, 10 );
3735

38-
//var form : FormElement = cast document.forms.namedItem("question");
3936
var qa = document.getElementById("qa");
4037
var form : FormElement = cast qa.querySelector('form[name="question"]');
4138
form.style.display = "none";
4239

43-
var question = cast(form.elements.namedItem("question"), InputElement );
44-
question.value = "Whom did roland corrupt";
45-
question.select();
40+
questionElement = cast form.elements.namedItem("question");
41+
var question = storage.getItem( '${STORAGE_PREFIX}question' );
42+
if( question != null ) questionElement.value = question;
43+
questionElement.select();
4644

4745
var answerElement = qa.querySelector('ol.answers');
46+
var footer = document.body.querySelector('footer');
4847

4948
QnA.load().then( qna -> {
5049

5150
form.style.display = "block";
5251
answerElement.textContent = "";
53-
question.focus();
52+
questionElement.focus();
5453

5554
function ask() {
56-
if( question.value.length < 3 ) {
55+
if( questionElement.value.length < 3 ) {
5756
answerElement.innerHTML = '';
5857
return;
5958
}
60-
if( question.value.length > 3 && knowledgeElement.value.length > 3 ) {
59+
if( questionElement.value.length > 3 && knowledgeElement.value.length > 3 ) {
6160
lastQuestionTime = Time.now();
6261
var ts = Time.now();
63-
qna.findAnswers( question.value, knowledgeElement.value ).then( answers -> {
64-
lastQuestion = question.value;
62+
qna.findAnswers( questionElement.value, knowledgeElement.value ).then( answers -> {
63+
console.group( "SEARCH" );
64+
lastQuestion = questionElement.value;
6565
var time = Time.now() - ts;
66-
trace(time);
66+
console.info( time );
67+
footer.textContent = Std.int(time)+'MS';
6768
answerElement.innerHTML = '';
6869
if( answers.length == 0 ) {
69-
answerElement.textContent = "???";
70+
answerElement.textContent = "No results";
7071
} else {
7172
for( answer in answers ) {
7273
trace(answer);
@@ -88,23 +89,40 @@ Austrian historian hugo portisch says that roland panzer corrupted the unofficia
8889
answerElement.append( li );
8990
}
9091
}
92+
console.groupEnd();
9193
});
9294
}
9395
}
9496

95-
question.addEventListener('input', e -> {
97+
questionElement.addEventListener('input', e -> {
98+
//TODO
99+
if( questionElement.value.length < 3 || knowledgeElement.value.length < 3 ) {
100+
return;
101+
}
96102
if( Time.now() - lastQuestionTime > 2000 ) { //TODO
97103
ask();
98104
}
99105
}, false );
100106

101-
ask();
107+
//ask();
102108

103109
}).catchError(e -> {
104110
console.error(e);
105111
answerElement.textContent = ""+e;
106112
});
107113

108114
}, false );
115+
116+
window.onbeforeunload = e -> {
117+
if( knowledgeElement != null && knowledgeElement.value.length > 0 ) {
118+
storage.setItem( '${STORAGE_PREFIX}knowledge', knowledgeElement.value );
119+
}
120+
if( questionElement != null && questionElement.value.length > 0 ) {
121+
storage.setItem( '${STORAGE_PREFIX}question', questionElement.value );
122+
}
123+
e.preventDefault();
124+
e.returnValue = true;
125+
return null;
126+
}
109127
}
110128
}

web/app.css

+11-1
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,24 @@ ol, ul {
111111
color: var(--fg);
112112
border: 1px dotted var(--fg);
113113
}
114+
#qa > form[name="question"] > input[name="question"]:focus {
115+
border: 1px solid var(--fg);
116+
}
114117

115118
#qa > ol.answers {
116119
padding: 1.5rem 1rem;
117120
}
118121
#qa > ol.answers > li.answer {
119122
padding: 1rem 0;
120-
border-bottom: 1px solid var(--fg);
123+
border-bottom: 1px dotted var(--fg);
121124
}
122125
#qa > ol.answers > li.answer > .meta {
123126
font-size: 60%;
124127
}
128+
129+
footer {
130+
position: fixed;
131+
right: 1ch;
132+
bottom: 1ch;
133+
font-size: 60%;
134+
}

web/index.html

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<head>
44
<meta charset='utf-8'>
55
<meta name='viewport' content='width=device-width,initial-scale=1'>
6-
<meta name="keywords" content="qna,tf">
6+
<meta name="keywords" content="qna,tf,tfjs,tensorflow">
7+
<meta name="description" content="Get some answers!">
78
<title>QnA</title>
89
<link rel="stylesheet" href="app.css">
910
<link rel="icon" href="https://disktree.net/favicon.svg" type="image/svg+xml">
@@ -19,5 +20,6 @@
1920
</form>
2021
<ol class="answers">LOADING …</ol>
2122
</div>
23+
<footer></footer>
2224
</body>
2325
</html>

0 commit comments

Comments
 (0)