Files: ef1a2eaa163709173d29cc9f3fc446695e466fe7 / index.html
38349 bytesRaw
1 | |
2 | <html manifest="./manifest.appcache"><head> |
3 | <title>---</title> |
4 | <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" /> |
5 | <meta charset=utf-8></head> |
6 | <body></body> |
7 | <script> |
8 | (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ |
9 | var h = require('hscrpt') |
10 | |
11 | function select (ready) { |
12 | return h('input', {type: 'file', onchange: function (ev) { |
13 | var file = ev.target.files[0] |
14 | ready(new FileReader(), file) |
15 | }}) |
16 | |
17 | } |
18 | |
19 | module.exports = function (onFile) { |
20 | return select(function (reader, file) { |
21 | reader.onload = function () { |
22 | onFile(reader.result) |
23 | } |
24 | reader.readAsArrayBuffer(file) |
25 | }) |
26 | } |
27 | |
28 | module.exports.asDataURL = function (onFile) { |
29 | return select(function (reader, file) { |
30 | reader.onload = function () { |
31 | onFile(reader.result) |
32 | } |
33 | reader.readAsDataURL(file) |
34 | }) |
35 | } |
36 | |
37 | |
38 | |
39 | },{"hscrpt":2}],2:[function(require,module,exports){ |
40 | module.exports = function h (tag, attrs, content) { |
41 | if(Array.isArray(attrs)) content = attrs, attrs = {} |
42 | var el = document.createElement(tag) |
43 | for(var k in attrs) el[k] = attrs[k] |
44 | if(content) content.forEach(function (e) { |
45 | if(e) el.appendChild('string' == typeof e ? document.createTextNode(e) : e) |
46 | }) |
47 | return el |
48 | } |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | },{}],3:[function(require,module,exports){ |
55 | |
56 | function create (tag, classname, children) { |
57 | var el = document.createElement(tag) |
58 | classname && el.classList.add(classname) |
59 | children && children.forEach(function (e) { |
60 | el.appendChild( |
61 | 'string' === typeof e ? document.createTextNode(e) : e |
62 | ) |
63 | }) |
64 | return el |
65 | } |
66 | |
67 | module.exports = function (steps) { |
68 | var list = create('ul', 'hyperprogress__list') |
69 | var error = create('pre', 'hyperprogress__error') |
70 | var liquid = create('div', 'hyperprogress__liquid', ['.']) |
71 | var bar = create('div', 'hyperprogress__bar', [liquid]) |
72 | liquid.style.width = '0%' |
73 | |
74 | var n = 0 |
75 | |
76 | var prog = create('div', 'hyperprogress', [ |
77 | steps ? bar : '', |
78 | list, |
79 | //only show bar if a number of steps is provided. |
80 | error |
81 | ]) |
82 | |
83 | prog.complete = function () { |
84 | liquid.style.width = '100%' |
85 | prog.classList.add('hyperprogress--complete') |
86 | } |
87 | |
88 | prog.next = function (name) { |
89 | n = Math.min(n+1, steps) |
90 | if(list.lastChild) |
91 | list.lastChild.classList.add('hyperprogress--okay') |
92 | |
93 | if(name) |
94 | list.appendChild(create('li', 'hyperprogress__started', [name])) |
95 | |
96 | liquid.style.width = Math.round((n/steps)*100)+'%' |
97 | |
98 | if(n === steps) |
99 | prog.complete() |
100 | } |
101 | |
102 | prog.fail = function (err) { |
103 | prog.classList.add('hyperprogress--failed') |
104 | if(err && err.stack && err.name) { |
105 | if(err.stack.indexOf(err.name) == 0) //chrome, node |
106 | error.textContent = err.stack |
107 | else //firefox |
108 | error.textContent = err.name+': '+err.message + '\n' + err.stack |
109 | } |
110 | else if(err && err.name && err.message) |
111 | error.textContent = err.name + ': ' + err.message |
112 | else |
113 | error.textContent = JSON.stringify(err) |
114 | |
115 | return err |
116 | } |
117 | |
118 | prog.reset = function () { |
119 | n = 0 |
120 | error.innerHTML = list.innerHTML = '' |
121 | liquid.style.width = '0%' |
122 | return prog |
123 | } |
124 | |
125 | return prog |
126 | } |
127 | |
128 | |
129 | |
130 | |
131 | |
132 | |
133 | },{}],4:[function(require,module,exports){ |
134 | var SecureUrl = require('./fetch') |
135 | var u = require('./util') |
136 | |
137 | module.exports = function (prefix, store, log) { |
138 | var appname = prefix |
139 | var wb, running = false |
140 | |
141 | //destroy everything |
142 | function scorchedEarth () { |
143 | for(var k in localStorage) { |
144 | delete localStorage[k] |
145 | } |
146 | } |
147 | function onProgress (ev) { |
148 | wb.onprogress && wb.onprogress(ev) |
149 | } |
150 | |
151 | var init = '#'+appname+'_INIT' |
152 | |
153 | return wb = { |
154 | scorchedEarth: scorchedEarth, |
155 | isInit: function () { |
156 | return location.hash.substring(0, init.length) === init |
157 | }, |
158 | setup: function () { |
159 | if(!wb.isInit()) |
160 | location.hash = init + location.hash |
161 | location.reload() |
162 | }, |
163 | reinitialize: function (cb) { |
164 | delete localStorage[appname+'_current'] |
165 | store.destroy(cb) |
166 | }, |
167 | install: function (url, cb) { |
168 | onProgress('installing from:'+url) |
169 | var id = SecureUrl.isSecureUrl(url) |
170 | if(!id) return cb(new Error('not a secure url:'+url)) |
171 | //check whether we already have this |
172 | //before downloading anything |
173 | store.get(id, function (err, data) { |
174 | if(!err) return cb(null, data, id) |
175 | SecureUrl(url, function (err, data, id) { |
176 | if(err) cb(err) |
177 | else store.add(data, id, function (err) { |
178 | cb(err, data, id) |
179 | }) |
180 | }) |
181 | }) |
182 | }, |
183 | installAndRun(url, cb) { |
184 | wb.install(url, function (err, _, id) { |
185 | if(err) cb(err) |
186 | else wb.run(id, cb) |
187 | }) |
188 | }, |
189 | add: store.add, |
190 | run: function (id, cb) { |
191 | if(!id) return cb(new Error('WebBoot.run: id must be provided')) |
192 | var _id |
193 | //if we are already running, restart |
194 | //clear out init code, if we are in setup mode |
195 | if(wb.isInit()) |
196 | location.hash = location.hash.substring(init.length) |
197 | |
198 | log.head(function (err, data) { |
199 | if(err) return cb(err) |
200 | if(data) _id = data.value |
201 | if(_id === id) |
202 | run(id) |
203 | else |
204 | log.append(id, function (err) { |
205 | if(err) return cb(err) |
206 | run(id) |
207 | }) |
208 | }) |
209 | |
210 | function run (id) { |
211 | if(running) { |
212 | //reload, and then the current version will trigger. |
213 | cb() |
214 | location.reload() |
215 | } |
216 | else |
217 | store.get(id, function (err, data) { |
218 | if(err) return cb(err) |
219 | var script = document.createElement('script') |
220 | running = true |
221 | document.body.innerHTML = '' |
222 | script.textContent = u.toUtf8(data) |
223 | document.head.appendChild(script) //run javascript. |
224 | cb() |
225 | }) |
226 | } |
227 | }, |
228 | size: function (cb) { |
229 | store.ls(function (err, ls) { |
230 | if(err) cb(err) |
231 | else cb(null, ls.reduce(function (total, item) { |
232 | return total + item.size |
233 | }, 0)) |
234 | }) |
235 | }, |
236 | //clear target amount of space. |
237 | prune: function (target, cb) { |
238 | if(!target) return cb(new Error('WebBoot.prune: size to clear must be provided')) |
239 | var cleared = 0, remove = [] |
240 | |
241 | function clear () { |
242 | var n = remove.length |
243 | while(remove.length) store.rm(remove.shift(), function () { |
244 | if(--n) return |
245 | if(cleared < target) |
246 | cb(new Error('could not clear requested space'), cleared) |
247 | else |
248 | cb(null, cleared) |
249 | }) |
250 | } |
251 | |
252 | store.ls(function (err, ls) { |
253 | if(err) return cb(err) |
254 | log.unfiltered(function (err, unfiltered) { |
255 | var stored = unfiltered.reverse() |
256 | for(var i = 0; i < stored.length; i++) { |
257 | var id = stored[i].value |
258 | var item = ls.find(function (e) { |
259 | return e.id === id |
260 | }) |
261 | |
262 | if(item) { |
263 | cleared += item.size |
264 | remove.push(id) |
265 | if(cleared >= target) return clear() |
266 | } |
267 | } |
268 | clear() |
269 | }) |
270 | }) |
271 | }, |
272 | |
273 | version: require('./package.json').version, |
274 | remove: store.rm, |
275 | has: store.has, |
276 | versions: function (cb) { |
277 | log.filtered(function (err, ls) { |
278 | if(err) return cb(err) |
279 | else if(ls.length) cb(null, ls) |
280 | else { |
281 | console.log('restore from legacy log...') |
282 | var versions = u.parse(localStorage[appname+'_versions']) |
283 | var n = Object.keys(versions).length |
284 | for(var ts in versions) { |
285 | log.append(versions[ts], function () { |
286 | if(--n) return |
287 | //try again |
288 | log.filtered(cb) |
289 | }) |
290 | } |
291 | } |
292 | }) |
293 | }, |
294 | history: log.unfiltered, |
295 | current: log.head, |
296 | append: log.append, |
297 | revert: log.revert, |
298 | onprogress: null |
299 | } |
300 | } |
301 | |
302 | |
303 | |
304 | |
305 | |
306 | |
307 | },{"./fetch":5,"./package.json":17,"./util":20}],5:[function(require,module,exports){ |
308 | var BinaryXHR = require('binary-xhr') |
309 | var hasHash = /([A-Za-z0-9\/+]{43}=)\.sha256/ |
310 | var isUrl = /^https?:\/\// |
311 | |
312 | var u = require('./util') |
313 | |
314 | //before calling this, always check whether you alread have |
315 | //a file with this hash. |
316 | exports = module.exports = function (url, cb) { |
317 | var id = exports.isSecureUrl(secure_url) |
318 | if(!id) |
319 | return cb(new Error('is not a secure url:'+secure_url)) |
320 | |
321 | BinaryXHR(secure_url, function (err, data) { |
322 | if(err) |
323 | return cb(new Error('could not retrive secure url:'+err)) |
324 | if(!data || !data.length) |
325 | return cb(new Error('empty response from: '+secure_url)) |
326 | u.hash(data, function (err, _id) { |
327 | if(_id !== id) cb(u.HashError(_id, id)) |
328 | |
329 | cb(null, data, id) |
330 | }) |
331 | }) |
332 | } |
333 | |
334 | exports.isSecureUrl = function (string) { |
335 | var h = hasHash.exec(string) |
336 | return isUrl.test(string) && h && h[1] |
337 | } |
338 | |
339 | |
340 | |
341 | },{"./util":20,"binary-xhr":9}],6:[function(require,module,exports){ |
342 | |
343 | |
344 | var appname = 'SWB' |
345 | var store = require('./store')(appname, localStorage) |
346 | var log = require('./log')(appname, localStorage) |
347 | var wb = window.WebBoot = require('./bootloader')(appname, store, log) |
348 | |
349 | //minimal user interface... |
350 | require('./ui')(appname, wb) |
351 | |
352 | |
353 | },{"./bootloader":4,"./log":7,"./store":18,"./ui":19}],7:[function(require,module,exports){ |
354 | var u = require('./util') |
355 | |
356 | /* |
357 | this uses localStorage, so it doesn't need async, |
358 | but i used async api anyway, |
359 | so it will be easy to switch to indexeddb. |
360 | */ |
361 | |
362 | module.exports = function (prefix, storage) { |
363 | //pass in non-local storage, to make testing easy. |
364 | storage = storage || localStorage |
365 | var log |
366 | function _append (data, cb) { |
367 | var log = u.parse(storage[prefix]) || [] |
368 | log.unshift(data) |
369 | storage[prefix] = JSON.stringify(log) |
370 | cb(null, data) |
371 | } |
372 | |
373 | function filtered (log) { |
374 | var revert = null |
375 | var output = [] |
376 | for(var i = 0; i < log.length; i++) { |
377 | var item = log[i] |
378 | if(revert && revert <= item.ts) //this op was reverted. |
379 | ; |
380 | else if(item.revert) |
381 | revert = item.revert |
382 | else |
383 | output.push(item) |
384 | } |
385 | return output |
386 | } |
387 | |
388 | function getLog() { |
389 | return u.parse(storage[prefix]) || [] |
390 | } |
391 | |
392 | return log = { |
393 | head: function (cb) { |
394 | cb(null, filtered(getLog())[0]) |
395 | }, |
396 | filtered: function (cb) { |
397 | cb(null, filtered(getLog())) |
398 | }, |
399 | unfiltered: function (cb) { |
400 | cb(null, getLog()) |
401 | }, |
402 | append: function (data, cb) { |
403 | _append({value: data, ts: Date.now()}, cb) |
404 | }, |
405 | revert: function (ts, cb) { |
406 | if(!ts) return cb(new Error('log.revert: must provide ts to revert to')) |
407 | _append({revert: ts, ts: Date.now()}, function (err) { |
408 | if(err) cb(err) |
409 | else cb(null, filtered(getLog())[0]) |
410 | }) |
411 | } |
412 | } |
413 | } |
414 | |
415 | |
416 | |
417 | },{"./util":20}],8:[function(require,module,exports){ |
418 | module.exports = function ToBase64(buf) { |
419 | buf = new Uint8Array(buf) |
420 | var s = '' |
421 | for(var i = 0; i < buf.byteLength; i++) |
422 | s+=String.fromCharCode(buf[i]) |
423 | return btoa(s) |
424 | } |
425 | |
426 | |
427 | },{}],9:[function(require,module,exports){ |
428 | var inherits = require('inherits') |
429 | |
430 | module.exports = function(url, cb) { |
431 | return new BinaryXHR(url, cb) |
432 | } |
433 | |
434 | function BinaryXHR(url, cb) { |
435 | var self = this |
436 | var xhr = new XMLHttpRequest() |
437 | this.xhr = xhr |
438 | xhr.open("GET", url, true) |
439 | xhr.responseType = 'arraybuffer' |
440 | xhr.onreadystatechange = function () { |
441 | XHR = xhr |
442 | if (self.xhr.readyState === 4) { |
443 | if (self.xhr.status !== 200) { |
444 | cb(self.xhr.status, self.xhr.response); |
445 | } else if (self.xhr.response && self.xhr.response.byteLength > 0) { |
446 | cb(false, self.xhr.response) |
447 | } else { |
448 | if (self.xhr.response && self.xhr.response.byteLength === 0) return cb('response length 0') |
449 | cb('no response') |
450 | } |
451 | } |
452 | } |
453 | xhr.send(null) |
454 | } |
455 | |
456 | },{"inherits":13}],10:[function(require,module,exports){ |
457 | |
458 | },{}],11:[function(require,module,exports){ |
459 | arguments[4][2][0].apply(exports,arguments) |
460 | },{"dup":2}],12:[function(require,module,exports){ |
461 | /** |
462 | * Print a human readable timestamp to the terminal |
463 | * given a number representing seconds |
464 | * |
465 | * Author: Dave Eddy <dave@daveeddy.com> |
466 | * Date: 8/18/2014 |
467 | * License: MIT |
468 | */ |
469 | |
470 | var util = require('util'); |
471 | |
472 | module.exports = human; |
473 | |
474 | function human(seconds) { |
475 | if (seconds instanceof Date) |
476 | seconds = Math.round((Date.now() - seconds) / 1000); |
477 | var suffix = seconds < 0 ? 'from now' : 'ago'; |
478 | seconds = Math.abs(seconds); |
479 | |
480 | var times = [ |
481 | seconds / 60 / 60 / 24 / 365, // years |
482 | seconds / 60 / 60 / 24 / 30, // months |
483 | seconds / 60 / 60 / 24 / 7, // weeks |
484 | seconds / 60 / 60 / 24, // days |
485 | seconds / 60 / 60, // hours |
486 | seconds / 60, // minutes |
487 | seconds // seconds |
488 | ]; |
489 | var names = ['year', 'month', 'week', 'day', 'hour', 'minute', 'second']; |
490 | |
491 | for (var i = 0; i < names.length; i++) { |
492 | var time = Math.floor(times[i]); |
493 | if (time > 1) |
494 | return util.format('%d %ss %s', time, names[i], suffix); |
495 | else if (time === 1) |
496 | return util.format('%d %s %s', time, names[i], suffix); |
497 | } |
498 | return util.format('0 seconds %s', suffix); |
499 | } |
500 | |
501 | },{"util":16}],13:[function(require,module,exports){ |
502 | module.exports = inherits |
503 | |
504 | function inherits (c, p, proto) { |
505 | proto = proto || {} |
506 | var e = {} |
507 | ;[c.prototype, proto].forEach(function (s) { |
508 | Object.getOwnPropertyNames(s).forEach(function (k) { |
509 | e[k] = Object.getOwnPropertyDescriptor(s, k) |
510 | }) |
511 | }) |
512 | c.prototype = Object.create(p.prototype, e) |
513 | c.super = p |
514 | } |
515 | |
516 | //function Child () { |
517 | // Child.super.call(this) |
518 | // console.error([this |
519 | // ,this.constructor |
520 | // ,this.constructor === Child |
521 | // ,this.constructor.super === Parent |
522 | // ,Object.getPrototypeOf(this) === Child.prototype |
523 | // ,Object.getPrototypeOf(Object.getPrototypeOf(this)) |
524 | // === Parent.prototype |
525 | // ,this instanceof Child |
526 | // ,this instanceof Parent]) |
527 | //} |
528 | //function Parent () {} |
529 | //inherits(Child, Parent) |
530 | //new Child |
531 | |
532 | },{}],14:[function(require,module,exports){ |
533 | if (typeof Object.create === 'function') { |
534 | // implementation from standard node.js 'util' module |
535 | module.exports = function inherits(ctor, superCtor) { |
536 | ctor.super_ = superCtor |
537 | ctor.prototype = Object.create(superCtor.prototype, { |
538 | constructor: { |
539 | value: ctor, |
540 | enumerable: false, |
541 | writable: true, |
542 | configurable: true |
543 | } |
544 | }); |
545 | }; |
546 | } else { |
547 | // old school shim for old browsers |
548 | module.exports = function inherits(ctor, superCtor) { |
549 | ctor.super_ = superCtor |
550 | var TempCtor = function () {} |
551 | TempCtor.prototype = superCtor.prototype |
552 | ctor.prototype = new TempCtor() |
553 | ctor.prototype.constructor = ctor |
554 | } |
555 | } |
556 | |
557 | },{}],15:[function(require,module,exports){ |
558 | module.exports = function isBuffer(arg) { |
559 | return arg && typeof arg === 'object' |
560 | && typeof arg.copy === 'function' |
561 | && typeof arg.fill === 'function' |
562 | && typeof arg.readUInt8 === 'function'; |
563 | } |
564 | },{}],16:[function(require,module,exports){ |
565 | // Copyright Joyent, Inc. and other Node contributors. |
566 | // |
567 | // Permission is hereby granted, free of charge, to any person obtaining a |
568 | // copy of this software and associated documentation files (the |
569 | // "Software"), to deal in the Software without restriction, including |
570 | // without limitation the rights to use, copy, modify, merge, publish, |
571 | // distribute, sublicense, and/or sell copies of the Software, and to permit |
572 | // persons to whom the Software is furnished to do so, subject to the |
573 | // following conditions: |
574 | // |
575 | // The above copyright notice and this permission notice shall be included |
576 | // in all copies or substantial portions of the Software. |
577 | // |
578 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
579 | // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
580 | // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN |
581 | // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
582 | // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
583 | // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE |
584 | // USE OR OTHER DEALINGS IN THE SOFTWARE. |
585 | |
586 | var formatRegExp = /%[sdj%]/g; |
587 | exports.format = function(f) { |
588 | if (!isString(f)) { |
589 | var objects = []; |
590 | for (var i = 0; i < arguments.length; i++) { |
591 | objects.push(inspect(arguments[i])); |
592 | } |
593 | return objects.join(' '); |
594 | } |
595 | |
596 | var i = 1; |
597 | var args = arguments; |
598 | var len = args.length; |
599 | var str = String(f).replace(formatRegExp, function(x) { |
600 | if (x === '%%') return '%'; |
601 | if (i >= len) return x; |
602 | switch (x) { |
603 | case '%s': return String(args[i++]); |
604 | case '%d': return Number(args[i++]); |
605 | case '%j': |
606 | try { |
607 | return JSON.stringify(args[i++]); |
608 | } catch (_) { |
609 | return '[Circular]'; |
610 | } |
611 | default: |
612 | return x; |
613 | } |
614 | }); |
615 | for (var x = args[i]; i < len; x = args[++i]) { |
616 | if (isNull(x) || !isObject(x)) { |
617 | str += ' ' + x; |
618 | } else { |
619 | str += ' ' + inspect(x); |
620 | } |
621 | } |
622 | return str; |
623 | }; |
624 | |
625 | |
626 | // Mark that a method should not be used. |
627 | // Returns a modified function which warns once by default. |
628 | // If --no-deprecation is set, then it is a no-op. |
629 | exports.deprecate = function(fn, msg) { |
630 | // Allow for deprecating things in the process of starting up. |
631 | if (isUndefined(global.process)) { |
632 | return function() { |
633 | return exports.deprecate(fn, msg).apply(this, arguments); |
634 | }; |
635 | } |
636 | |
637 | if (process.noDeprecation === true) { |
638 | return fn; |
639 | } |
640 | |
641 | var warned = false; |
642 | function deprecated() { |
643 | if (!warned) { |
644 | if (process.throwDeprecation) { |
645 | throw new Error(msg); |
646 | } else if (process.traceDeprecation) { |
647 | console.trace(msg); |
648 | } else { |
649 | console.error(msg); |
650 | } |
651 | warned = true; |
652 | } |
653 | return fn.apply(this, arguments); |
654 | } |
655 | |
656 | return deprecated; |
657 | }; |
658 | |
659 | |
660 | var debugs = {}; |
661 | var debugEnviron; |
662 | exports.debuglog = function(set) { |
663 | if (isUndefined(debugEnviron)) |
664 | debugEnviron = process.env.NODE_DEBUG || ''; |
665 | set = set.toUpperCase(); |
666 | if (!debugs[set]) { |
667 | if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) { |
668 | var pid = process.pid; |
669 | debugs[set] = function() { |
670 | var msg = exports.format.apply(exports, arguments); |
671 | console.error('%s %d: %s', set, pid, msg); |
672 | }; |
673 | } else { |
674 | debugs[set] = function() {}; |
675 | } |
676 | } |
677 | return debugs[set]; |
678 | }; |
679 | |
680 | |
681 | /** |
682 | * Echos the value of a value. Trys to print the value out |
683 | * in the best way possible given the different types. |
684 | * |
685 | * @param {Object} obj The object to print out. |
686 | * @param {Object} opts Optional options object that alters the output. |
687 | */ |
688 | /* legacy: obj, showHidden, depth, colors*/ |
689 | function inspect(obj, opts) { |
690 | // default options |
691 | var ctx = { |
692 | seen: [], |
693 | stylize: stylizeNoColor |
694 | }; |
695 | // legacy... |
696 | if (arguments.length >= 3) ctx.depth = arguments[2]; |
697 | if (arguments.length >= 4) ctx.colors = arguments[3]; |
698 | if (isBoolean(opts)) { |
699 | // legacy... |
700 | ctx.showHidden = opts; |
701 | } else if (opts) { |
702 | // got an "options" object |
703 | exports._extend(ctx, opts); |
704 | } |
705 | // set default options |
706 | if (isUndefined(ctx.showHidden)) ctx.showHidden = false; |
707 | if (isUndefined(ctx.depth)) ctx.depth = 2; |
708 | if (isUndefined(ctx.colors)) ctx.colors = false; |
709 | if (isUndefined(ctx.customInspect)) ctx.customInspect = true; |
710 | if (ctx.colors) ctx.stylize = stylizeWithColor; |
711 | return formatValue(ctx, obj, ctx.depth); |
712 | } |
713 | exports.inspect = inspect; |
714 | |
715 | |
716 | // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics |
717 | inspect.colors = { |
718 | 'bold' : [1, 22], |
719 | 'italic' : [3, 23], |
720 | 'underline' : [4, 24], |
721 | 'inverse' : [7, 27], |
722 | 'white' : [37, 39], |
723 | 'grey' : [90, 39], |
724 | 'black' : [30, 39], |
725 | 'blue' : [34, 39], |
726 | 'cyan' : [36, 39], |
727 | 'green' : [32, 39], |
728 | 'magenta' : [35, 39], |
729 | 'red' : [31, 39], |
730 | 'yellow' : [33, 39] |
731 | }; |
732 | |
733 | // Don't use 'blue' not visible on cmd.exe |
734 | inspect.styles = { |
735 | 'special': 'cyan', |
736 | 'number': 'yellow', |
737 | 'boolean': 'yellow', |
738 | 'undefined': 'grey', |
739 | 'null': 'bold', |
740 | 'string': 'green', |
741 | 'date': 'magenta', |
742 | // "name": intentionally not styling |
743 | 'regexp': 'red' |
744 | }; |
745 | |
746 | |
747 | function stylizeWithColor(str, styleType) { |
748 | var style = inspect.styles[styleType]; |
749 | |
750 | if (style) { |
751 | return '\u001b[' + inspect.colors[style][0] + 'm' + str + |
752 | '\u001b[' + inspect.colors[style][1] + 'm'; |
753 | } else { |
754 | return str; |
755 | } |
756 | } |
757 | |
758 | |
759 | function stylizeNoColor(str, styleType) { |
760 | return str; |
761 | } |
762 | |
763 | |
764 | function arrayToHash(array) { |
765 | var hash = {}; |
766 | |
767 | array.forEach(function(val, idx) { |
768 | hash[val] = true; |
769 | }); |
770 | |
771 | return hash; |
772 | } |
773 | |
774 | |
775 | function formatValue(ctx, value, recurseTimes) { |
776 | // Provide a hook for user-specified inspect functions. |
777 | // Check that value is an object with an inspect function on it |
778 | if (ctx.customInspect && |
779 | value && |
780 | isFunction(value.inspect) && |
781 | // Filter out the util module, it's inspect function is special |
782 | value.inspect !== exports.inspect && |
783 | // Also filter out any prototype objects using the circular check. |
784 | !(value.constructor && value.constructor.prototype === value)) { |
785 | var ret = value.inspect(recurseTimes, ctx); |
786 | if (!isString(ret)) { |
787 | ret = formatValue(ctx, ret, recurseTimes); |
788 | } |
789 | return ret; |
790 | } |
791 | |
792 | // Primitive types cannot have properties |
793 | var primitive = formatPrimitive(ctx, value); |
794 | if (primitive) { |
795 | return primitive; |
796 | } |
797 | |
798 | // Look up the keys of the object. |
799 | var keys = Object.keys(value); |
800 | var visibleKeys = arrayToHash(keys); |
801 | |
802 | if (ctx.showHidden) { |
803 | keys = Object.getOwnPropertyNames(value); |
804 | } |
805 | |
806 | // IE doesn't make error fields non-enumerable |
807 | // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx |
808 | if (isError(value) |
809 | && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) { |
810 | return formatError(value); |
811 | } |
812 | |
813 | // Some type of object without properties can be shortcutted. |
814 | if (keys.length === 0) { |
815 | if (isFunction(value)) { |
816 | var name = value.name ? ': ' + value.name : ''; |
817 | return ctx.stylize('[Function' + name + ']', 'special'); |
818 | } |
819 | if (isRegExp(value)) { |
820 | return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); |
821 | } |
822 | if (isDate(value)) { |
823 | return ctx.stylize(Date.prototype.toString.call(value), 'date'); |
824 | } |
825 | if (isError(value)) { |
826 | return formatError(value); |
827 | } |
828 | } |
829 | |
830 | var base = '', array = false, braces = ['{', '}']; |
831 | |
832 | // Make Array say that they are Array |
833 | if (isArray(value)) { |
834 | array = true; |
835 | braces = ['[', ']']; |
836 | } |
837 | |
838 | // Make functions say that they are functions |
839 | if (isFunction(value)) { |
840 | var n = value.name ? ': ' + value.name : ''; |
841 | base = ' [Function' + n + ']'; |
842 | } |
843 | |
844 | // Make RegExps say that they are RegExps |
845 | if (isRegExp(value)) { |
846 | base = ' ' + RegExp.prototype.toString.call(value); |
847 | } |
848 | |
849 | // Make dates with properties first say the date |
850 | if (isDate(value)) { |
851 | base = ' ' + Date.prototype.toUTCString.call(value); |
852 | } |
853 | |
854 | // Make error with message first say the error |
855 | if (isError(value)) { |
856 | base = ' ' + formatError(value); |
857 | } |
858 | |
859 | if (keys.length === 0 && (!array || value.length == 0)) { |
860 | return braces[0] + base + braces[1]; |
861 | } |
862 | |
863 | if (recurseTimes < 0) { |
864 | if (isRegExp(value)) { |
865 | return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp'); |
866 | } else { |
867 | return ctx.stylize('[Object]', 'special'); |
868 | } |
869 | } |
870 | |
871 | ctx.seen.push(value); |
872 | |
873 | var output; |
874 | if (array) { |
875 | output = formatArray(ctx, value, recurseTimes, visibleKeys, keys); |
876 | } else { |
877 | output = keys.map(function(key) { |
878 | return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array); |
879 | }); |
880 | } |
881 | |
882 | ctx.seen.pop(); |
883 | |
884 | return reduceToSingleString(output, base, braces); |
885 | } |
886 | |
887 | |
888 | function formatPrimitive(ctx, value) { |
889 | if (isUndefined(value)) |
890 | return ctx.stylize('undefined', 'undefined'); |
891 | if (isString(value)) { |
892 | var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '') |
893 | .replace(/'/g, "\\'") |
894 | .replace(/\\"/g, '"') + '\''; |
895 | return ctx.stylize(simple, 'string'); |
896 | } |
897 | if (isNumber(value)) |
898 | return ctx.stylize('' + value, 'number'); |
899 | if (isBoolean(value)) |
900 | return ctx.stylize('' + value, 'boolean'); |
901 | // For some reason typeof null is "object", so special case here. |
902 | if (isNull(value)) |
903 | return ctx.stylize('null', 'null'); |
904 | } |
905 | |
906 | |
907 | function formatError(value) { |
908 | return '[' + Error.prototype.toString.call(value) + ']'; |
909 | } |
910 | |
911 | |
912 | function formatArray(ctx, value, recurseTimes, visibleKeys, keys) { |
913 | var output = []; |
914 | for (var i = 0, l = value.length; i < l; ++i) { |
915 | if (hasOwnProperty(value, String(i))) { |
916 | output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, |
917 | String(i), true)); |
918 | } else { |
919 | output.push(''); |
920 | } |
921 | } |
922 | keys.forEach(function(key) { |
923 | if (!key.match(/^\d+$/)) { |
924 | output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, |
925 | key, true)); |
926 | } |
927 | }); |
928 | return output; |
929 | } |
930 | |
931 | |
932 | function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { |
933 | var name, str, desc; |
934 | desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] }; |
935 | if (desc.get) { |
936 | if (desc.set) { |
937 | str = ctx.stylize('[Getter/Setter]', 'special'); |
938 | } else { |
939 | str = ctx.stylize('[Getter]', 'special'); |
940 | } |
941 | } else { |
942 | if (desc.set) { |
943 | str = ctx.stylize('[Setter]', 'special'); |
944 | } |
945 | } |
946 | if (!hasOwnProperty(visibleKeys, key)) { |
947 | name = '[' + key + ']'; |
948 | } |
949 | if (!str) { |
950 | if (ctx.seen.indexOf(desc.value) < 0) { |
951 | if (isNull(recurseTimes)) { |
952 | str = formatValue(ctx, desc.value, null); |
953 | } else { |
954 | str = formatValue(ctx, desc.value, recurseTimes - 1); |
955 | } |
956 | if (str.indexOf('\n') > -1) { |
957 | if (array) { |
958 | str = str.split('\n').map(function(line) { |
959 | return ' ' + line; |
960 | }).join('\n').substr(2); |
961 | } else { |
962 | str = '\n' + str.split('\n').map(function(line) { |
963 | return ' ' + line; |
964 | }).join('\n'); |
965 | } |
966 | } |
967 | } else { |
968 | str = ctx.stylize('[Circular]', 'special'); |
969 | } |
970 | } |
971 | if (isUndefined(name)) { |
972 | if (array && key.match(/^\d+$/)) { |
973 | return str; |
974 | } |
975 | name = JSON.stringify('' + key); |
976 | if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) { |
977 | name = name.substr(1, name.length - 2); |
978 | name = ctx.stylize(name, 'name'); |
979 | } else { |
980 | name = name.replace(/'/g, "\\'") |
981 | .replace(/\\"/g, '"') |
982 | .replace(/(^"|"$)/g, "'"); |
983 | name = ctx.stylize(name, 'string'); |
984 | } |
985 | } |
986 | |
987 | return name + ': ' + str; |
988 | } |
989 | |
990 | |
991 | function reduceToSingleString(output, base, braces) { |
992 | var numLinesEst = 0; |
993 | var length = output.reduce(function(prev, cur) { |
994 | numLinesEst++; |
995 | if (cur.indexOf('\n') >= 0) numLinesEst++; |
996 | return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1; |
997 | }, 0); |
998 | |
999 | if (length > 60) { |
1000 | return braces[0] + |
1001 | (base === '' ? '' : base + '\n ') + |
1002 | ' ' + |
1003 | output.join(',\n ') + |
1004 | ' ' + |
1005 | braces[1]; |
1006 | } |
1007 | |
1008 | return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1]; |
1009 | } |
1010 | |
1011 | |
1012 | // NOTE: These type checking functions intentionally don't use `instanceof` |
1013 | // because it is fragile and can be easily faked with `Object.create()`. |
1014 | function isArray(ar) { |
1015 | return Array.isArray(ar); |
1016 | } |
1017 | exports.isArray = isArray; |
1018 | |
1019 | function isBoolean(arg) { |
1020 | return typeof arg === 'boolean'; |
1021 | } |
1022 | exports.isBoolean = isBoolean; |
1023 | |
1024 | function isNull(arg) { |
1025 | return arg === null; |
1026 | } |
1027 | exports.isNull = isNull; |
1028 | |
1029 | function isNullOrUndefined(arg) { |
1030 | return arg == null; |
1031 | } |
1032 | exports.isNullOrUndefined = isNullOrUndefined; |
1033 | |
1034 | function isNumber(arg) { |
1035 | return typeof arg === 'number'; |
1036 | } |
1037 | exports.isNumber = isNumber; |
1038 | |
1039 | function isString(arg) { |
1040 | return typeof arg === 'string'; |
1041 | } |
1042 | exports.isString = isString; |
1043 | |
1044 | function isSymbol(arg) { |
1045 | return typeof arg === 'symbol'; |
1046 | } |
1047 | exports.isSymbol = isSymbol; |
1048 | |
1049 | function isUndefined(arg) { |
1050 | return arg === void 0; |
1051 | } |
1052 | exports.isUndefined = isUndefined; |
1053 | |
1054 | function isRegExp(re) { |
1055 | return isObject(re) && objectToString(re) === '[object RegExp]'; |
1056 | } |
1057 | exports.isRegExp = isRegExp; |
1058 | |
1059 | function isObject(arg) { |
1060 | return typeof arg === 'object' && arg !== null; |
1061 | } |
1062 | exports.isObject = isObject; |
1063 | |
1064 | function isDate(d) { |
1065 | return isObject(d) && objectToString(d) === '[object Date]'; |
1066 | } |
1067 | exports.isDate = isDate; |
1068 | |
1069 | function isError(e) { |
1070 | return isObject(e) && |
1071 | (objectToString(e) === '[object Error]' || e instanceof Error); |
1072 | } |
1073 | exports.isError = isError; |
1074 | |
1075 | function isFunction(arg) { |
1076 | return typeof arg === 'function'; |
1077 | } |
1078 | exports.isFunction = isFunction; |
1079 | |
1080 | function isPrimitive(arg) { |
1081 | return arg === null || |
1082 | typeof arg === 'boolean' || |
1083 | typeof arg === 'number' || |
1084 | typeof arg === 'string' || |
1085 | typeof arg === 'symbol' || // ES6 symbol |
1086 | typeof arg === 'undefined'; |
1087 | } |
1088 | exports.isPrimitive = isPrimitive; |
1089 | |
1090 | exports.isBuffer = require('./support/isBuffer'); |
1091 | |
1092 | function objectToString(o) { |
1093 | return Object.prototype.toString.call(o); |
1094 | } |
1095 | |
1096 | |
1097 | function pad(n) { |
1098 | return n < 10 ? '0' + n.toString(10) : n.toString(10); |
1099 | } |
1100 | |
1101 | |
1102 | var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', |
1103 | 'Oct', 'Nov', 'Dec']; |
1104 | |
1105 | // 26 Feb 16:19:34 |
1106 | function timestamp() { |
1107 | var d = new Date(); |
1108 | var time = [pad(d.getHours()), |
1109 | pad(d.getMinutes()), |
1110 | pad(d.getSeconds())].join(':'); |
1111 | return [d.getDate(), months[d.getMonth()], time].join(' '); |
1112 | } |
1113 | |
1114 | |
1115 | // log is just a thin wrapper to console.log that prepends a timestamp |
1116 | exports.log = function() { |
1117 | console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments)); |
1118 | }; |
1119 | |
1120 | |
1121 | /** |
1122 | * Inherit the prototype methods from one constructor into another. |
1123 | * |
1124 | * The Function.prototype.inherits from lang.js rewritten as a standalone |
1125 | * function (not on Function.prototype). NOTE: If this file is to be loaded |
1126 | * during bootstrapping this function needs to be rewritten using some native |
1127 | * functions as prototype setup using normal JavaScript does not work as |
1128 | * expected during bootstrapping (see mirror.js in r114903). |
1129 | * |
1130 | * @param {function} ctor Constructor function which needs to inherit the |
1131 | * prototype. |
1132 | * @param {function} superCtor Constructor function to inherit prototype from. |
1133 | */ |
1134 | exports.inherits = require('inherits'); |
1135 | |
1136 | exports._extend = function(origin, add) { |
1137 | // Don't do anything if add isn't an object |
1138 | if (!add || !isObject(add)) return origin; |
1139 | |
1140 | var keys = Object.keys(add); |
1141 | var i = keys.length; |
1142 | while (i--) { |
1143 | origin[keys[i]] = add[keys[i]]; |
1144 | } |
1145 | return origin; |
1146 | }; |
1147 | |
1148 | function hasOwnProperty(obj, prop) { |
1149 | return Object.prototype.hasOwnProperty.call(obj, prop); |
1150 | } |
1151 | |
1152 | },{"./support/isBuffer":15,"inherits":14}],17:[function(require,module,exports){ |
1153 | module.exports={ |
1154 | "name": "web-bootloader", |
1155 | "description": "", |
1156 | "version": "1.0.2", |
1157 | "homepage": "https://github.com/dominictarr/web-bootloader", |
1158 | "repository": { |
1159 | "type": "git", |
1160 | "url": "git://github.com/dominictarr/web-bootloader.git" |
1161 | }, |
1162 | "devDependencies": { |
1163 | "arraybuffer-base64": "^1.0.0", |
1164 | "binary-xhr": "0.0.2", |
1165 | "browserify": "^13.0.1", |
1166 | "hyperfile": "^1.1.1", |
1167 | "hyperprogress": "^0.1.1", |
1168 | "indexhtmlify": "^1.3.0", |
1169 | "tape": "^4.6.0" |
1170 | }, |
1171 | "browser": { |
1172 | "./_util": false |
1173 | }, |
1174 | "scripts": { |
1175 | "test": "set -e; for t in test/*.js; do node $t; done", |
1176 | "build": "browserify index.js --igv , | indexhtmlify --appcache > index.html && node handler/cache.js > manifest.appcache", |
1177 | "gh-pages": "git checkout master && git branch -D gh-pages ; git checkout -b gh-pages && git push origin gh-pages; git checkout master" |
1178 | }, |
1179 | "author": "'Dominic Tarr' <dominic.tarr@gmail.com> (dominictarr.com)", |
1180 | "license": "MIT", |
1181 | "dependencies": { |
1182 | "hscrpt": "0.0.1", |
1183 | "human-time": "0.0.1" |
1184 | } |
1185 | } |
1186 | |
1187 | },{}],18:[function(require,module,exports){ |
1188 | var u = require('./util') |
1189 | |
1190 | module.exports = function (prefix, storage) { |
1191 | return { |
1192 | get: function (id, cb) { |
1193 | var data = ( |
1194 | storage[prefix+'_versions_'+id] || storage[prefix+'_version_'+id] |
1195 | ) |
1196 | if(data) |
1197 | u.hash(data, function (err, _id) { |
1198 | if(err) cb(err) |
1199 | else if(_id !== id) cb(u.HashError(_id, id)) |
1200 | else cb(null, data) |
1201 | }) |
1202 | else cb(new Error('not found:'+id)) |
1203 | }, |
1204 | |
1205 | add: function (data, id, cb) { |
1206 | if(!cb) cb = id, id = null |
1207 | u.hash(data, function (err, _id) { |
1208 | if(err) cb(err) |
1209 | else if(id && _id !== id) cb(u.HashError(_id, id)) |
1210 | else { |
1211 | try { |
1212 | storage[prefix+'_versions_'+_id] = u.toUtf8(data) |
1213 | } |
1214 | catch(err) { return cb(err) } //this will be quota error |
1215 | cb(null, _id) |
1216 | } |
1217 | }) |
1218 | }, |
1219 | |
1220 | has: function (id, cb) { |
1221 | return cb(null, |
1222 | !!storage[prefix+'_versions_'+id] || |
1223 | !!storage[prefix+'_version_'+id] //legacy |
1224 | ) |
1225 | }, |
1226 | |
1227 | rm: function (id, cb) { |
1228 | delete storage[prefix+'_versions_'+id] |
1229 | |
1230 | cb() |
1231 | }, |
1232 | |
1233 | |
1234 | ls: function (cb) { |
1235 | var match = new RegExp('^'+prefix+'_versions_'), ary = [] |
1236 | for(var key in storage) { |
1237 | if(match.test(key)) { |
1238 | var data = storage[key] |
1239 | ary.push({ |
1240 | id: key.replace(match, ''), |
1241 | size: data && data.length || 0 |
1242 | }) |
1243 | } |
1244 | } |
1245 | cb(null, ary) |
1246 | }, |
1247 | |
1248 | destroy: function (cb) { |
1249 | var match = new RegExp('^'+prefix+'_versions_') |
1250 | for(var key in storage) { |
1251 | if(match.test(key)) { |
1252 | delete storage[key] |
1253 | } |
1254 | } |
1255 | |
1256 | cb() |
1257 | } |
1258 | } |
1259 | } |
1260 | |
1261 | |
1262 | |
1263 | |
1264 | |
1265 | |
1266 | |
1267 | |
1268 | |
1269 | |
1270 | |
1271 | |
1272 | |
1273 | |
1274 | |
1275 | |
1276 | |
1277 | },{"./util":20}],19:[function(require,module,exports){ |
1278 | var h = require('hscrpt') |
1279 | var input_file = require('hyperfile') |
1280 | var Progress = require('hyperprogress') |
1281 | var u = require('./util') |
1282 | var prog = Progress() |
1283 | |
1284 | //split the hash. |
1285 | var parts = window.location.hash.split('#').slice(1) |
1286 | var QUOTA = 5*1024*1024 |
1287 | |
1288 | var human = require('human-time') |
1289 | |
1290 | module.exports = function (appname, wb) { |
1291 | document.body.appendChild(prog) |
1292 | |
1293 | function nice_error(err, msg) { |
1294 | if(err.name && err.message && err.stack) |
1295 | return err |
1296 | if('object' !== typeof err) |
1297 | return new Error(msg+JSON.stringify(err)) |
1298 | } |
1299 | |
1300 | function btn (label, action) { |
1301 | return h('button', {onclick: action}, [label]) |
1302 | } |
1303 | |
1304 | function kb (bytes) { |
1305 | return (Math.round((bytes / 1024) * 100)/100) + 'k' |
1306 | } |
1307 | |
1308 | // var isElectron = typeof process !== 'undefined' |
1309 | // && process.env && process.env[appname+'_INIT'] |
1310 | |
1311 | function handleQuota(err, data, id) { |
1312 | if(err |
1313 | && err.name == "QuotaExceededError" |
1314 | && confirm ('adding: '+id+' exceedes quota, clear cache?') |
1315 | ) { |
1316 | wb.prune(data.length, function (err) { |
1317 | if(err) throw prog.fail(err) |
1318 | wb.add(data, id, function (err) { |
1319 | if(err) throw prog.fail(err) |
1320 | wb.run(id, function (err) { |
1321 | if(err) throw prog.fail(err) |
1322 | }) |
1323 | }) |
1324 | }) |
1325 | } |
1326 | else if(!err) wb.run(id, function (err) { |
1327 | if(err) throw prog.fail(err) |
1328 | }) |
1329 | else |
1330 | throw prog.fail(err) |
1331 | } |
1332 | |
1333 | ;(function redraw () { |
1334 | wb.versions(function (err, log) { |
1335 | if(err) throw prog.fail(err) |
1336 | document.body.innerHTML = '' |
1337 | if(log.length && !wb.isInit()) |
1338 | return wb.run(log[0].value, function (err) { |
1339 | if(err) throw prog.fail(err) |
1340 | }) |
1341 | |
1342 | document.body.appendChild( |
1343 | h('div', {classList: 'WebBoot'}, [ |
1344 | ( !log.length |
1345 | ? h('h2', 'please enter secure-url or select file to run') |
1346 | : h('ol', {classList: 'WebBoot__recent'}, log.map(function (v) { |
1347 | return h('li', [ |
1348 | h('code', [v.value]), |
1349 | h('label', |
1350 | { title: new Date(v.ts).toString() }, |
1351 | [ ' (loaded ', human(new Date(v.ts)), ') '] |
1352 | ), |
1353 | h('div', [ |
1354 | btn('run', function () { |
1355 | wb.run(v.value) |
1356 | }), |
1357 | btn('revert', function () { |
1358 | wb.revert(v.ts, function (err) { |
1359 | if(err) throw prog.fail(err) |
1360 | redraw() |
1361 | }) |
1362 | }) |
1363 | ]) |
1364 | ]) |
1365 | })) |
1366 | ), |
1367 | |
1368 | //paste a secure url into this text input |
1369 | h('input', { |
1370 | placeholder: 'enter secure url', |
1371 | onchange: function (ev) { |
1372 | //else, download it. if that succeeds, |
1373 | //add to store, if success, run. |
1374 | //if that fails, offer to clean up, or fail. |
1375 | //add to store, if success, run. |
1376 | |
1377 | //this can fail from quota exceeded. |
1378 | //check whether we have this already, if so, run it. |
1379 | var url = ev.target.value |
1380 | |
1381 | wb.install(url, handleQuota) |
1382 | } |
1383 | }), |
1384 | |
1385 | //or select a local file to run |
1386 | input_file(function (data) { |
1387 | wb.add(data, function (err, id) { |
1388 | handleQuota(err, data, id) |
1389 | }) |
1390 | }) |
1391 | ]) |
1392 | ) |
1393 | }) |
1394 | })() |
1395 | |
1396 | } |
1397 | |
1398 | |
1399 | |
1400 | |
1401 | |
1402 | |
1403 | |
1404 | |
1405 | |
1406 | |
1407 | |
1408 | |
1409 | |
1410 | |
1411 | },{"./util":20,"hscrpt":11,"human-time":12,"hyperfile":1,"hyperprogress":3}],20:[function(require,module,exports){ |
1412 | //attempt to load node version. |
1413 | u = require('./_util') |
1414 | if(u.parse) return module.exports = u, console.log("loaded node version for testing") |
1415 | |
1416 | var decoder = new TextDecoder('utf8') |
1417 | var encoder = new TextEncoder('utf8') |
1418 | var u = exports |
1419 | |
1420 | u.toUtf8 = function (data) { |
1421 | return 'string' == typeof data ? data : decoder.decode(data) |
1422 | } |
1423 | |
1424 | u.toBuffer = function (data) { |
1425 | return 'string' !== typeof data |
1426 | ? data |
1427 | : new Uint8Array(encoder.encode(data)) |
1428 | } |
1429 | |
1430 | u.toBase64 = require('arraybuffer-base64') |
1431 | |
1432 | u.hash = function (data, cb) { |
1433 | window.crypto.subtle.digest( |
1434 | { name: "SHA-256" }, |
1435 | u.toBuffer(data) |
1436 | ) |
1437 | .then(function(hash){ |
1438 | return cb(null, exports.toBase64(new Uint8Array(hash))) |
1439 | }) |
1440 | .catch(function(err){ |
1441 | cb(err) |
1442 | }) |
1443 | } |
1444 | |
1445 | u.parse = function (str) { |
1446 | try { |
1447 | return JSON.parse(str) |
1448 | } catch (_) { } |
1449 | } |
1450 | |
1451 | u.HashError = function (_id, id) { |
1452 | return new Error('incorrect hash:'+_id+'\n expected:'+id) |
1453 | } |
1454 | |
1455 | |
1456 | |
1457 | |
1458 | |
1459 | |
1460 | |
1461 | |
1462 | |
1463 | |
1464 | |
1465 | |
1466 | |
1467 | |
1468 | },{"./_util":10,"arraybuffer-base64":8}]},{},[6]); |
1469 | </script> |
1470 | </html> |
1471 |
Built with git-ssb-web