Skip to content

Instantly share code, notes, and snippets.

@rpavlik
Forked from Ashish879/PushBulletBookmarklet.js
Last active October 30, 2020 16:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rpavlik/bc92b5cf640a903438d5f37dc773cd77 to your computer and use it in GitHub Desktop.
Save rpavlik/bc92b5cf640a903438d5f37dc773cd77 to your computer and use it in GitHub Desktop.
PushBullet Bookmarklet
(function() {
var API_KEY = "YOUR_API_KEY_GOES_HERE";
// code for IE7+, Firefox, Chrome, Opera, Safari - forget IE6
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", "https://api.pushbullet.com/v2/pushes", true);
xmlhttp.setRequestHeader('Content-Type', 'application/json');
xmlhttp.setRequestHeader('Authorization', "Bearer " + API_KEY);
/// @todo needs oauth2 update? ugh.
var newPush = {
"type": "link",
"title": document.title,
"url": document.URL
};
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
alert("Successfully Pushed" + xmlhttp.responseText);
} else if (xmlhttp.status == 400) {
alert('There was an error 400');
} else {
alert('something else other than 200 was returned');
}
}
};
xmlhttp.send(JSON.stringify(newPush));
})(document);
// Converted to a bookmarklet from beautiful source with http://chriszarate.github.io/bookmarkleter/
// Options: url encoding and minify (disabled IIFE, left jQuery disabled)
// Still needs your API key added
javascript:(function(){var%20e=%22YOUR_API_KEY_GOES_HERE%22,t=new%20XMLHttpRequest;t.open(%22POST%22,%22https://api.pushbullet.com/v2/pushes%22,!0),t.setRequestHeader(%22Content-Type%22,%22application/json%22),t.setRequestHeader(%22Authorization%22,%22Bearer%20%22+e);var%20s={type:%22link%22,title:document.title,url:document.URL};t.onreadystatechange=function(){4==t.readyState%26%26alert(200==t.status%3F%22Successfully%20Pushed%22+t.responseText:400==t.status%3F%22There%20was%20an%20error%20400%22:%22something%20else%20other%20than%20200%20was%20returned%22)},t.send(JSON.stringify(s))})(document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment