Skip to content

Instantly share code, notes, and snippets.

@karlgroves
Created June 24, 2015 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karlgroves/cdd532edbe957851f719 to your computer and use it in GitHub Desktop.
Save karlgroves/cdd532edbe957851f719 to your computer and use it in GitHub Desktop.
Uncompressed Tenon Bookmarklet
javascript:(function () {
var html = document.documentElement.innerHTML;
/**
* the iframe's onload event is triggered twice: once when appending it to the document,
* and once when the form finishes submitting and the new URL is loaded
*/
var loaded = 0;
var iframe = document.createElement('iframe');
// unique name, to make sure we don't create any conflicts with other elements on the page
iframe.name = 'bookmarklet-' + Math.floor((Math.random() * 10000) + 1);
iframe.style.display = 'none';
iframe.onload = function () {
// remove the iframe from the document on the second firing of the onload event
if (++loaded == 1) {
return;
}
// you can also alert('Done!') here :)
document.body.removeChild(iframe);
};
var form = document.createElement('form');
form.method = "POST";
form.action = "https://tenon.io/api/";
form.target = iframe.name;
var hidden = document.createElement('input');
hidden.type = 'hidden';
hidden.name = 'key';
hidden.value = 'ADD_YOUR_API_KEY_HERE';
var store = document.createElement('input');
store.type = 'hidden';
store.name = 'store';
store.value = '1';
var textarea = document.createElement('textarea');
textarea.name = 'src';
textarea.value = html;
form.appendChild(hidden);
form.appendChild(store);
form.appendChild(textarea);
iframe.appendChild(form);
document.body.appendChild(iframe);
form.submit();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment