forked from mapsam/lotripsum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
90 lines (76 loc) · 2.09 KB
/
main.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
72
73
74
75
76
77
78
79
80
81
82
83
84
//three buttons
//add paragraph button
$('#add').click(function(){
generate();
return false;
});
//remove single paragraph button
$('#removeSingle').click(function(){
$('#text p').last().remove();
return false;
});
//remove it all and add a funny line
$('#removeAll').click(function(){
$('#text').empty();
var comment = '<p>The salted pork is particularly good.</p>';
$('#text').append(comment);
return false;
});
function generate() {
var lotrLength = lotr.length,
ipsumLength = ipsum.length,
paragraph, sentence, lotrBrick, ipsumBrick = null,
ipsumBrickLength = Math.round(Math.random()*(2-1)+1);
//create paragraph
paraLength = Math.round(Math.random()*(8-2)+2);
for(p=0; p<paraLength; p++){
//create sentence
sentence = null;
sentenceBricks = Math.round(Math.random()*(3-1)+1);
//console.log("sentence bricks: ", sentenceBricks);
for(s=0; s<sentenceBricks; s++){
//create a single lotr brick
lotrBrick = null;
lotrBrickLength = Math.round(Math.random()*(4-1)+1);
for(i=0; i<=lotrBrickLength; i++){
lotrSingle = Math.round(Math.random()*lotrLength)
if(lotrBrick == null) {
lotrBrick = lotr[lotrSingle];
} else {
lotrBrick = lotrBrick + ' ' + lotr[lotrSingle];
}
//console.log(lotrBrick);
}
//add single lotr brick to sentence
if(sentence == null){
sentence = lotrBrick;
} else {
sentence = sentence + ' ' + lotrBrick;
}
lotrBrick = null;
//create a single ipsum brick
for(i=0; i<=ipsumBrickLength; i++){
ipsumSingle = Math.round(Math.random()*ipsumLength)
if(ipsumBrick == null){
ipsumBrick = ipsum[ipsumSingle];
} else {
ipsumBrick = ipsumBrick + ' ' + ipsum[ipsumSingle];
}
}
//add single ipsum brick to the sentence
sentence = sentence + ' ' + ipsumBrick;
ipsumBrick = null;
}
sentence = sentence + '.'
if(paragraph == null){
paragraph = sentence;
} else {
paragraph = paragraph + ' ' + sentence;
}
sentence = null;
}
paragraph = "<p>"+paragraph+"</p>";
$('#text').append(paragraph);
paragraph = null;
}
window.onLoad = generate();