Skip to content

Commit

Permalink
Allow using any text file, not just .txt ones
Browse files Browse the repository at this point in the history
  • Loading branch information
hnOsmium0001 committed Jul 19, 2020
1 parent 0efcc05 commit f932648
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 17 deletions.
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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
<details>
<summary>Deprecated use of .txt attachments</summary>
`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
Expand All @@ -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
</details>
## Logging format
Additional formatting will occur for lines formatted in the following way:
Expand Down
47 changes: 31 additions & 16 deletions js/custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(data, 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 <b>' + url + '</b> : ' + 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 <b>' + url + '</b> : ' + errorThrown);
}
});
loadFileAt(loc);
} else {
$('#output').html('No text file provided.<br><br>'
+'This site is used to view .txt files that have been uploaded to Discord.<br><br>'
+'For example, the file uploaded here: https://cdn.discordapp.com/attachments/147698382092238848/506154212124786689/example.txt<br><br>'
+'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.<br><br>'
+'This site is used to view text files that have been uploaded to Discord.<br><br>'
+'For example, the file uploaded here: https://cdn.discordapp.com/attachments/147698382092238848/506154212124786689/example.txt<br><br>'
+'Can be viewed here: https://txt.discord.website/?file=147698382092238848/506154212124786689/example.txt');
}
}
});

0 comments on commit f932648

Please sign in to comment.