Created
June 24, 2015 12:13
-
-
Save karlgroves/cdd532edbe957851f719 to your computer and use it in GitHub Desktop.
Uncompressed Tenon Bookmarklet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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