forked from mattgodbolt/jsbeeb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sth.js
47 lines (41 loc) · 1.48 KB
/
sth.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
"use strict";
import * as utils from './utils.js';
import $ from 'jquery';
export function StairwayToHell(onStart, onCat, onError, tape) {
var self = this;
var baseUrl = document.location.protocol + "//www.stairwaytohell.com/bbc/archive/";
if (tape) baseUrl += "tapeimages/"; else baseUrl += "diskimages/";
var catalogUrl = "reclist.php?sort=name&filter=.zip";
var catalog = [];
self.populate = function () {
onStart();
if (catalog.length === 0) {
var request = new XMLHttpRequest();
request.open("GET", baseUrl + catalogUrl, true);
request.onerror = function () {
if (onError) onError();
};
request.onload = function () {
var doc = $($.parseHTML(this.responseText, null, false));
doc.find("tr td:nth-child(3) a").each(function (_, link) {
var href = $(link).attr("href");
if (href.indexOf(".zip") > 0) catalog.push(href);
});
if (onCat) onCat(catalog);
};
request.send();
} else {
if (onCat) onCat(catalog);
}
};
self.catalog = function () {
return catalog;
};
self.fetch = function (file) {
var name = baseUrl + file;
console.log("Loading ZIP from " + name);
return utils.loadData(name).then(function (data) {
return utils.unzipDiscImage(data).data;
});
};
}