Last active
December 21, 2015 15:08
-
-
Save briandrum/6324052 to your computer and use it in GitHub Desktop.
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
// After making the required edits below, use something like http://daringfireball.net/2007/03/javascript_bookmarklet_builder to create the bookmarklet. | |
(function(){ | |
var form=document.createElement("form"); | |
// Edit the action value to match your domain and section names. | |
form.setAttribute("action","http://example.com/symphony/publish/entries/new/"); | |
form.setAttribute("method","post"); | |
// Edit the params to match your auth-token | |
// (found on the author page) and section fields. | |
var params={ | |
"auth-token":"your-auth-token", | |
"fields[date-published]":new Date(), | |
"fields[title]":document.title, | |
"fields[body]":(function(){ | |
var html = ""; | |
var sel = window.getSelection(); | |
if (sel.rangeCount) { | |
var container = document.createElement("div"); | |
var blockquote = document.createElement("blockquote"); | |
for (var i = 0, len = sel.rangeCount; i < len; ++i) { | |
blockquote.appendChild(sel.getRangeAt(i).cloneContents()); | |
} | |
container.appendChild(blockquote); | |
html = container.innerHTML; | |
} | |
return html; | |
})(), | |
"fields[url]":document.URL, | |
"action[save]":"" | |
}; | |
for(var key in params) { | |
if(params.hasOwnProperty(key)) { | |
var hiddenField=document.createElement("input"); | |
hiddenField.setAttribute("type","hidden"); | |
hiddenField.setAttribute("name",key); | |
hiddenField.setAttribute("value",params[key]); | |
form.appendChild(hiddenField); | |
} | |
}; | |
document.body.appendChild(form); | |
form.submit(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment