Skip to content

Instantly share code, notes, and snippets.

@discatte
Last active February 14, 2022 09:56
Show Gist options
  • Save discatte/f47ccd76ea2a2bca25b1e0003222a5b2 to your computer and use it in GitHub Desktop.
Save discatte/f47ccd76ea2a2bca25b1e0003222a5b2 to your computer and use it in GitHub Desktop.
wordle local storage nytimes redirect magic https://twitter.com/GalacticFurball/status/1492014062976188420
const ls = window.localStorage;
// Ensure we're always sending something
let stringifiedData = '{}';
// Default to production
let url = 'https://www.nytimes.com/games/wordle'
// Don't attempt unless our user has local storage enabled
if (ls) {
const errors = [];
const localData = {
time: new Date().getTime(),
statistics: null,
darkTheme: null,
colorBlindTheme: null,
};
// Allow QA folks to switch the redirect url
const params = new Proxy(new URLSearchParams(window.location.search), {
get: (searchParams, prop) => searchParams.get(prop),
});
if (params.url) url = params.url
// Attempt to pull and parse the stats and themes
try {
localData.statistics = JSON.parse(ls.getItem('statistics'));
localData.darkTheme = JSON.parse(ls.getItem('darkTheme'));
localData.colorBlindTheme = JSON.parse(ls.getItem('colorBlindTheme'));
} catch (e) {
// Anything that's not valid JSON will not be sent
errors.push(e);
}
try {
stringifiedData = JSON.stringify(localData);
} catch (e) {
errors.push(e);
}
}
// Everyone will redirect, regardless of local storage
window.location.assign(`${url}?data=${stringifiedData}`)
const ls = window.localStorage;
// Ensure we're always sending something
let stringifiedData = '{}';
// Default to production
let url = 'https://www.nytimes.com/games/wordle'
// Don't attempt unless our user has local storage enabled
if (ls) {
const errors = [];
const localData = {
time: new Date().getTime(),
statistics: null,
darkTheme: null,
colorBlindTheme: null,
force: true
};
// Attempt to pull and parse the stats and themes
try {
localData.statistics = JSON.parse(ls.getItem('statistics'));
localData.darkTheme = JSON.parse(ls.getItem('darkTheme'));
localData.colorBlindTheme = JSON.parse(ls.getItem('colorBlindTheme'));
} catch (e) {
// Anything that's not valid JSON will not be sent
errors.push(e);
}
try {
stringifiedData = JSON.stringify(localData);
} catch (e) {
errors.push(e);
}
}
// Everyone will redirect, regardless of local storage
window.location.assign(`${url}?data=${stringifiedData}`)
@discatte
Copy link
Author

there are two versions, as shortly after posting about this someone noticed the QA section was removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment