Skip to content

Instantly share code, notes, and snippets.

@mgamini
Last active October 23, 2020 14:26
Show Gist options
  • Save mgamini/8eabf2924fb0daa4f968ff94f6e88d64 to your computer and use it in GitHub Desktop.
Save mgamini/8eabf2924fb0daa4f968ff94f6e88d64 to your computer and use it in GitHub Desktop.
Newsday Saturday Stumper AcrossLite Grid Parser
// Instructions:
// Open the Newsday Saturday Stumper in Firefox: https://www.newsday.com/entertainment/extras/crossword-puzzle-1.6375288
// Click on your selected puzzle to navigate to the puzzle page.
// Right-click (option click) anywhere on the puzzle. Select "This Frame -> Show Only This Frame".
// This should bring up just the puzzle.
// Right-click (option click) and click "Inspect Element". Enter the Console tab.
// Paste the code below, and press Enter. Save the text file, and open into Across Lite.
// PLEASE NOTE: EXECUTING CODE IN YOUR CONSOLE YOU DON'T UNDERSTAND IS GENERALLY A VERY BAD IDEA. Don't make a habit of this.
// These two functions are pulled from minified source here:
// https://cdn2.amuselabs.com/pmm/js/c-min.js?v=7fbc5a4d05f45af0cea12e53e8c87fd3ae522c861198391667345f8167b116ed
function bda(t, e) {
for (var n, i, r, o = t.replace(/[^A-Za-z0-9\+\/]/g, ""), s = o.length, a = e ? Math.ceil((3 * s + 1 >> 2) / e) * e : 3 * s + 1 >> 2, c = new Uint8Array(a), u = 0, l = 0, f = 0; f < s; f++)
if (i = 3 & f,
u |= (64 < (r = o.charCodeAt(f)) && r < 91 ? r - 65 : 96 < r && r < 123 ? r - 71 : 47 < r && r < 58 ? r + 4 : 43 === r ? 62 : 47 === r ? 63 : 0) << 18 - 6 * i,
3 == i || s - f == 1) {
for (n = 0; n < 3 && l < a; n++,
l++)
c[l] = u >>> (16 >>> n & 24) & 255;
u = 0
}
return c
}
function UTF8ArrToStr(a) {
for (var l = "", p, R = a.length, y = 0; y < R; y++) p = a[y], l += String.fromCharCode(251 < p && 254 > p && y + 5 < R ? 1073741824 * (p - 252) + (a[++y] - 128 << 24) + (a[++y] - 128 << 18) + (a[++y] - 128 << 12) + (a[++y] - 128 << 6) + a[++y] - 128 : 247 < p && 252 > p && y + 4 < R ? (p - 248 << 24) + (a[++y] - 128 << 18) + (a[++y] - 128 << 12) + (a[++y] - 128 << 6) + a[++y] - 128 : 239 < p && 248 > p && y + 3 < R ? (p - 240 << 18) + (a[++y] - 128 << 12) + (a[++y] - 128 << 6) + a[++y] - 128 : 223 < p && 240 > p && y + 2 < R ? (p - 224 << 12) + (a[++y] - 128 << 6) + a[++y] - 128 : 191 < p && 224 > p && y + 1 < R ? (p - 192 << 6) + a[++y] - 128 : p);
return l
}
// end
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
function exec() {
var data = JSON.parse(UTF8ArrToStr(bda(window.rawc)))
var grid = Array(data.h).fill('')
data.box.forEach((col) => col.forEach((letter, row) => grid[row] += letter))
grid = grid.map(row => row.replace(/\u0000/gi,'.'))
var across = data.placedWords.filter(word => word.acrossNotDown).map(word => word.clue.clue)
var down = data.placedWords.filter(word => !word.acrossNotDown).map(word => word.clue.clue)
var output = [
'<ACROSS PUZZLE>',
'<TITLE>',
data.title,
'<AUTHOR>',
data.author,
'<COPYRIGHT>',
data.copyright,
'<SIZE>',
`${data.h}x${data.w}`,
'<GRID>',
...grid,
'<ACROSS>',
...across,
'<DOWN>',
...down
]
download(data.id + '.txt', output.join('\n'))
}
exec()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment