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