-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompiler.js
More file actions
190 lines (167 loc) · 6.15 KB
/
compiler.js
File metadata and controls
190 lines (167 loc) · 6.15 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// let initString = ['HOW|I|THIS|WORKING', 'CHADLEY|Hello World!|REPLIES 0|yoooo', 'ABHISHEK|TWO|REPLIES 18|asdfasdf', 'OJ|BOI|REPLIES 24|asdfhc', 'OJJJ|BBBBBBBBB|REPLIES 24|HHHHHHHH']
let postObj
let initString;
if (localStorage.getItem('initString') !== null) {
initString = localStorage.getItem('initString').split(',');
}
else initString = ['Made with Love | By Ojasvin Kirpane & Abhishek Cherath | 4:20'];
//initString = ['How|I|this|work'];
console.log(initString);
var initStringObj = { init: initString };
let receiveShit = [];
let cycles;
let selfPost = []
//so this proxy thing listens for changes in initstring and rebroadcasts over serialnet.
var initStringProxy = new Proxy(initStringObj, {
set: function (target, key, value) {
target[key] = value;
console.log('sweet dreams', initStringObj.init);
sendMessage();
//receiveText();
arbitraryStorePost();
//updateFeed();
return true;
}
});
function generateDOM() {
let divide = []
let pageTitle = 'CEWITs Funky Forum'
let populateText = ['GhostForum', pageTitle, 'Type your message in the following format:']
for (i = 0; i < 3; i++) {
divide[i] = document.createElement('div')
divide[i].id = "title" + i
divide[i].innerHTML = populateText[i]
document.body.append(divide[i])
}
//localStorage.clear()
receiveText()
pushPost()
updateFeed()
}
function receiveText() {
for (var i = 0; i < initStringObj.init.length; i++) {
receiveShit[i] = initStringObj.init[i].split("|")
for (j = 0; j < 3; j++) {
//localStorage.setItem('pos' + eval(4 * i + j), JSON.stringify(receiveShit[i][j]))
localStorage.setItem('pos' + eval(3 * i + j), receiveShit[i][j])
cycles = 3 * i + j
}
}
//cycles = 4*initString.length+3;
}
function pushPost() {
var a = document.createElement("FORM")
a.setAttribute("id", "username")
a.setAttribute("onsubmit", "return false")
document.body.appendChild(a)
var b = document.createElement("INPUT")
b.setAttribute("type", "text")
b.setAttribute("value", "Your Username")
b.setAttribute("id", "usernameInput");
document.body.appendChild(b)
b.setAttribute("style", "margin-left: 25%; padding: 1em; width: 30%; margin-bottom: 1em; border:none; border-bottom: 1px solid black; background-color: #FFFDF5; height: 13px")
var x = document.createElement("FORM");
x.setAttribute("id", "posting");
x.setAttribute("onsubmit", "return false")
document.body.appendChild(x);
var y = document.createElement("INPUT");
y.setAttribute("type", "text");
y.setAttribute("value", "Your message");
y.setAttribute("id", "userInput");
document.getElementById("posting").appendChild(y);
var z = document.createElement("INPUT");
z.setAttribute("id", "butt")
z.setAttribute("type", "submit");
z.setAttribute("onclick", "storePost(); sendMessage();") //communicator sends. so peer.send here.
z.setAttribute("value", "Post!");
document.getElementById("posting").appendChild(z);
$('input:text').click(
function () {
$(this).val('');
});
if (typeof (conn) !== 'undefined') {
conn.send(initString);
}
}
function postConstruct(u, i){
let transID = Math.floor(Math.random()*16777215).toString(16);
let roomID = Math.floor(Math.random()*16777215).toString(16);
var post = {
origin_server_ts: '',
sender: '@' + u + ':ghostforum.tech',
unsigned: {
age: 'x',
transaction_id: transID
},
content: {
body: i,
msgtype: 'm.text'
},
type: 'm.room.message',
room_id: 'communism'+roomID //put page title (from url) here
}
postObj = JSON.stringify(post);
//console.log(postObj)
}
function storePost() {
localStorage.setItem('response', 'Hello')
var un = document.getElementById('usernameInput').value
var input = document.getElementById('userInput').value;
input2 = un + '|' + input + '|' + dateCalc()
initStringObj.init.unshift(input2)
console.log(input2)
console.log(initString)
receiveText()
document.getElementById("container").innerHTML = "";
updateFeed()
postConstruct(un,input)
console.log(postObj)
}
function arbitraryStorePost() {
receiveText()
document.getElementById("container").innerHTML = "";
updateFeed()
}
function updateFeed() {
let posts = []
let postContain = []
let postText = []
var container = document.createElement('div')
container.id = 'container'
document.body.append(container)
for (i = 0; i < cycles; i++) {
//postText[i] = JSON.parse(localStorage.getItem("pos" + i))
postText[i] = localStorage.getItem("pos" + i)
}
for (x = 0; x <= cycles / 3; x++) {
postContain[i] = document.createElement('div')
postContain[i].id = "postContainer" + x
postContain[i].className = "remove"
postContain[i].setAttribute("style", "margin-left: 25%; padding: 1em; width: 46%; border: solid; border-radius: 5px ;margin-bottom: 0.25em")
document.getElementById("container").append(postContain[i])
for (i = 3 * x; i < 3 * x + 3; i++) {
posts[i] = document.createElement('div')
posts[i].id = "text" + eval(i % 3)
posts[i].innerHTML = postText[i]
document.getElementById("postContainer" + x).appendChild(posts[i]);
}
}
//stores for future instance in localstorage everythin
localStorage.setItem('initString', initStringObj.init);
}
function dateCalc() {
var currentDate = new Date();
var date = currentDate.getDate();
var month = currentDate.getMonth(); //Be careful! January is 0 not 1
var year = currentDate.getFullYear();
var dateString = date + "-" + (month + 1) + "-" + year;
return dateString;
}
function sendMessage() {
if (typeof conner !== 'undefined') {
conner.send(initStringObj.init);
}
if (typeof connection !== 'undefined') {
connection.send(initStringObj.init);
}
}