Skip to content

Instantly share code, notes, and snippets.

@joelcarranza
Last active April 17, 2020 14:22
Show Gist options
  • Save joelcarranza/7904787 to your computer and use it in GitHub Desktop.
Save joelcarranza/7904787 to your computer and use it in GitHub Desktop.
bookmarklet template for Pinswift
// bookmarklet template for Pinswift
// This can be copied into a bookmarklet maker like:
// http://chriszarate.github.io/bookmarkleter/
// Or used with Gruber's script
// http://daringfireball.net/2007/03/javascript_bookmarklet_builder
var href = location.href;
var path = 'pinswift://x-callback-url/add';
var param = {
url:href,
title:document.title,
// optional parameters
// description: "this is just text",
// tags: "foo,bar",
// private: "yes",
// toread: "yes",
// these x-callback-url parameters tell us what URL to open when we are done
// for Safari, we return to the URL we bookmarked
// for Chrome, use the URL scheme googlechrome://
'x-success':href,
'x-cancel':href
};
// construct a pinswift URL from path + param
var url = [path];
var n = 0;
for(var p in param) {
if(param.hasOwnProperty(p)) {
url.push(n++ == 0 ? '?' : '&',p,'=',encodeURIComponent(param[p]));
}
}
// open pinswift URL
window.location = url.join('');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment