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/'
3
2
4
3
// Query string parsing
5
4
function getParameterByName ( name , url ) {
@@ -21,48 +20,60 @@ var markdown = function(source) {
21
20
return htmlOutput ( parser ( source + "\n\n" , { inline : false } ) ) ;
22
21
} ;
23
22
23
+ // Document Parsing
24
+ function parseAndShowDocument ( data , url , raw ) {
25
+ // filter html
26
+ var text = data . split ( '&' ) . join ( '&' ) . split ( '<' ) . join ( '<' ) . split ( '>' ) . join ( '>' ) . 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 ( / & l t ; ( : [ A - Z a - z 0 - 9 - _ ] { 2 , 64 } : ) ( \d { 17 , 20 } ) & g t ; / g, '<img src="https://cdn.discordapp.com/emojis/$2.png?v=1" class="emote" alt="$1">' ) ;
44
+ text = text . replace ( / & l t ; a ( : [ A - Z a - z 0 - 9 - _ ] { 2 , 64 } : ) ( \d { 17 , 20 } ) & g t ; / 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, ' ' ) ) ) ;
50
+ //twemoji
51
+ if ( ! raw )
52
+ {
53
+ twemoji . size = '16x16' ;
54
+ twemoji . parse ( document . body ) ;
55
+ }
56
+ }
57
+
24
58
// Loading doc and parsing
25
59
$ ( document ) . ready ( function ( ) {
26
60
var loc = getParameterByName ( 'txt' )
27
61
var raw = getParameterByName ( 'raw' )
28
62
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 ( '&' ) . split ( '<' ) . join ( '<' ) . split ( '>' ) . join ( '>' ) . 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 ( / & l t ; ( : [ A - Z a - z 0 - 9 - _ ] { 2 , 64 } : ) ( \d { 17 , 20 } ) & g t ; / g, '<img src="https://cdn.discordapp.com/emojis/$2.png?v=1" class="emote" alt="$1">' ) ;
50
- text = text . replace ( / & l t ; a ( : [ A - Z a - z 0 - 9 - _ ] { 2 , 64 } : ) ( \d { 17 , 20 } ) & g t ; / 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, ' ' ) ) ) ;
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 ) ;
61
71
}
62
72
} ) ;
63
- else
73
+ } else {
64
74
$ ( '#output' ) . html ( 'No text file provided.<br><br>'
65
75
+ 'This site is used to view .txt files that have been uploaded to Discord.<br><br>'
66
76
+ '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
+ }
68
79
} ) ;
0 commit comments