Bookmarklet Creator

bookmarklet

Usage

Examples

Inject CSS style sheet from a given URL into current page

var link = document.createElement("link");
link.href = prompt("Style sheet URI:", "");
link.type = "text/css";
link.rel = "stylesheet";
document.head.appendChild(link);

inject CSS

Check for the current page in the Wayback Machine

window.location = "https://web.archive.org/web/*/" + document.URL

check the Wayback Machine

Reveal the unescaped contents of a bookmarklet link (selected by clicking)

window.addEventListener("click", {
  handleEvent(event) {
    const JS_URI_PREFIX = "javascript:";
    if (event.target instanceof HTMLAnchorElement &&
        event.target.href.startsWith(JS_URI_PREFIX)) {
      event.stopPropagation();
      event.preventDefault();

      let xi = this.escape(
        decodeURIComponent(event.target.href.substr(JS_URI_PREFIX.length))
      );
      window.history.pushState(null, "unescaped bookmarklet contents");
      window.location = (
        "javascript:`\x3C!doctype html\x3E\x3Cpre\x3E" + xi + "\x3C/pre\x3E`"
      );
    }
  },
  escape(text) {
    return encodeURIComponent(
      text.replace(new RegExp("[\x3C\x3E\x26\x22]", "g"), function(ch) {
        switch (ch) {
          case '\x3C': return "\x26lt;";
          case '\x3E': return "\x26gt;";
          case '\x26': return "\x26amp;";
          case '\x22': return "\x26quot;";
        }
        throw new Error("wat.  ch: " + ch);
      }).replace(new RegExp("\x5C\x5C", "g"), (
        "\x5C" + "\x5C"
      )).replace(new RegExp("\x5C\x24\x7B", "g"), (
        "\x5C" + "\x24" + "\x7B"
      )).replace(new RegExp("\x60", "g"), (
        "\x5C" + "\x60"
      ))
    );
  }
}, true);

unescape bookmarklet

Transform this page's unescaping bookmarklet to show URIs instead

const after = "event.target.href";
const before = "decodeURIComponent(" + after + ".substr(JS_URI_PREFIX.length))";

let candidates = Array.from(document.querySelectorAll("pre, a.bookmarklet"));
for (let i = 0, n = candidates.length; i < n; ++i) {
  makeSubstitution(candidates[i]);
}

function makeSubstitution(node) {
  let source = node.outerHTML.replace(before, after);
  if (node.outerHTML != source) {
    if (node.previousElementSibling.textContent.startsWith("Reveal the un")) {
      node.previousElementSibling.textContent = (
        "Reveal the URI for a bookmarklet (selected by clicking)"
      );
    } else if (node.textContent == "unescape bookmarklet") {
      source = source.replace(
        "unescape bookmarklet", "reveal bookmarklet URI"
      );
    }
    node.outerHTML = source;
  }
}

transform unescaping bookmarklet