Live data from Hacker News

Infinite Craft

neal.fun

571–580 of 831 posts

Re: Infinite Craft

#573
post #225

Earlier quoted context omitted.

Sure, its not a referendum, but its a prominent sign that even with this task AI can fail spectacularly. P.S. Today I learned from AI that Sphinx + Drunk = Sphinxter.

What would the right answer be?

Riddler, drunk game, no answer.

Re: Infinite Craft

#577
post #492

The game state clears on reload, so here's a wee console snippet to export your list of elements: console.log(JSON.stringify({discoveries: window.$nuxt.$root.$children[2].$children[0].$children[0]._data.discoveries, elements:window.$nuxt.$root.$children[2].$children[0].$children[0]._data.elements})) I'll figure out how to re-import the state later, but it's past midnight for me now.

The state can be re-imported like this: ``` a = (insert JSON output here) window.$nuxt.$root.$children[2].$children[0].$children[0]._data.elements = a.elements; window.$nuxt.$root.$children[2].$children[0].$children[0]._data.discoveries = a.discoveries; ```

I made a bookmarklet that loads the state from localstorage and also autosaves the state on each new craft

    javascript:(function(){
        const exportState = () => JSON.stringify({
            discoveries: window.$nuxt.$root.$children[2].$children[0].$children[0]._data.discoveries, 
            elements: window.$nuxt.$root.$children[2].$children[0].$children[0]._data.elements
        });

        const importState = (state) => {
            const { discoveries, elements } = JSON.parse(state);
            const gameInstance = window.$nuxt.$root.$children[2].$children[0].$children[0]._data;
            gameInstance.discoveries = discoveries;
            gameInstance.elements = elements;
        };

        /* Set up a MutationObserver to listen for changes in the DOM and automatically export the current state. */
        const observer = new MutationObserver((mutations) => {
            const state = exportState();
            localStorage.setItem('gameState', state);
        });

        /* Start observing DOM changes to auto-save the game state. */
        const startObserving = () => {
            const targetNode = document.querySelector('.sidebar');
            observer.observe(targetNode, { childList: true, subtree: true });
        };

        /* Check for a saved state in localStorage and import it if available. */
        const savedState = localStorage.getItem('gameState');
        if (savedState) importState(savedState);
        else localStorage.setItem('gameState', exportState() );

        startObserving();
    })();
Post reply on HN