Distribute the bookmarklet as a link, so folks can just drag it up
onto their bookmark toolbar.
We're trying to avoid external dependencies, so I don't want to force
folks to load nmbug.js whenever they run the bookmarklet. Instead,
load_bookmarklet fetches nmbug.js, adds a bit of wrapping code to
create the bookmarklet, and injects that as the nmbug link's href.
--- /dev/null
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset="UTF-8"/>
+
+ <script type="text/javascript">
+ function load_bookmarklet(id, source) {
+ var request = new XMLHttpRequest();
+ request.onload = function () {
+ var element = document.getElementById(id);
+ var href = 'javascript:(function () {\n' + this.responseText + '\n run();})();';
+ element.setAttribute('href', href);
+ };
+ request.open('get', source, true);
+ request.send();
+ }
+ </script>
+ </head>
+ <body onload="load_bookmarklet('nmbug', 'nmbug.js');">
+ <p>
+ This is the <a id="nmbug">nmbug</a> bookmarklet.
+ </p>
+ </body>
+</html>