20
\$\begingroup\$

Sometimes, we need to have posts that can bypass the 30,000 character limit. I have created this Stack Snippet that, given text as input, compresses the text and outputs a Stack Snippet that can be run to view the original text.

var fmt = pako.inflate(atob("eJx1kcFugzAMhu99Co9NAqSRqDsyyrsYcNOwkGSx0TpVffdBO7TL6pP/39Zn2W6eqgo6MtYDexsjSQ0jw8kOVIOkmaAPnoNb1BEdE3TYkdtEVbW7XbMiHHozo1na1qxaELcaLPFSZM+YlUroLEXEj6CsPzoUKlBCV+SXa16+wkVCDTlLst7k17J8/x98ksn9oRvuk40CnPpDdhKJXGvdD14l/DJWVB8m7cNAPep1sJ6QhZIeLMvNUJP1auSsbfSd1D7G4ohnZUIwjjBavrFXTzvbsR4/Z0rf+k3t1f5XPILHRGCHQ4bZ3QC4+3opbOckP2z/WLf9ATMjg/g="), {
  to: 'string'
});
$('#compress').click(function() {
  $('#output').val(fmt.replace(/{}/, btoa(pako.deflate($('#input').val(), {
    to: 'string'
  }))));
});
<script src="https://cdn.rawgit.com/nodeca/pako/master/dist/pako.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<textarea id="input"></textarea>
<br>
<input type="button" value="Compress" id="compress" />
<br>
<br>Output:
<br>
<textarea id="output" readonly></textarea>

An example output Stack Snippet:

$("#a").text(pako.inflate(atob('eJzzSM3JyddRCM8vyklRBAAfngRq'), {to: 'string'}));
<script src="https://cdn.rawgit.com/nodeca/pako/master/dist/pako.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<pre id="a">
  
</pre>

Alternatively, if the above solution is still too long, you can save the contents to a public GitHub Gist, and display it with the following snippet (replacing the URL with your Gist's URL):

$('#a').load('https://gist.githubusercontent.com/Mego/43ae1cfba25105a47e6744ac36847c61/raw/df8fcad07ba95caadfa1f6e4ce98de32e2a37cc5/test.txt');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="a">
</div>

Feedback is always appreciated.

\$\endgroup\$
  • 2
    \$\begingroup\$ Is jQuery really necessary for this? \$\endgroup\$ – programmer5000 May 2 '17 at 10:16
  • \$\begingroup\$ @programmer5000 No, but it saves bytes. \$\endgroup\$ – Mego May 2 '17 at 10:18
  • \$\begingroup\$ including the code required to load it? \$\endgroup\$ – programmer5000 May 2 '17 at 10:18
  • 1
    \$\begingroup\$ @programmer5000 It seems I counted wrong. It's barely longer with jQuery. But, jQuery is simple and ubiquitous, and I'm much more experienced with it than with vanilla DOM manipulation, so I chose to use it. \$\endgroup\$ – Mego May 2 '17 at 10:25

You must log in to answer this question.

Browse other questions tagged .