diff --git a/README.md b/README.md index dcf910d..91b1859 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,26 @@ # txt.discord.website -This site is used to view `.txt` files that have been uploaded to Discord. +This site is used to view text files that have been uploaded to Discord. The site is static; the data loading and formatting is performed clientside. Deleting the original file from Discord will also prevent loading it with this site. ## Example +Link to a text file uploaded to Discord: +> https://cdn.discordapp.com/attachments/147698382092238848/506154212124786689/example.txt + +Take the relevant substring (channel id, attachment id, and attachment name): +> 147698382092238848/506154212124786689/example.txt + +Add as a query parameter: +> https://txt.discord.website?file=147698382092238848/506154212124786689/example.txt + +For raw (non-formatted) output, append `&raw=true`: +> https://txt.discord.website?file=147698382092238848/506154212124786689/example&raw=true + +
+Deprecated use of .txt attachments +`file=` is prioritized over the `txt=` parameter, i.e. when both are present, `file=` parameter +will take effect. + Link to a txt file uploaded to Discord: > https://cdn.discordapp.com/attachments/147698382092238848/506154212124786689/example.txt @@ -15,6 +32,7 @@ Add as a query parameter: For raw (non-formatted) output, append `&raw=true`: > https://txt.discord.website?txt=147698382092238848/506154212124786689/example&raw=true +
## Logging format Additional formatting will occur for lines formatted in the following way: diff --git a/js/custom.js b/js/custom.js index f06bc04..f5cc96a 100644 --- a/js/custom.js +++ b/js/custom.js @@ -55,25 +55,40 @@ function parseAndShowDocument(data, url, raw) { } } +function loadFileAt(loc) { + var raw = getParameterByName('raw'); + var url = `https://cdn.discordapp.com/attachments/${loc}`; + $.ajax({ + url: cors_url + url , + headers: {'x-requested-with': 'Discord Text Webview'}, + method: 'GET', + success: function(response) { + if(typeof response === typeof 'string') { + parseAndShowDocument(response, url, raw) + } else { + $('#output').html(`Given file attachment at ${url} is not a text file.`); + } + }, + error: function( jqXHR, textStatus, errorThrown) { + $('#output').html('Failed to load ' + url + ' : ' + errorThrown); + } + }); +} + // Loading doc and parsing $(document).ready(function() { - var loc = getParameterByName('txt') - var raw = getParameterByName('raw') - var url = "https://cdn.discordapp.com/attachments/"+loc+".txt"; + var loc = getParameterByName('file'); if(loc) { - $.ajax({ - url: cors_url + url , - headers: {'x-requested-with': 'Discord Text Webview'}, - method: 'GET', - success: function(data) { parseAndShowDocument(data, url, raw) }, - error: function( jqXHR, textStatus, errorThrown) { - $('#output').html('Failed to load ' + url + ' : ' + errorThrown); - } - }); + loadFileAt(loc); } else { - $('#output').html('No text file provided.

' - +'This site is used to view .txt files that have been uploaded to Discord.

' - +'For example, the file uploaded here: https://cdn.discordapp.com/attachments/147698382092238848/506154212124786689/example.txt

' - +'Can be viewed here: https://txt.discord.website/?txt=147698382092238848/506154212124786689/example'); + var txt = getParameterByName("txt"); + if(txt) { + loadFileAt(txt + ".txt"); + } else { + $('#output').html('No text file provided.

' + +'This site is used to view text files that have been uploaded to Discord.

' + +'For example, the file uploaded here: https://cdn.discordapp.com/attachments/147698382092238848/506154212124786689/example.txt

' + +'Can be viewed here: https://txt.discord.website/?file=147698382092238848/506154212124786689/example.txt'); + } } });