-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
53 lines (41 loc) · 1.52 KB
/
script.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
function IsYouTubeLink(text){
return text.includes('youtube') || text.includes('youtu.be');
}
function IsTwitchLink(text){
return text.includes('twitch.tv');
}
function ProcessNewLines(text){
return text.replace(/(?:\r\n|\r|\n)/g, ' <br/>');
}
function ProcessLinks(text){
var newText = text;
var result = URI.withinString(text, function(url){
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="720" height="400" src=' + newUrl + '></iframe>');
}else if(IsTwitchLink(url) && !url.includes('/p/')){
console.log(url);
var newURL = url.substring(url.lastIndexOf('/') + 1);
console.log(newURL);
newText = newText.replace(url, '<iframe width="720" height="400" src=https://player.twitch.tv/?video=' + newURL + '&autoplay=false></iframe>');
}
});
return newText;
}
function run(fileName){
var target = document.getElementById('targetDiv');
var converter = new showdown.Converter();
jQuery.get('https://raw.githubusercontent.com/ArkhamSpeedrunningWiki/ArkhamSpeedrunningWiki.github.io/master/' + fileName, function(data){
data = ProcessLinks(data);
data = ProcessNewLines(data);
target.innerHTML = converter.makeHtml(data);
});
}