DEV Community

Cover image for Unleash the power of bookmarklets
Amir.H Ebrahimi
Amir.H Ebrahimi

Posted on

4 2

Unleash the power of bookmarklets

Bookmarklet 📜

Although the title is not exactly what I intend, it is what it is.
So, what exactly is a bookmarklet? You can learn more about it here.
In a nutshell, it is the javascript snippet that is saved in the url. Sorry if it's not entirely correct; it doesn't really matter what it is 🥸.

How to Use a Bookmarklet Professionally

  1. Include images that are mostly connected to the functionality.
  2. Add an alt property to the picture > Keep in mind that this will be the name for the browser bookmark in the end.
  3. Place your code in the code structure shown below.
  4. Ensure that the user can easily copy the code.
  5. Ask that the user drag the picture to the bookmark section and edit the bookmark URL to the copied snippet.
  6. Now, when user clicks on the bookmark, they'll get the functionality you're looking for.
javascript: (() => {
  'use strict';
  (function () {
    // Your code
  })();
})();
Enter fullscreen mode Exit fullscreen mode

Real usage

Pintrest

Remove redundant sections of the Pinterest page.

javascript: (() => {
  'use strict';
  (function () {
    const css = `
      a { display:none; }
      button, 
      [data-test-id="pointer-events-wrapper"] { display:none !important; }
      [role="banner"] { margin-bottom: -140px; visibility: hidden; }
    `;
    const head = document.head || document.getElementsByTagName('head')[0];
    const style = document.createElement('style');
    head.appendChild(style);
    style.appendChild(document.createTextNode(css));

    [...document.querySelectorAll('body *')].forEach(item => {
      if (item.getAttribute('id') === '__PWS_DATA__') return;
      if (item.innerHTML === item.innerText && item.innerText.length !== 0)
        item.parentNode.removeChild(item);
    });
  })();
})();
Enter fullscreen mode Exit fullscreen mode

Gitpod

Creating a workspace is as easy as prefixing any GitHub URL with gitpod.io/#

javascript: (() => {
  "use strict";
  (function () {
    for (
      var t = document.getElementsByTagName("meta"), n = 0;
      n < t.length;
      n++
    ) {
      var o = t[n];
      if (o.content.toLowerCase().includes("gitlab")) return !0;
      if ("hostname" === o.name && o.content.includes("github")) return !0;
      if (
        "application-name" === o.name &&
        o.content.toLowerCase().includes("bitbucket")
      )
        return !0;
    }
    return !1;
  })() &&
    window.open(
      ("https://gitpod.io",
      "https://gitpod.io/#" +
        (window.location.protocol + "//" + window.location.host) +
        window.location.pathname)
    );
})();
Enter fullscreen mode Exit fullscreen mode

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay