[go: up one dir, main page]

Menu

[r144]: / imeight_dev.js  Maximize  Restore  History

Download this file

255 lines (202 with data), 6.1 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
var listClean = true //does the tokenized program match the text in the listing?
var oldText = ""
var tabs
var grabTutor = null
function dragTutor(ev) {
if (ev.buttons == 0) grabTutor = null
if (grabTutor === null) return
ev.preventDefault()
divTutor.style.left = ev.clientX + grabTutor + "px"
}
function selectTab(selected) {
var oldTab
for (var i in tabs) {
if (tabs[i].tab.style.display != "none") {
oldTab = i
}
if (scriptRunning) {
continue
}
if (i == selected) {
tabs[i].btn.src = tabs[i].btn.src.replace("-ina", "-act")
tabs[i].tab.style.display = "block"
} else {
tabs[i].btn.src = tabs[i].btn.src.replace("-act", "-ina")
tabs[i].tab.style.display = "none"
}
}
tabs[selected].focused.focus()
return oldTab
}
function programTab() { return selectTab("Program") }
function graphicTab() { return selectTab("Graphic") }
function designerTab() { return selectTab("Designer") }
function miscTab() { return selectTab("Misc") }
pageLoadHooks.push(function() {
tabs = {
Program: { btn: btnProgram, tab: tabProgram, focused: taList },
Graphic: { btn: btnGraphic, tab: tabGraphic, focused: tabGraphic },
Designer: { btn: btnDesigner, tab: tabDesigner, focused: tabDesigner },
Misc: { btn: btnMisc, tab: tabMisc, focused: tabMisc }
}
cursorBlink = true
taList.addEventListener("keyup", function(event) {
if (event.keyCode === 120) { //F9
event.preventDefault()
parseText()
}
updateLineNumber() //in case it's up/down arrow etc.
})
taList.addEventListener("mouseup", updateLineNumber)
taList.addEventListener("change", function() {
listClean = false
if (window.navigator.userAgent.indexOf("Edge/") >= 0) return
localStorage.setItem("proglist", taList.value)
})
// initialize built-in variables for direct expressions (?) on Command Line
instructions.CLR.run(0)
//Edge will fill the form automatically by default
listClean = false
if (window.navigator.userAgent.indexOf("Edge/") >= 0) return
taList.value = localStorage.getItem("proglist")
})
function updateLineNumber() {
inLine.value = taList.value.substring(0, taList.selectionStart).split("\n").length
divStatus.innerHTML = ""
var isScript = taList.value.startsWith("SCRIPT\n")
btnScript.style.display = isScript ? "inline-block" : "none"
btnTokenize.style.display = isScript ? "none" : "inline-block"
}
function goLine(target, selectIt) {
var currPos = 0
var lines = taList.value.split("\n")
var target0based = parseInt(target) - 1
var saveTab = programTab()
taList.scrollTop = Math.max(taList.scrollTop, (target0based - 16)*15)
taList.scrollTop = Math.min(taList.scrollTop, (target0based - 4)*15)
selectTab(saveTab)
if (selectIt !== false) {
for (var currLine in lines) {
var part = lines[currLine]
if (currLine == target0based) {
taList.selectionStart = currPos
}
currPos += part.length + 1
if (currLine == target0based) {
taList.selectionEnd = currPos
break
}
}
taList.focus()
}
}
//the default inputAction routine
var interact = function(input) {
if (input === null) return
videoPrint(input)
if (input === "") return
fullTextParse = false
var command = input.toUpperCase().trim()
if (command in commands) {
commands[command]()
commands[command].coverage = true
} else if (command.startsWith("?")) {
//direct expression
var saveProgram = program.slice()
var saveStopped = stopped
var evalPC = program.length
bugLocator = false
parseSuccess = true //enable reporting PARSE errors (even after errors)
stopped = evalPC //enable reporting RUN errors (even after errors)
var rest = expressionArg(input.trim().substring(1))
if (rest !== "") {
parseError("EXTRA ARGUMENT")
} else {
while (evalPC in program) {
var token = program[evalPC]
evaluateToken(token)
evalPC++
}
var result = popAndEvaluate("")
if (result === undefined) {
readyPrompt()
} else {
videoPrint(result)
}
}
program = saveProgram
stopped = saveStopped
} else {
//try adding it as a line to the end of the program text
parseSuccess = true
text = input
parseLine()
if (parseSuccess) {
if (listClean) {
if (!taList.value.endsWith("\n") && taList.value.length > 0) {
taList.value += "\n"
}
taList.value += input + "\n"
updateLineNumber()
} else {
divStatus.innerHTML = "[PROGRAM FORKED]"
}
variables.CURSORY--
videoPrint(FmtStr("PROGRAM", input))
} else {
userInputValue = input
}
}
}
var inputAction = interact
var commands = {
RUN: runProgram,
CONT: contProgram,
LIST: programTab,
NEW: function() {
newProgram()
oldText = taList.value
taList.value = ""
programTab()
},
OLD: function() {
newProgram()
var swap = taList.value
taList.value = oldText
oldText = swap
programTab()
}
}
var coveredErrors = {}
runErrorHook = function(message) {
if (bugLocator) {
goLine(bugLocator.line, false)
taList.selectionStart = bugLocator.chStart
taList.selectionEnd = bugLocator.chEnd
taList.focus()
videoPrint("?" + message + " ERROR IN " + bugLocator.line + ":"
+ bugLocator.colon + ", " + bugLocator.instruction)
divStatus.innerHTML = message
} else {
videoPrint("?" + message + " ERROR")
}
coveredErrors[message] = true
}
parseErrorHook = function(message) {
if (fullTextParse) {
videoPrint("?" + message + " ERROR IN " + lineNumber + ":" + colonCount)
divStatus.innerHTML = message
charsParsed -= text.length
} else {
videoPrint("?" + message + " ERROR")
}
text = ""
readyPrompt()
if (fullTextParse) {
userInputValue = "LIST"
goLine(lineNumber, false)
taList.selectionStart = charsParsed
taList.selectionEnd = (taList.value + "\n").indexOf("\n", charsParsed)
taList.focus()
}
}