Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I prefer bookmarklets because they

- Are easy to edit

- Are inactive until clicked

- Work in all browsers

- Work on mobile

- Integrate nicely into the UI. I can move them around, put them into any bookmark folder, assign shortcuts.

I wrote this bookmarlet editor which makes it easy to convert between clean code and a bookmarklet:

https://www.gibney.org/bookmarklet_editor



Well that's a handy site you have there. Last time I fiddled with bookmarklets they didn't work on Firefox for Android, but now they do. This is going to be handy combining it with my Node-red instance.

Got any good bookmarklets you want to share?


edit any text on webpage

    javascript: (function() {   document.body.contentEditable = true;   document.body.spellcheck = false;  })();
Open on wayback machine

    javascript:location.href='https://web.archive.org/web/*/'+document.location.href.replace(/\/$/, '');
Others that are longer https://github.com/madacol/web-automation/tree/master/bookma...


An interesting one I made recently is related to a game published a couple of days ago here in HN called "infinite craft" https://neal.fun/infinite-craft/

The game does not have any save mechanism, so I made a bookmarklet that loads and autosaves to localStorage

```

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();
})();

```


Oh that's just awesome. Using this with the send to obsidian addon sounds like the best of ideas


You can click on the question mark and then, when you click on one of the examples, it will fill the code area with the code for that bookmarklet.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: