Skip to content

Instantly share code, notes, and snippets.

@peerreynders
Last active February 12, 2024 20:56

Revisions

  1. peerreynders revised this gist Feb 12, 2024. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -5,4 +5,9 @@ Resource: [Implementing bookmarklets in JavaScript](https://2ality.com/2011/06/i
    - Minify the finished bookmarklet, e.g. [Minify JS Online](https://minify-js.com/)
    - In the Bookmark Manager (Ctrl+Shift+O) choose “Add New Bookmark” under the “Organise” menu.
    - Specify a name.
    - In URL specify the `javascript:` scheme and delimeter and paste the minified bookmarklet at the end.
    - In URL specify the `javascript:` scheme and delimeter and paste the minified bookmarklet at the end.

    e.g.
    ```JavaScript
    javascript:(()=>{const t=document.location.hash;if(t.length<2&&"#"!==t[0])return;const e=document.getElementById(t.slice(1));e&&e.scrollIntoView({behavior:"smooth",block:"start",inline:"nearest"})})();
    ```
  2. peerreynders revised this gist Feb 12, 2024. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions jump-to-anchor.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    () => {
    (() => {
    // Force Chrome to go to anchor
    const hash = document.location.hash;
    // bail if there is no anchor
    @@ -13,4 +13,4 @@
    block: 'start',
    inline: 'nearest',
    });
    }
    })();
  3. peerreynders revised this gist Feb 12, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -5,4 +5,4 @@ Resource: [Implementing bookmarklets in JavaScript](https://2ality.com/2011/06/i
    - Minify the finished bookmarklet, e.g. [Minify JS Online](https://minify-js.com/)
    - In the Bookmark Manager (Ctrl+Shift+O) choose “Add New Bookmark” under the “Organise” menu.
    - Specify a name.
    - In URL specify the `javascript:` scheme and delimeter a paste the minified bookmarklet at the end.
    - In URL specify the `javascript:` scheme and delimeter and paste the minified bookmarklet at the end.
  4. peerreynders created this gist Feb 12, 2024.
    8 changes: 8 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    Resource: [Implementing bookmarklets in JavaScript](https://2ality.com/2011/06/implementing-bookmarklets.html)

    - Implement bookmarklet as an [IIFE](https://developer.mozilla.org/en-US/docs/Glossary/IIFE).
    - Test the IIFE in the console for a relevant page.
    - Minify the finished bookmarklet, e.g. [Minify JS Online](https://minify-js.com/)
    - In the Bookmark Manager (Ctrl+Shift+O) choose “Add New Bookmark” under the “Organise” menu.
    - Specify a name.
    - In URL specify the `javascript:` scheme and delimeter a paste the minified bookmarklet at the end.
    16 changes: 16 additions & 0 deletions jump-to-anchor.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    () => {
    // Force Chrome to go to anchor
    const hash = document.location.hash;
    // bail if there is no anchor
    if (hash.length < 2 && hash[0] !== '#') return;

    const target = document.getElementById(hash.slice(1));
    // bail if nothing was found
    if (!target) return;

    target.scrollIntoView({
    behavior: 'smooth',
    block: 'start',
    inline: 'nearest',
    });
    }