Skip to content

Instantly share code, notes, and snippets.

@Lokno
Created December 2, 2020 20:20
Show Gist options
  • Select an option

  • Save Lokno/938a22f301ac1c72dd8bd387fb424634 to your computer and use it in GitHub Desktop.

Select an option

Save Lokno/938a22f301ac1c72dd8bd387fb424634 to your computer and use it in GitHub Desktop.
user script for https://adventofcode.com/ that automatically downloads the input for the day in the format dayDD_input.txt
Number.prototype.pad = function(size) {
var s = String(this);
while (s.length < (size || 2)) {s = "0" + s;}
return s;
}
if( document.URL.endsWith('/input') )
{
var url_sans_input = document.URL.slice(0,document.URL.lastIndexOf('/'))
var day_num = parseInt(url_sans_input.slice(url_sans_input.lastIndexOf('/')+1))
var bb = new Blob([document.body.innerText], { type: 'text/plain' });
var a = document.createElement('a');
a.download = 'day' + day_num.pad(2) + '_input.txt';
a.href = window.URL.createObjectURL(bb);
a.click();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment