Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using any text file, not just .txt ones #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(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 <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');
}
}
});