Bookmarklets

A bookmarklet is a small JavaScript program that can be stored as a URL within a bookmark in most popular web browsers. Right-click on any of these Bookmarklets, and Add to Favorites.

Hello World 

 
(function () {
 var message = "Hello world!";
 alert(message); /* Say hello */
}
)();

View Source 

 
(function () {
    var sourceDocument = open().document;
    sourceDocument.open();
    sourceDocument.write("<html><head><meta name='viewport' content='initial-scale=1.0'/><title>Source of: " + 
            document.location + "</title></head><body><pre wrap>" + 
            document.documentElement.innerHTML.
            replace(/</g, "&lt;").
            replace(/( (?:src|href)=")(.+?)(")/g, "$1<a target=_blank href=$2>$2</a>$3") + 
            "</pre></body></html>");
    sourceDocument.close();
}
)();

SAML Attribute De-babelizer 

 
(function () {
    var assertion = document.getElementById("taEdit").value, xmlDoc;
    if (window.DOMParser) {
        var parser = new DOMParser();
        xmlDoc = parser.parseFromString(assertion, "text/xml");
    } else {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async = false;
        xmlDoc.loadXML(assertion);
    }
    var ns = new Namespace(assertion.substr(1, 6).split(":")[0], "urn:oasis:names:tc:SAML:2.0:assertion");
    var attrNodes = ns.getElements(xmlDoc, "Attribute");
    for (var a = 0; a < attrNodes.length; a++) {
        var valueNodes = ns.getElements(attrNodes[a], "AttributeValue"), values = [];
        for (var v = 0; v < valueNodes.length; v++) {
            values.push(valueNodes[v].firstChild.nodeValue);
        }
        debug.print(attrNodes[a].getAttribute("FriendlyName") + " = " + values.join(", "));
    }
    debug.print("SubjectConfirmationData Address = " + ns.getElements(xmlDoc, "SubjectConfirmationData")[0].getAttribute("Address"));
    debug.print("SubjectLocality Address = " + ns.getElements(xmlDoc, "SubjectLocality")[0].getAttribute("Address"));
}
)();

Show XML 

 
(function () {
   var xml = <a><b/></a>;
   print(xml.toString());
}
)();

Show Functions 

 
(function () {
    var p, o = window, s, fn, ops = [], ans = [], fs = [], win = window.open(), d = win.document, code;
    for (p in o) {
        if (typeof o[p] == "function") {
            s = o[p].toString();
            /*{*/
            if (!s.match(/\{\s*\[native code\]\s*\}/)) {
                fn = (/function (\w*)/).exec(s)[1];
                ops.push("<option value='" + fn + "'>" + fn);
                ans.push("<a href='javascript:document.getElementById(\"" + fn + "\").scrollIntoView()'>" + fn + "</a><br>");
                code = formatCode(s);
                /* code = s.replace(/&/g, "&amp;").replace(/</g, "&lt;"); */
                fs.push("<pre id='" + fn + "'>\n" + code + "\n</pre>");
            }
        }
    }
    ops.sort();
    var style = '<link rel="stylesheet" type="text/css" href="syntax.css" />';
    d.writeln(style + "<select onchange='document.getElementById(this.options[this.selectedIndex].text).scrollIntoView()'>\n" + 
        ops.join("\n") + "\n</select><br>");
    ans.sort();
    d.writeln(ans.join("\n"));
    fs.sort();
    d.writeln(fs.join("\n"));
    d.close();
}
)();

Show DOM Objects 

 
(function () {
 showObject(window.open(), window, "window", "window.opener");
}
)();

Show Cookies 

 
(function () {
 var win = window.open();
 var d = win.document;
 var cs = document.cookie.split("; ");
 d.writeln("Cookies (last updated: " + Date() + ")<br>");
 d.writeln("<table>");
 for (var i = 0; i < cs.length; i++) {
  d.writeln("<tr bgcolor=#f5faff><td>" + unescape(cs[i]));
 }
 d.writeln("</table>");
 d.close();
}
)();

Cookies Window 

 
(function () {
 var d = document, w, cs, s, i;
 w = d.body.appendChild(d.createElement("div"));
 w.style.position = "absolute";
 w.style.left = "5px";
 w.style.top = "5px";
 w.style.zIndex = 1000;
 w.style.color = "white";
 w.style.backgroundColor = "blue";
 cs = d.cookie.split("; ");
 s = "Cookies  X<table>";
 for (i = 0; i < cs.length; i++){
  s += "<tr><td>" + unescape(cs[i]);
 }
 s += "</table>";
 w.innerHTML = s;
 w.onclick = function () {
  d.body.removeChild(w);
 };
}
)();

Draggable Cookies Window 

 
(function () {
 function makeDraggableBox(title, body) {
  
  var box = makeBox("<div id=dragHeader> " + title + " - drag me--press esc to close</div>", body);
  box.dragging = false;
  box.dragStart = function (x, y) {
   this.dragging = true;
   this.dragX = x - parseInt(this.offsetLeft);
   this.dragY = y - parseInt(this.offsetTop);
  };
  box.drag = function (x, y) {
   this.style.left = (x - this.dragX) + "px";
   this.style.top = (y - this.dragY) + "px";
  };
  box.dragStop = function () {
   this.dragging = false;
  };
  document.getElementById("dragHeader").onmousedown = function (event) {box.dragStart(event.pageX, event.pageY);};
  document.getElementById("dragHeader").onmouseup = function (event) {box.dragStop();};
  document.onmousemove = function (event) {
   if (box.dragging) {
    box.drag(event.pageX, event.pageY);
   }
  };
  return box;
 }
 
 function makeBox(title, body) {
  function cleanUp() {
   try {
    document.body.removeChild(box);
    document.onkeydown = null;
    document.onmousemove = null;
   } catch (err) {
    
   }
  }
  
  var box = document.body.appendChild(document.createElement("div"));
  box.id = "box";
  box.innerHTML = "<div>" + title + "</div>" + body;
  box.style.position = "absolute";
  box.style.left = "400px";
  box.style.top = "200px";
  box.style.zIndex = 1000;
  box.style.color = "white";
  box.style.backgroundColor = "grey";
  document.onkeydown = function (event) {
   const keyEsc = 27;
   if (event.keyCode == keyEsc) cleanUp();
  };
  return box;
 }
 
 function getCookies() {
  var cookieTable = "<table>";
  var cookies = document.cookie.split("; ");
  for (var cookie in cookies) {
   cookieTable += "<tr bgcolor=#aaaaaa><td>" + unescape(cookies[cookie]);
  }
  cookieTable += "</table>";
  return cookieTable;
 }
 
 var box = makeDraggableBox("Cookies", getCookies());
}
)();

Show Top-Level Frames 

 
(function () {
 var frames = window.top.frames;
 var s = "";
 if (frames.length == 0) {
   s = "No frames";
 } else {
   for (var i = 0; i < frames.length; i++) {
    s += frames[i].name + " = " + frames[i].location + "\n";
   }
 }
 alert(s);
}
)();

Show Length of Clipboard Text 

 
if (window.clipboardData) {
    alert(window.clipboardData.getData("Text").length);
} else {
    alert("Copy not supported on this browser (try IE)");
}

slayeroffice favelet suite 

 
(function () {
 var script = document.body.appendChild(document.createElement("script"));
 script.id = "fs";
 script.type="text/javascript";
 script.src = "http://slayeroffice.com/tools/suite/suite.js";
}
)();

In IE 7/8/9, the Maximum Length for a Script from the Address Bar is 2047, in a Favorite it is 2083 including the "javascript:"


See also