-
Notifications
You must be signed in to change notification settings - Fork 1
/
page.js
77 lines (61 loc) · 2.25 KB
/
page.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
function IsYouTubeLink(text){
return text.includes("youtube") || text.includes("youtu.be");
}
function IsTwitchLink(text){
return text.includes("twitch.tv");
}
function ProcessLinks(text){
var iFrameWidth = "100%";
var iFrameHeight = 415;
var newText = text;
var result = URI.withinString(text, function(url){
if(url.includes("http") && !url.includes("https")){
url.replace("http", "https");
}
if(IsYouTubeLink(url)){
var newUrl = url;
if(url.includes("&")){
newUrl = url.substr(0, url.lastIndexOf("&"));
}
if(newUrl.includes("watch?v=")){
newUrl = newUrl.replace("watch?v=", "embed/");
}else if(url.includes("youtu.be")){
newUrl = newUrl.replace("youtu.be/", "youtube.com/embed/");
}
newText = newText.replace(url, "<iframe width='" + iFrameWidth + "' height='" + iFrameHeight + "' src=" + newUrl + "></iframe>");
}else if(IsTwitchLink(url) && !url.includes("/p/")){
var newURL = url.substring(url.lastIndexOf("/") + 1);
newText = newText.replace(url, "<iframe width='" + iFrameWidth + "' height='" + iFrameHeight + "' src=https://player.twitch.tv/?video=" + newURL + "&autoplay=false></iframe>");
}
});
return newText;
}
function LoadPageMarkdown(){
var url = new URL(window.location.href);
var fileName = url.searchParams.get("page");
if(fileName === null){
return;
}
console.log(fileName);
LoadFileMarkdown(fileName);
}
function LoadFileMarkdown(fileName, embedLinks = true){
if(fileName === null){
return;
}
var target = document.getElementById("targetDiv");
var converter = new showdown.Converter();
converter.setFlavor("github");
jQuery.get("https://raw.githubusercontent.com/ArkhamSpeedrunningWiki/ArkhamSpeedrunningWiki.github.io/master/" + fileName + ".md", function(data){
if(embedLinks){
data = ProcessLinks(data); //Temporary workaround for certain pages, TODO - find a way to denote that links should not embed
}
data = converter.makeHtml(data);
target.innerHTML = "<div class=panel container>" + data + "</div>";
}).fail(function(){
target.innerHTML = "<div class=panel container>"
+ "<h2>Page not found!</h2>"
+ "<a href='index.html'>Return to home page</a>"
+ "</div>";
});
}