Skip to content

Commit 0efcc05

Browse files
committedNov 5, 2019
switched cors host and added error message
1 parent 596d2e6 commit 0efcc05

File tree

2 files changed

+51
-38
lines changed

2 files changed

+51
-38
lines changed
 

‎css/custom.css

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ html, body {
66
min-height: 100%;
77
margin-left: auto;
88
margin-right: auto;
9+
margin-top: 0;
10+
margin-bottom: 0;
911
}
1012

1113
a {
@@ -21,9 +23,9 @@ a {
2123
color: hsla(0,0%,100%,.2);
2224
font-size: 10pt;
2325
text-align: center;
26+
margin-top: 40px;
27+
margin-bottom: 30px;
2428
width: 98%;
25-
/*position: fixed;
26-
bottom: 10px;*/
2729
}
2830

2931
.name {

‎js/custom.js

+47-36
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
//val json_url = 'https://allorigins.glitch.me/get?url='
2-
const json_url = 'https://api.allorigins.win/get?url='
1+
const cors_url = 'https://cors-anywhere.herokuapp.com/'
32

43
// Query string parsing
54
function getParameterByName(name, url) {
@@ -21,48 +20,60 @@ var markdown = function(source) {
2120
return htmlOutput(parser(source + "\n\n", {inline: false}));
2221
};
2322

23+
// Document Parsing
24+
function parseAndShowDocument(data, url, raw) {
25+
// filter html
26+
var text = data.split('&').join('&amp;').split('<').join('&lt;').split('>').join('&gt;').split('\n').join('<br>');
27+
if(!raw)
28+
{
29+
// reformat for logs (<md> tokens for markdown later)
30+
// text = text.replace(/\[(.*)\] (\S.{0,70}\S) : (.*)/g,'<md/><span class="name">$2</span> <span class="time">$1</span><br><md>$3');
31+
// changed this line to add support for user IDs
32+
text = text.replace(/\[(.*)\] (\S.{0,70}?\S) (\(\d{17,20}\) )?: (.*)/g,'<md/><span class="name">$2</span> <span class="time">$3$1</span><br><md>$4');
33+
// markdown
34+
text = text.split('<md').map(s => {
35+
if(s.startsWith('/>'))
36+
return s.substring(2);
37+
else if(s.startsWith('>'))
38+
return markdown(s.substring(1));
39+
else
40+
return markdown(s);
41+
}).join('');
42+
// custom emotes
43+
text = text.replace(/&lt;(:[A-Za-z0-9-_]{2,64}:)(\d{17,20})&gt;/g,'<img src="https://cdn.discordapp.com/emojis/$2.png?v=1" class="emote" alt="$1">');
44+
text = text.replace(/&lt;a(:[A-Za-z0-9-_]{2,64}:)(\d{17,20})&gt;/g,'<img src="https://cdn.discordapp.com/emojis/$2.gif?v=1" class="emote" alt="$1">');
45+
}
46+
else
47+
text += "\n\n"
48+
// update
49+
$('#output').html('<a class="button" href="'+url+'">Download Original</a><br><br>'+(text.replace(/ /g,' &nbsp;')));
50+
//twemoji
51+
if(!raw)
52+
{
53+
twemoji.size = '16x16';
54+
twemoji.parse(document.body);
55+
}
56+
}
57+
2458
// Loading doc and parsing
2559
$(document).ready(function() {
2660
var loc = getParameterByName('txt')
2761
var raw = getParameterByName('raw')
2862
var url = "https://cdn.discordapp.com/attachments/"+loc+".txt";
29-
if(loc)
30-
$.getJSON(json_url + encodeURIComponent(url) + '&callback=?', function(data){
31-
// filter html
32-
var text = data.contents.split('&').join('&amp;').split('<').join('&lt;').split('>').join('&gt;').split('\n').join('<br>');
33-
if(!raw)
34-
{
35-
// reformat for logs (<md> tokens for markdown later)
36-
// text = text.replace(/\[(.*)\] (\S.{0,70}\S) : (.*)/g,'<md/><span class="name">$2</span> <span class="time">$1</span><br><md>$3');
37-
// changed this line to add support for user IDs
38-
text = text.replace(/\[(.*)\] (\S.{0,70}?\S) (\(\d{17,20}\) )?: (.*)/g,'<md/><span class="name">$2</span> <span class="time">$3$1</span><br><md>$4');
39-
// markdown
40-
text = text.split('<md').map(s => {
41-
if(s.startsWith('/>'))
42-
return s.substring(2);
43-
else if(s.startsWith('>'))
44-
return markdown(s.substring(1));
45-
else
46-
return markdown(s);
47-
}).join('');
48-
// custom emotes
49-
text = text.replace(/&lt;(:[A-Za-z0-9-_]{2,64}:)(\d{17,20})&gt;/g,'<img src="https://cdn.discordapp.com/emojis/$2.png?v=1" class="emote" alt="$1">');
50-
text = text.replace(/&lt;a(:[A-Za-z0-9-_]{2,64}:)(\d{17,20})&gt;/g,'<img src="https://cdn.discordapp.com/emojis/$2.gif?v=1" class="emote" alt="$1">');
51-
}
52-
else
53-
text += "\n\n"
54-
// update
55-
$('#output').html('<a class="button" href="'+url+'">Download Original</a><br><br>'+(text.replace(/ /g,' &nbsp;')));
56-
//twemoji
57-
if(!raw)
58-
{
59-
twemoji.size = '16x16';
60-
twemoji.parse(document.body);
63+
if(loc) {
64+
$.ajax({
65+
url: cors_url + url ,
66+
headers: {'x-requested-with': 'Discord Text Webview'},
67+
method: 'GET',
68+
success: function(data) { parseAndShowDocument(data, url, raw) },
69+
error: function( jqXHR, textStatus, errorThrown) {
70+
$('#output').html('Failed to load <b>' + url + '</b> : ' + errorThrown);
6171
}
6272
});
63-
else
73+
} else {
6474
$('#output').html('No text file provided.<br><br>'
6575
+'This site is used to view .txt files that have been uploaded to Discord.<br><br>'
6676
+'For example, the file uploaded here: https://cdn.discordapp.com/attachments/147698382092238848/506154212124786689/example.txt<br><br>'
67-
+'Can be viewed here: https://txt.discord.website/?txt=147698382092238848/506154212124786689/example<br><br>');
77+
+'Can be viewed here: https://txt.discord.website/?txt=147698382092238848/506154212124786689/example');
78+
}
6879
});

0 commit comments

Comments
 (0)
Please sign in to comment.