-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgithelp.js
89 lines (79 loc) · 3.29 KB
/
githelp.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
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
var GitHelp = new function() {
var navhist = [];
var page = document.getElementById("help-page");
var sidebar = document.getElementById("help-sidebar");
var sconverter = new showdown.Converter();
sconverter.setFlavor("github");
baseUrl = location.protocol + "//" + location.host + location.pathname;
if (baseUrl.endsWith("/index.html")) {
baseUrl = baseUrl.replace("/index.html", "");
}
if (baseUrl.endsWith("/")) {
baseUrl = baseUrl.slice(0, -1);
}
function fixlinks(div, project) {
var a = div.getElementsByTagName("a");
for (var i=0; i < a.length; i++) {
if (a[i].href) {
var href = a[i].href;
if (href.startsWith("https://github.com") && href.includes("/wiki/")) {
href = href.replace("/wiki/", "/");
href = href.replace("github.com", "raw.githubusercontent.com/wiki") + ".md";
a[i].href = "javascript:GitHelp.wikinav('" + href + "')";
}
else if (href.startsWith("#") || href.startsWith(baseUrl + "/index.html#")) {
// do nothing
}
else if (href.startsWith(baseUrl + "#") || href.startsWith(baseUrl + "/#")) {
a[i].href = href.substring(href.indexOf("#"));
}
else if (href.startsWith(baseUrl + "?") ||
href.startsWith(baseUrl + "/?") ||
href.startsWith(baseUrl + "/index.html?")) {
a[i].target = "_blank";
}
else if (href.startsWith(baseUrl + "/")) {
href = href.replace(baseUrl + "/", "");
href = "https://raw.githubusercontent.com/wiki/" + project + "/" + href + ".md";
a[i].href = "javascript:GitHelp.wikinav('" + href + "')";
}
else {
a[i].target = "_blank";
}
}
}
}
this.navhome = function() {
navhist = [];
this.wikinav("https://raw.githubusercontent.com/wiki/boxgaming/qbjs/QBasic-Language-Support.md");
return false;
};
this.navback = function() {
if (navhist.length > 1) {
navhist.pop();
var prev = navhist.pop();
this.wikinav(prev);
}
return false;
};
this.navto = function(id) {
document.getElementById(id).scrollIntoView();
};
this.wikinav = async function(url) {
var project;
var pageName;
var res = await QB.func_Fetch(url);
navhist.push(url);
page.scrollTop = 0;
project = url.replace("https://raw.githubusercontent.com/wiki/", "");
project = project.substring(0, project.lastIndexOf("/"));
pageName = url.substring(url.lastIndexOf("/")+1);
pageName = pageName.replaceAll("-", " ");
pageName = pageName.replace(".md", "");
page.innerHTML = "<h1>" + pageName + "</h1>" + sconverter.makeHtml(res.text);
fixlinks(page, project);
res = await QB.func_Fetch("https://raw.githubusercontent.com/wiki/" + project + "/_Sidebar.md");
sidebar.innerHTML = sconverter.makeHtml(res.text);
fixlinks(sidebar, project);
}
};