SHOW:
|
|
- or go back to the newest paste.
| 1 | - | --KristScape by cossacksson |
| 1 | + | --KristScape by cossacksson leaked by 0147dfcf09076391382181e24c7ae15c58215de861aa0a64b44ed7c42e703e9235993ac347aed1845fb674a379d311e24ee94b344fef5543677c24a18dcb6e09 |
| 2 | local release = 1 | |
| 3 | local version = "pre-release" | |
| 4 | local latest = 0 | |
| 5 | local gui = 0 | |
| 6 | local tabs = 1 | |
| 7 | local activetab = 1 | |
| 8 | local selected = false | |
| 9 | local editing = false | |
| 10 | local title = {}
| |
| 11 | local address = {}
| |
| 12 | local content = {}
| |
| 13 | local literal = {}
| |
| 14 | local history = {}
| |
| 15 | local links = {}
| |
| 16 | local themefore = 32 | |
| 17 | local themeback = 8192 | |
| 18 | local themehead = 256 | |
| 19 | local themetext = 32768 | |
| 20 | local themetool = -1 | |
| 21 | local themedang = 16384 | |
| 22 | local issue = 0 | |
| 23 | local headers = {["User-Agent"] = "KristScape "..version}
| |
| 24 | links[1] = {}
| |
| 25 | links[2] = {}
| |
| 26 | links[3] = {}
| |
| 27 | links[1][0] = 0 | |
| 28 | history[1] = {}
| |
| 29 | history[2] = {}
| |
| 30 | history[3] = {}
| |
| 31 | history[1][0] = 0 | |
| 32 | local function boot() | |
| 33 | term.setBackgroundColor(1) | |
| 34 | term.clear() | |
| 35 | checkdir() | |
| 36 | checkdir() | |
| 37 | --if http then update() end | |
| 38 | settle() | |
| 39 | title[1] = "New Tab" | |
| 40 | address[1] = "" | |
| 41 | content[1] = "[BG:WHITE]" | |
| 42 | while tabs > 0 do | |
| 43 | go() | |
| 44 | end | |
| 45 | term.setBackgroundColor(32768) | |
| 46 | term.setTextColor(16) | |
| 47 | term.clear() | |
| 48 | term.setCursorPos(1,1) | |
| 49 | end | |
| 50 | function update() | |
| 51 | latest = tonumber(http.get(readconfig("versionserver")).readAll())
| |
| 52 | if latest > version then | |
| 53 | print("An update is available!")
| |
| 54 | --log("Discovered update")
| |
| 55 | if readconfig("autoupdate") then
| |
| 56 | local me = fs.open(fs.getName(shell.getRunningProgram()),"w") | |
| 57 | local nextversion = http.get(readconfig("updateserver")).readAll()
| |
| 58 | print("Installed update. Run this program again to start v"..latest..".")
| |
| 59 | me.write(nextversion) | |
| 60 | me.close() | |
| 61 | --("Installed update")
| |
| 62 | else | |
| 63 | --log("Ignored update")
| |
| 64 | latest = -2 | |
| 65 | end | |
| 66 | else | |
| 67 | --log("No updates found")
| |
| 68 | end | |
| 69 | end | |
| 70 | function log(text) | |
| 71 | logfile = fs.open("kst/log_scape","a")
| |
| 72 | logfile.writeLine(tostring(os.day()).."-"..tostring(os.time())..": "..text) | |
| 73 | logfile.close() | |
| 74 | end | |
| 75 | function checkfile(path,default) | |
| 76 | if not fs.exists("kst/"..path) then
| |
| 77 | file = fs.open("kst/"..path,"w")
| |
| 78 | file.writeLine(default) | |
| 79 | file.close() | |
| 80 | --log("Created file "..path)
| |
| 81 | return false | |
| 82 | else | |
| 83 | return true | |
| 84 | end | |
| 85 | end | |
| 86 | function resetfile(path,default) | |
| 87 | file = fs.open("kst/"..path,"w")
| |
| 88 | file.writeLine(default) | |
| 89 | file.close() | |
| 90 | --log("Wrote file "..path)
| |
| 91 | end | |
| 92 | function readconfig(path) | |
| 93 | if fs.exists("kst/"..path) then
| |
| 94 | file = fs.open("kst/"..path,"r")
| |
| 95 | local context = file.readAll() | |
| 96 | file.close() | |
| 97 | if context == "true" then return true end | |
| 98 | if context == "false" then return false end | |
| 99 | return context | |
| 100 | else | |
| 101 | return false | |
| 102 | end | |
| 103 | end | |
| 104 | function settle() | |
| 105 | gui = 2 | |
| 106 | if pocket then gui = 4 end | |
| 107 | if term.isColor() then gui = 1 end | |
| 108 | if term.isColor() and pocket then gui = 2 end | |
| 109 | local theme = readconfig("theme")
| |
| 110 | themefore = 2^tonumber(theme:sub(1,1),16) | |
| 111 | themeback = 2^tonumber(theme:sub(2,2),16) | |
| 112 | themehead = 2^tonumber(theme:sub(3,3),16) | |
| 113 | themetext = 2^tonumber(theme:sub(4,4),16) | |
| 114 | themedang = 2^tonumber(theme:sub(5,5),16) | |
| 115 | end | |
| 116 | local function panic() | |
| 117 | tabs = 0 | |
| 118 | end | |
| 119 | local function getError(code) | |
| 120 | if code == 000 then return "UNSPECIFIED_EXCEPTION" end | |
| 121 | if code == 001 then return "ILLEGALLY_NESTED_TAGS" end | |
| 122 | if code == 002 then return "UNEXPECTED_CLOSING_TAG" end | |
| 123 | if code == 003 then return "HTTP_NOT_ENABLED" end | |
| 124 | if code == 004 then return "NO_DATA_RECEIVED" end | |
| 125 | if code == 005 then return "NO_DNS_RECORD_FOUND" end | |
| 126 | if code == 006 then return "GENERIC_EXCEPTION" end | |
| 127 | if code == 007 then return "UNSUPPORTED_IMAGE_FORMAT" end | |
| 128 | if code == 008 then return "NFP_IMAGE_NOT_STORED_LOCALLY" end | |
| 129 | if code == 009 then return "HOSTNAME_NOT_RESOLVED" end | |
| 130 | if code == 042 then return "BLOCKED_BY_CHUCK_NORRIS" end | |
| 131 | return "INVALID_ERROR_CODE" | |
| 132 | end | |
| 133 | function checkdir() | |
| 134 | if fs.isDir("kst") then
| |
| 135 | checkfile("log_scape","KristScape browsing history")
| |
| 136 | checkfile("versionserver","https://raw.githubusercontent.com/BTCTaras/kristwallet/master/staticapi/browserversion")
| |
| 137 | checkfile("updateserver","https://raw.githubusercontent.com/BTCTaras/kristwallet/master/kristscape")
| |
| 138 | checkfile("theme","5d8fe")
| |
| 139 | checkfile("theme","1ecff")
| |
| 140 | checkfile("theme","87ffe")
| |
| 141 | checkfile("theme","39bfe")
| |
| 142 | checkfile("theme","4c8fe")
| |
| 143 | checkfile("theme","6e8ff")
| |
| 144 | checkfile("theme","f788e")
| |
| 145 | resetfile("syncnode","http://ceriat.net/krist/index.php")
| |
| 146 | resetfile("pages/test",[[Images test
| |
| 147 | .nfp format: | |
| 148 | [BR][IMAGE]images/dang.nfp[/IMAGE][END] | |
| 149 | ]]) | |
| 150 | resetfile("pages/error",[[Oh dear!!!!![ERROR]
| |
| 151 | [BG:THEMEDISABLED][C:THEMETEXT][HL:THEMEFG][BR][CENTER]KristScape has encountered an error![/CENTER][HL:THEMEDISABLED] | |
| 152 | [BR]The page could not be displayed because of an | |
| 153 | [BR]error. Sorry about that :( | |
| 154 | [BR] | |
| 155 | [BR]Code: [C:YELLOW][HL:RED][PROBLEM][C:THEMETEXT][HL:THEMEDISABLED] | |
| 156 | [BR] | |
| 157 | [BR]If you need help or don't know what this | |
| 158 | [BR]means, you can ask on the Krist thread. | |
| 159 | [BR] [IMAGE]images/dang.nfp[/IMAGE] | |
| 160 | [END] | |
| 161 | ]]) | |
| 162 | resetfile("pages/images/dang.nfp",[[4444 44 4 4 44444
| |
| 163 | 4 44 44 44 444 4 4 4 | |
| 164 | 4 4 44 44 4 44 4 4 | |
| 165 | 4 4 444444444 4 444 4 444 | |
| 166 | 4 4 4 44 4 44 44 4 | |
| 167 | 444 44 4 4 4 4444]]) | |
| 168 | resetfile("pages/images/krist.nft",[[?0?5/?5?d\
| |
| 169 | ?5?d\?d?5/]]) | |
| 170 | else | |
| 171 | fs.makeDir("kst/scape")
| |
| 172 | end | |
| 173 | end | |
| 174 | local function centerText(text) | |
| 175 | local x,y = term.getSize() | |
| 176 | local x2,y2 = term.getCursorPos() | |
| 177 | term.setCursorPos(math.ceil((x/2)-(text:len()/2)),y2) | |
| 178 | term.write(text) | |
| 179 | end | |
| 180 | local function centerTextAt(text,width,at) | |
| 181 | local x,y = term.getSize() | |
| 182 | local x2,y2 = term.getCursorPos() | |
| 183 | term.setCursorPos(math.ceil((x/2)-((width)/2))+at,y2) | |
| 184 | term.write(text) | |
| 185 | end | |
| 186 | local function stripTags(text) | |
| 187 | local digest = "" | |
| 188 | local nexttag = 0 | |
| 189 | while true do | |
| 190 | nexttag = text:find("%[")
| |
| 191 | if tostring(nexttag) == "nil" then | |
| 192 | digest = text | |
| 193 | break | |
| 194 | else | |
| 195 | if nexttag ~= 1 then | |
| 196 | digest = digest .. text:sub(1,nexttag-1):gsub("%]","")
| |
| 197 | text = text:sub(nexttag) | |
| 198 | else | |
| 199 | if tostring(text:find("%]")) == "nil" then break else
| |
| 200 | text = text:sub(nexttag+text:find("%]"))
| |
| 201 | end | |
| 202 | end | |
| 203 | end | |
| 204 | end | |
| 205 | return digest | |
| 206 | end | |
| 207 | local function newtab() | |
| 208 | activetab = tabs + 1 | |
| 209 | tabs = tabs + 1 | |
| 210 | title[activetab] = "New Tab" | |
| 211 | address[activetab] = "" | |
| 212 | literal[activetab] = "" | |
| 213 | content[activetab] = "[BG:WHITE]" | |
| 214 | history[activetab][0] = 0 | |
| 215 | links[activetab][0] = 0 | |
| 216 | end | |
| 217 | local function movetab(from,to) | |
| 218 | title[to] = title[from] | |
| 219 | address[to] = address[from] | |
| 220 | literal[to] = literal[from] | |
| 221 | content[to] = content[from] | |
| 222 | history[to] = history[from] | |
| 223 | links[to] = links[from] | |
| 224 | end | |
| 225 | local function fixaddress(a) | |
| 226 | a = a:gsub(".com",".kst"):gsub(".org",".kst"):gsub(".net",".kst"):gsub(".gov",".kst")
| |
| 227 | if string.sub(a,1,7) ~= "http://" and string.sub(a,1,8) ~= "scape://" then | |
| 228 | a = "http://"..a | |
| 229 | end | |
| 230 | return a | |
| 231 | end | |
| 232 | local function refresh(addr) | |
| 233 | links[activetab][0] = 0 | |
| 234 | local domain = "" | |
| 235 | if addr == "" then | |
| 236 | content[activetab] = " " | |
| 237 | title[activetab] = "" | |
| 238 | else | |
| 239 | if string.sub(addr,1,7) == "http://" then | |
| 240 | if http then | |
| 241 | addr = string.sub(addr,8) | |
| 242 | if addr:find(".kst") == nil then crash(9) return false end
| |
| 243 | domain = string.sub(addr,1,addr:find(".kst")-1)
| |
| 244 | addr = string.sub(addr,5+string.len(domain)) | |
| 245 | local zone = http.get(readconfig("syncnode").."?a="..domain).readAll()
| |
| 246 | --if zone == nil then crash(5) return false end | |
| 247 | if zone == "" then crash(5) return false end | |
| 248 | if string.sub(zone,1,1) == "$" then | |
| 249 | zone = string.sub(zone,2) | |
| 250 | address[activetab] = fixaddress(zone) | |
| 251 | --content[activetab] = "aaaa[SLB]aaaa" | |
| 252 | refresh(address[activetab]) | |
| 253 | else | |
| 254 | literal[activetab] = "http://"..zone..addr | |
| 255 | if history[activetab][history[activetab][0]] ~= address[activetab] then | |
| 256 | history[activetab][0] = history[activetab][0] + 1 | |
| 257 | history[activetab][history[activetab][0]] = address[activetab] | |
| 258 | end | |
| 259 | log(address[activetab]) | |
| 260 | content[activetab] = http.get(literal[activetab],nil,headers).readAll() | |
| 261 | content[activetab] = string.gsub(content[activetab],"\n","[SLB]") | |
| 262 | if tostring(content[activetab]:find("%[SLB%]")) == "nil" then
| |
| 263 | title[activetab] = content[activetab] | |
| 264 | else | |
| 265 | title[activetab] = string.sub(content[activetab],1,string.find(content[activetab],"%[SLB%]")-1) | |
| 266 | end | |
| 267 | content[activetab] = string.sub(content[activetab],string.find(content[activetab],"%[SLB%]")+4) | |
| 268 | end | |
| 269 | else crash(3) return false end | |
| 270 | elseif string.sub(addr,1,8) == "scape://" then | |
| 271 | addr = string.sub(addr,9) | |
| 272 | literal[activetab] = "scape://"..addr | |
| 273 | history[activetab][0] = history[activetab][0] + 1 | |
| 274 | history[activetab][history[activetab][0]] = literal[activetab] | |
| 275 | log(literal[activetab]) | |
| 276 | content[activetab] = readconfig("pages/"..addr)
| |
| 277 | content[activetab] = string.gsub(content[activetab],"\n","[SLB]") | |
| 278 | if tostring(content[activetab]:find("%[SLB%]")) == "nil" then
| |
| 279 | title[activetab] = content[activetab] | |
| 280 | else | |
| 281 | title[activetab] = string.sub(content[activetab],1,string.find(content[activetab],"%[SLB%]")-1) | |
| 282 | end | |
| 283 | content[activetab] = string.sub(content[activetab],string.find(content[activetab],"%[SLB%]")+4) | |
| 284 | end | |
| 285 | end | |
| 286 | end | |
| 287 | function crash(code) | |
| 288 | issue = code | |
| 289 | log("ERROR/"..tostring(code))
| |
| 290 | refresh("scape://error/")
| |
| 291 | literal[activetab] = "scape://error" | |
| 292 | os.setAlarm(os.time()+.01) | |
| 293 | end | |
| 294 | function showsite() | |
| 295 | local page = content[activetab]:gsub("%[PROBLEM%]",string.format("%03d",tostring(issue)).." "..getError(issue)):gsub("%[ID%]",os.getComputerID())
| |
| 296 | if string.len(page) == 0 then crash(4) return false end | |
| 297 | local tag = 0 | |
| 298 | local el = "" | |
| 299 | local align = 1 | |
| 300 | local offset = 0 | |
| 301 | local wid = 0 | |
| 302 | local dontcolorlinks = false | |
| 303 | term.setBackgroundColor(1) | |
| 304 | el = page:sub(2,page:sub(2):find("%]")).."]"
| |
| 305 | if el == "[BG:BLACK]" then | |
| 306 | term.setBackgroundColor(32768) | |
| 307 | elseif el == "[BG:RED]" then | |
| 308 | term.setBackgroundColor(16384) | |
| 309 | elseif el == "[BG:GREEN]" then | |
| 310 | term.setBackgroundColor(8192) | |
| 311 | elseif el == "[BG:BROWN]" then | |
| 312 | term.setBackgroundColor(4096) | |
| 313 | elseif el == "[BG:BLUE]" then | |
| 314 | term.setBackgroundColor(2048) | |
| 315 | elseif el == "[BG:PURPLE]" then | |
| 316 | term.setBackgroundColor(1024) | |
| 317 | elseif el == "[BG:CYAN]" then | |
| 318 | term.setBackgroundColor(512) | |
| 319 | elseif el == "[BG:LIGHTGRAY]" or el == "[BG:LIGHTGREY]" then | |
| 320 | term.setBackgroundColor(256) | |
| 321 | elseif el == "[BG:DARKGRAY]" or el == "[BG:DARKGREY]" or el == "[BG:GRAY]" or el == "[BG:GREY]" then | |
| 322 | term.setBackgroundColor(128) | |
| 323 | elseif el == "[BG:PINK]" then | |
| 324 | term.setBackgroundColor(64) | |
| 325 | elseif el == "[BG:LIME]" then | |
| 326 | term.setBackgroundColor(32) | |
| 327 | elseif el == "[BG:YELLOW]" then | |
| 328 | term.setBackgroundColor(16) | |
| 329 | elseif el == "[BG:LIGHTBLUE]" then | |
| 330 | term.setBackgroundColor(8) | |
| 331 | elseif el == "[BG:MAGENTA]" then | |
| 332 | term.setBackgroundColor(4) | |
| 333 | elseif el == "[BG:ORANGE]" then | |
| 334 | term.setBackgroundColor(2) | |
| 335 | elseif el == "[BG:WHITE]" then | |
| 336 | term.setBackgroundColor(1) | |
| 337 | elseif el == "[BG:THEMEFG]" then | |
| 338 | term.setBackgroundColor(themefore) | |
| 339 | elseif el == "[BG:THEMEDISABLED]" then | |
| 340 | term.setBackgroundColor(themeback) | |
| 341 | elseif el == "[BG:THEMEBG]" then | |
| 342 | term.setBackgroundColor(themehead) | |
| 343 | elseif el == "[BG:THEMETEXT]" then | |
| 344 | term.setBackgroundColor(themetext) | |
| 345 | elseif el == "[BG:THEMEDANGER]" then | |
| 346 | term.setBackgroundColor(themedang) | |
| 347 | end | |
| 348 | while true do | |
| 349 | tag = tag + 1 | |
| 350 | term.setCursorPos(1,3+tag) | |
| 351 | term.write(" ")
| |
| 352 | if tag == 16 then break end | |
| 353 | end | |
| 354 | tag = 0 | |
| 355 | term.setTextColor(32768) | |
| 356 | term.setCursorPos(1,4) | |
| 357 | while true do | |
| 358 | --print(page) | |
| 359 | tag = page:find("%[")
| |
| 360 | if tostring(tag) == "nil" then | |
| 361 | if align == 1 then term.write(page:gsub("%]",""))
| |
| 362 | elseif align == 2 then centerText(page) | |
| 363 | end | |
| 364 | break | |
| 365 | else | |
| 366 | if tag ~= 1 then | |
| 367 | if align == 1 then term.write(page:sub(1,tag-1):gsub("%]",""))
| |
| 368 | elseif align == 2 then | |
| 369 | local line = page:sub(1,tag-1) | |
| 370 | --string.len(page:sub(1,-8+tag+page:find("%[/CENTER%]")))
| |
| 371 | --string.find(stripTags(page:gsub("%[/CENTER%]","$$ENDCENT")),"$$ENDCENT")-string.len(stripTags(line))-- - string.len(line))
| |
| 372 | --print() | |
| 373 | --while string.len(stripTags(line)) < string.len(stripTags(line)) + offset do line = " " .. line end | |
| 374 | --while string.len(stripTags(line)) < string.find(stripTags(page:gsub("%[/CENTER%]","$$ENDCENT")),"$$ENDCENT") + offset do line = line .. " " end
| |
| 375 | centerTextAt(line,wid,offset)--,-(string.len(page:sub(1,-9+tag+string.find(stripTags(page:gsub("%[/CENTER%]","$$ENDCENT")),"$$ENDCENT")))/2)+offset-5)
| |
| 376 | offset = offset + string.len(stripTags(line)) | |
| 377 | end | |
| 378 | page = page:sub(tag) | |
| 379 | else | |
| 380 | el = page:sub(tag,-1+tag+page:find("%]"))
| |
| 381 | if el == "[C:BLACK]" then | |
| 382 | term.setTextColor(32768) | |
| 383 | elseif el == "[C:RED]" then | |
| 384 | term.setTextColor(16384) | |
| 385 | elseif el == "[C:GREEN]" then | |
| 386 | term.setTextColor(8192) | |
| 387 | elseif el == "[C:BROWN]" then | |
| 388 | term.setTextColor(4096) | |
| 389 | elseif el == "[C:BLUE]" then | |
| 390 | term.setTextColor(2048) | |
| 391 | elseif el == "[C:PURPLE]" then | |
| 392 | term.setTextColor(1024) | |
| 393 | elseif el == "[C:CYAN]" then | |
| 394 | term.setTextColor(512) | |
| 395 | elseif el == "[C:LIGHTGRAY]" or el == "[C:LIGHTGREY]" then | |
| 396 | term.setTextColor(256) | |
| 397 | elseif el == "[C:DARKGRAY]" or el == "[C:DARKGREY]" or el == "[C:GRAY]" or el == "[C:GREY]" then | |
| 398 | term.setTextColor(128) | |
| 399 | elseif el == "[C:PINK]" then | |
| 400 | term.setTextColor(64) | |
| 401 | elseif el == "[C:LIME]" then | |
| 402 | term.setTextColor(32) | |
| 403 | elseif el == "[C:YELLOW]" then | |
| 404 | term.setTextColor(16) | |
| 405 | elseif el == "[C:LIGHTBLUE]" then | |
| 406 | term.setTextColor(8) | |
| 407 | elseif el == "[C:MAGENTA]" then | |
| 408 | term.setTextColor(4) | |
| 409 | elseif el == "[C:ORANGE]" then | |
| 410 | term.setTextColor(2) | |
| 411 | elseif el == "[C:WHITE]" then | |
| 412 | term.setTextColor(1) | |
| 413 | elseif el == "[C:THEMEFG]" then | |
| 414 | term.setTextColor(themefore) | |
| 415 | elseif el == "[C:THEMEDISABLED]" then | |
| 416 | term.setTextColor(themeback) | |
| 417 | elseif el == "[C:THEMEBG]" then | |
| 418 | term.setTextColor(themehead) | |
| 419 | elseif el == "[C:THEMETEXT]" then | |
| 420 | term.setTextColor(themetext) | |
| 421 | elseif el == "[C:THEMEDANGER]" then | |
| 422 | term.setTextColor(themedang) | |
| 423 | elseif el == "[HL:BLACK]" then | |
| 424 | term.setBackgroundColor(32768) | |
| 425 | elseif el == "[HL:RED]" then | |
| 426 | term.setBackgroundColor(16384) | |
| 427 | elseif el == "[HL:GREEN]" then | |
| 428 | term.setBackgroundColor(8192) | |
| 429 | elseif el == "[HL:BROWN]" then | |
| 430 | term.setBackgroundColor(4096) | |
| 431 | elseif el == "[HL:BLUE]" then | |
| 432 | term.setBackgroundColor(2048) | |
| 433 | elseif el == "[HL:PURPLE]" then | |
| 434 | term.setBackgroundColor(1024) | |
| 435 | elseif el == "[HL:CYAN]" then | |
| 436 | term.setBackgroundColor(512) | |
| 437 | elseif el == "[HL:LIGHTGRAY]" or el == "[HL:LIGHTGREY]" then | |
| 438 | term.setBackgroundColor(256) | |
| 439 | elseif el == "[HL:DARKGRAY]" or el == "[HL:DARKGREY]" or el == "[HL:GRAY]" or el == "[HL:GREY]" then | |
| 440 | term.setBackgroundColor(128) | |
| 441 | elseif el == "[HL:PINK]" then | |
| 442 | term.setBackgroundColor(64) | |
| 443 | elseif el == "[HL:LIME]" then | |
| 444 | term.setBackgroundColor(32) | |
| 445 | elseif el == "[HL:YELLOW]" then | |
| 446 | term.setBackgroundColor(16) | |
| 447 | elseif el == "[HL:LIGHTBLUE]" then | |
| 448 | term.setBackgroundColor(8) | |
| 449 | elseif el == "[HL:MAGENTA]" then | |
| 450 | term.setBackgroundColor(4) | |
| 451 | elseif el == "[HL:ORANGE]" then | |
| 452 | term.setBackgroundColor(2) | |
| 453 | elseif el == "[HL:WHITE]" then | |
| 454 | term.setBackgroundColor(1) | |
| 455 | elseif el == "[HL:THEMEFG]" then | |
| 456 | term.setBackgroundColor(themefore) | |
| 457 | elseif el == "[HL:THEMEDISABLED]" then | |
| 458 | term.setBackgroundColor(themeback) | |
| 459 | elseif el == "[HL:THEMEBG]" then | |
| 460 | term.setBackgroundColor(themehead) | |
| 461 | elseif el == "[HL:THEMETEXT]" then | |
| 462 | term.setBackgroundColor(themetext) | |
| 463 | elseif el == "[HL:THEMEDANGER]" then | |
| 464 | term.setBackgroundColor(themedang)--[[ old method | |
| 465 | elseif el == "[CENTER]" then | |
| 466 | local ox, oy = term.getCursorPos() | |
| 467 | if ox ~= 1 then term.setCursorPos(1,1+oy) end | |
| 468 | centerText(page:sub(9,-2+tag+page:find("%[/CENTER%]")))
| |
| 469 | page = page:sub(tag+page:find("%[/CENTER"))
| |
| 470 | term.setCursorPos(1,1+oy) | |
| 471 | if ox ~= 1 then term.setCursorPos(1,2+oy) end]]-- | |
| 472 | elseif el == "[CENTER]" then | |
| 473 | if align == 1 then | |
| 474 | local ox, oy = term.getCursorPos() | |
| 475 | if ox ~= 1 then term.setCursorPos(1,1+oy) end | |
| 476 | align = 2 | |
| 477 | wid = string.len(stripTags(page:sub(1,page:find("%[/CENTER%]"))))
| |
| 478 | elseif align == 2 then | |
| 479 | crash(1) | |
| 480 | break | |
| 481 | end | |
| 482 | elseif el == "[/CENTER]" then | |
| 483 | if align == 2 then | |
| 484 | local ox, oy = term.getCursorPos() | |
| 485 | align = 1 | |
| 486 | term.setCursorPos(1,1+oy) | |
| 487 | offset = 0 | |
| 488 | else crash(2) return false end | |
| 489 | elseif el == "[UP]" then | |
| 490 | local ox, oy = term.getCursorPos() | |
| 491 | term.setCursorPos(ox,oy-1) | |
| 492 | elseif el == "[CR]" then | |
| 493 | local ox, oy = term.getCursorPos() | |
| 494 | term.setCursorPos(1,oy) | |
| 495 | elseif el == "[BR]" then | |
| 496 | local ox, oy = term.getCursorPos() | |
| 497 | term.setCursorPos(1,oy+1) | |
| 498 | elseif el == "[LF]" then | |
| 499 | local ox, oy = term.getCursorPos() | |
| 500 | term.setCursorPos(ox,oy+1) | |
| 501 | elseif el == "[TOP]" then | |
| 502 | local ox, oy = term.getCursorPos() | |
| 503 | term.setCursorPos(1,4) | |
| 504 | elseif el == "[END]" then | |
| 505 | break--[[ | |
| 506 | elseif el == "[PROBLEM]" then | |
| 507 | if align ~= 1 then crash(1) return false end | |
| 508 | --if issue == 0 then crash(6) return false end | |
| 509 | term.write(string.format("%03d",tostring(issue)))
| |
| 510 | term.write(" "..getError(issue))--]]
| |
| 511 | elseif el == "[IMAGE]" then | |
| 512 | local ox, oy = term.getCursorPos() | |
| 513 | local src = "" | |
| 514 | local url = page:sub(8,-1+page:find("%[/IMAGE%]"))
| |
| 515 | local islocal = false | |
| 516 | local img = "" | |
| 517 | if url:sub(1,7) == "http://" then | |
| 518 | src = url | |
| 519 | elseif url:sub(1,8) == "scape://" then | |
| 520 | src = url | |
| 521 | islocal = true | |
| 522 | else | |
| 523 | src = string.sub(literal[activetab],1,-string.find(literal[activetab]:reverse(),"/"))..page:sub(8,-1+page:find("%[/IMAGE%]"))
| |
| 524 | if src:sub(1,8) == "scape://" then islocal = true end | |
| 525 | end | |
| 526 | log(src) | |
| 527 | if islocal then | |
| 528 | src = src:sub(8) | |
| 529 | img = readconfig("pages/"..src)
| |
| 530 | else | |
| 531 | print(src) | |
| 532 | img = http.get(src).readAll() | |
| 533 | end | |
| 534 | local filetype = string.sub(src,1-string.find(src:reverse(),"%.")) | |
| 535 | if filetype == "nfp" then | |
| 536 | if islocal then | |
| 537 | --img = paintutils.loadImage(src) | |
| 538 | paintutils.drawImage(paintutils.loadImage("kst/pages/"..src),ox,oy)
| |
| 539 | else crash(8) return false end | |
| 540 | else | |
| 541 | crash(7) | |
| 542 | end | |
| 543 | page = page:sub(1+page:find("%[/IMAGE"))
| |
| 544 | elseif el == "[DONTCOLORLINKS]" then | |
| 545 | dontcolorlinks = true | |
| 546 | elseif el == "[COLORLINKS]" then | |
| 547 | dontcolorlinks = false | |
| 548 | elseif el == "[A]" then | |
| 549 | links[activetab][0] = links[activetab][0] + 1 | |
| 550 | links[activetab][links[activetab][0]] = {}
| |
| 551 | links[activetab][links[activetab][0]][0], links[activetab][links[activetab][0]][1] = term.getCursorPos() | |
| 552 | links[activetab][links[activetab][0]][2] = page:sub(4,-1+page:find(" "))
| |
| 553 | page = page:sub(1+page:find(" "))
| |
| 554 | if not dontcolorlinks then term.setTextColor(512) end | |
| 555 | elseif el == "[/A]" then | |
| 556 | local linklen = term.getCursorPos() | |
| 557 | links[activetab][links[activetab][0]][3] = linklen + links[activetab][links[activetab][0]][1] - 1 | |
| 558 | end | |
| 559 | if el ~= "[A]" then page = page:sub(tag+page:find("%]")) end
| |
| 560 | end | |
| 561 | end | |
| 562 | end | |
| 563 | end | |
| 564 | function go() | |
| 565 | --issue = 0 | |
| 566 | ui() | |
| 567 | local event, param1, param2, param3 = os.pullEvent() | |
| 568 | if event == "mouse_click" and param1 == 1 then | |
| 569 | if param2 > 2 and param2 < 38 and param3 == 2 then | |
| 570 | if not editing then | |
| 571 | editing = true | |
| 572 | address[0] = address[activetab] | |
| 573 | else | |
| 574 | if selected then selected = false else selected = true end | |
| 575 | end | |
| 576 | elseif address[activetab] ~= "" and param2 > 44 and param2 < 47 and param3 == 2 then | |
| 577 | selected = false | |
| 578 | editing = false | |
| 579 | address[activetab] = fixaddress(address[0]) | |
| 580 | refresh(address[activetab]) | |
| 581 | else | |
| 582 | editing = false | |
| 583 | selected = false | |
| 584 | if param2 < 51 and (param2 - 2) % 17 < 15 and param3 == 1 then | |
| 585 | local tabclicked = 1 + math.floor((param2 - 2) / 17) | |
| 586 | if (param2 - 2) % 17 == 14 and tabclicked <= tabs then | |
| 587 | if tabs * 2 == tabclicked + activetab then | |
| 588 | activetab = activetab - 1 | |
| 589 | elseif tabclicked == activetab - 1 then | |
| 590 | movetab(activetab,tabclicked) | |
| 591 | if activetab < 3 and tabs == 3 then movetab(activetab + 1,activetab) end | |
| 592 | activetab = activetab - 1 | |
| 593 | elseif tabclicked == 1 and activetab == 3 then | |
| 594 | movetab(2,1) | |
| 595 | movetab(3,2) | |
| 596 | activetab = 2 | |
| 597 | elseif 2 == tabclicked + activetab then | |
| 598 | movetab(2,1) | |
| 599 | movetab(3,2) | |
| 600 | else | |
| 601 | movetab(3,2) | |
| 602 | end | |
| 603 | tabs = tabs - 1 | |
| 604 | else | |
| 605 | if tabclicked > tabs then | |
| 606 | if (param2 - 2) % 17 < 3 then newtab() end | |
| 607 | else | |
| 608 | activetab = tabclicked | |
| 609 | end | |
| 610 | end | |
| 611 | end | |
| 612 | end | |
| 613 | elseif editing and event == "char" then | |
| 614 | if selected then | |
| 615 | address[0] = param1 | |
| 616 | selected = false | |
| 617 | else | |
| 618 | address[0] = address[0]..param1 | |
| 619 | end | |
| 620 | elseif editing and event == "key" then | |
| 621 | if param1 == 14 then | |
| 622 | if selected then | |
| 623 | address[0] = "" | |
| 624 | selected = false | |
| 625 | else | |
| 626 | if string.len(address[0]) > 0 then address[0] = address[0]:sub(1,-2) end | |
| 627 | end | |
| 628 | elseif param1 == 28 then | |
| 629 | selected = false | |
| 630 | editing = false | |
| 631 | if address[0] ~= "" then | |
| 632 | address[activetab] = fixaddress(address[0]) | |
| 633 | refresh(address[activetab]) | |
| 634 | end | |
| 635 | end | |
| 636 | end | |
| 637 | end | |
| 638 | function ui() | |
| 639 | term.setTextColor(themefore) | |
| 640 | term.setCursorPos(1,1) | |
| 641 | term.setBackgroundColor(themehead) | |
| 642 | term.write(" ")
| |
| 643 | term.setTextColor(themetext) | |
| 644 | term.setBackgroundColor(themefore) | |
| 645 | term.setCursorPos(1,2) | |
| 646 | term.write(" ")
| |
| 647 | term.setCursorPos(1,3) | |
| 648 | term.write(" ")
| |
| 649 | --address bar and buttons | |
| 650 | term.setBackgroundColor(1) | |
| 651 | term.setCursorPos(3,2) | |
| 652 | term.write(" ")
| |
| 653 | term.setBackgroundColor(themefore) | |
| 654 | term.setCursorPos(39,2) | |
| 655 | term.setTextColor(themeback) | |
| 656 | if history[activetab][0] > 1 then term.setTextColor(themedang) end | |
| 657 | term.write("<-")
| |
| 658 | term.setCursorPos(42,2) | |
| 659 | term.setTextColor(themeback) | |
| 660 | term.write("->")
| |
| 661 | term.setCursorPos(45,2) | |
| 662 | term.setTextColor(themeback) | |
| 663 | if address[activetab] ~= "" then term.setTextColor(themedang) end | |
| 664 | term.write("rf")
| |
| 665 | term.setCursorPos(48,2) | |
| 666 | term.setTextColor(themeback) | |
| 667 | term.write("-(")
| |
| 668 | --tabs | |
| 669 | local n = 0 | |
| 670 | while n < tabs do | |
| 671 | term.setTextColor(themetext) | |
| 672 | term.setCursorPos((17*n)+2,1) | |
| 673 | if activetab == n + 1 then term.setBackgroundColor(themefore) else term.setBackgroundColor(themeback) end | |
| 674 | term.write(" ")
| |
| 675 | term.setCursorPos((17*n)+3,1) | |
| 676 | if tostring(string.find(title[1+n],"%[ERROR%]")) ~= "nil" then term.setTextColor(themedang) end | |
| 677 | term.write(string.gsub(string.sub(title[1+n],1,12),"%[ERROR%]","")) | |
| 678 | term.setCursorPos((17*n)+16,1) | |
| 679 | term.setTextColor(themedang) | |
| 680 | term.write("x")
| |
| 681 | if n == tabs - 1 then | |
| 682 | term.setCursorPos((17*n)+19,1) | |
| 683 | term.setBackgroundColor(themeback) | |
| 684 | term.setTextColor(themetext) | |
| 685 | term.write(" + ")
| |
| 686 | end | |
| 687 | n = n + 1 | |
| 688 | end | |
| 689 | term.setBackgroundColor(1) | |
| 690 | term.setCursorPos(3,2) | |
| 691 | if editing then | |
| 692 | term.setTextColor(themedang) | |
| 693 | term.write(address[0]:sub(-33)) | |
| 694 | if not selected then term.write("_") end
| |
| 695 | else | |
| 696 | term.setTextColor(themetext) | |
| 697 | term.write(address[activetab]:sub(1,35)) | |
| 698 | end | |
| 699 | if selected then | |
| 700 | term.setBackgroundColor(512) | |
| 701 | term.setTextColor(1) | |
| 702 | term.setCursorPos(3,2) | |
| 703 | term.write(address[0]:sub(1,35)) | |
| 704 | end | |
| 705 | term.setBackgroundColor(themefore) | |
| 706 | term.setTextColor(themetext) | |
| 707 | term.setCursorPos(string.len(title[activetab]),3) | |
| 708 | centerText(string.gsub(title[activetab],"%[ERROR%]","")) | |
| 709 | showsite() | |
| 710 | term.setBackgroundColor(themeback) | |
| 711 | term.setTextColor(themefore) | |
| 712 | local bar = 0 | |
| 713 | while bar < 16 do | |
| 714 | bar = bar + 1 | |
| 715 | term.setCursorPos(51,3+bar) | |
| 716 | if bar == 1 or bar == 15 then term.write("#") end
| |
| 717 | if bar == 16 then term.write("_") end
| |
| 718 | term.write(" ")
| |
| 719 | end | |
| 720 | end | |
| 721 | boot() |