index.html: Supply nmbug.js as a bookmarklet
authorW. Trevor King <wking@tremily.us>
Sat, 20 Sep 2014 18:46:55 +0000 (11:46 -0700)
committerW. Trevor King <wking@tremily.us>
Sat, 20 Sep 2014 20:12:03 +0000 (13:12 -0700)
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.

index.html [new file with mode: 0644]

diff --git a/index.html b/index.html
new file mode 100644 (file)
index 0000000..952b669
--- /dev/null
@@ -0,0 +1,24 @@
+<!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>