Skip to content

Instantly share code, notes, and snippets.

@joseadrian
Created June 6, 2012 19:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joseadrian/2884340 to your computer and use it in GitHub Desktop.
Save joseadrian/2884340 to your computer and use it in GitHub Desktop.
Add a Facebook app bookmarklet
/* Add it as a bookmark an click it when you are on the Config page of the app, or any Facebook Tab.
This works for the following url formats:
- http[s]://[www.]facebook.com/pagename/app_APPID
- http[s]://[www.]facebook.com/pagename?sk=app_APPID.
- http[s]://[www.]developers.facebook.com/apps/APP_ID[/summary[/... ?...]]
- http[s]://[www.]facebook.com/pages/[pagename]/[page_id]?sk=app_APPID[&app_data=...]
If you are not on any of these links... it will ask your for the App ID
*/
// Bookmarlet
javascript:(function(){var s=location.href,ai,re=/(?:^https?:\/\/(?:www\.)?(?:developers\.)?facebook.com\/(?:apps\/)?(?:.+(?:\/|\?sk=))(?:app_)?)([0-9]{15})(?:.+)?/;ai=((ai=s.match(re))==null)?prompt('APP ID'):ai[1];if(ai==null)return;location.href="http://www.facebook.com/dialog/pagetab?app_id="+ai+"&redirect_uri=http%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html";})();
// Code
javascript:(function(){
var s = location.href, app_id, regex = /(?:^https?:\/\/(?:www\.)?(?:developers\.)?facebook.com\/(?:apps\/)?(?:.+(?:\/|\?sk=))(?:app_)?)([0-9]{15})(?:.+)?/;
if( (app_id = s.match(regex)) == null )
app_id = prompt('APP ID');
else
app_id = app_id[1];
if( app_id == null ) return;
location.href="http://www.facebook.com/dialog/pagetab?app_id="+app_id+"&redirect_uri=http%3A%2F%2Fwww.facebook.com%2Fconnect%2Flogin_success.html";
})();
// Thanks to Aswin Lutchanah to point out the alternative url to add a app as a page
// And Christoph Broeckmann for the idea of the prompt...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment