Last active
November 12, 2018 14:07
-
-
Save Ashish879/fe280abfb6583ebcd04d to your computer and use it in GitHub Desktop.
PushBullet 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
/*********************************************** | |
* If you don't have any proxy restrictions calling PushBullet directly is the recommended approach. | |
* To use this script replace the "<INSERT_API_KEY_HERE>" section with your API KEY | |
* A bookmarklet is created like a regular bookmark. The below javascript code goes in the URL area. | |
************************************************/ | |
javascript:(function()%7Bfunction%20callback()%7B(function(%24)%7Bvar%20jQuery%3D%24%3Bvar%20API_KEY%20%3D%20%22<INSERT_API_KEY_HERE>%22%3Bvar%20newPush%20%3D%20%7B%7D%3BnewPush%5B%22type%22%5D%20%3D%20%22link%22%3B%20newPush%5B%22title%22%5D%20%3D%20document.title%3BnewPush%5B%22url%22%5D%20%3D%20document.URL%3B%24.ajax(%7Btype%3A%20%22POST%22%2Cheaders%3A%20%7B%22Authorization%22%3A%20%22Bearer%20%22%20%2B%20API_KEY%7D%2Curl%3A%20%22https%3A%2F%2Fapi.pushbullet.com%2Fv2%2Fpushes%22%2Cdata%3A%20newPush%7D)%7D)(jQuery.noConflict(true))%7Dvar%20s%3Ddocument.createElement(%22script%22)%3Bs.src%3D%22https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fjquery%2F1.7.1%2Fjquery.min.js%22%3Bif(s.addEventListener)%7Bs.addEventListener(%22load%22%2Ccallback%2Cfalse)%7Delse%20if(s.readyState)%7Bs.onreadystatechange%3Dcallback%7Ddocument.body.appendChild(s)%3B%7D)() |
Readable and formatted:
(function() {
var xmlhttp, API_KEY = "YOUR_API_KEY_GOES_HERE";
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("POST", "https://api.pushbullet.com/v2/pushes", true);
xmlhttp.setRequestHeader('Content-Type', 'application/json');
xmlhttp.setRequestHeader('Authorization', "Bearer " + API_KEY);
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);
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Removed dependency on jquery. Tested in Chrome, FF.
javascript:(function(){var e,t="YOUR_API_KEY_GOES_HERE";e=window.XMLHttpRequest?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP"),e.open("POST","https://api.pushbullet.com/v2/pushes",!0),e.setRequestHeader("Content-Type","application/json"),e.setRequestHeader("Authorization","Bearer "+t);var n={type:"link",title:document.title,url:document.URL};e.onreadystatechange=function(){4==e.readyState&&(200==e.status?(document.getElementById("myDiv").innerHTML=e.responseText,alert("Successfully Pushed"+e.responseText)):alert(400==e.status?"There was an error 400":"something else other than 200 was returned"))},e.send(JSON.stringify(n))})(document);