Skip to content

Instantly share code, notes, and snippets.

@Cam
Last active August 29, 2015 14:12
Show Gist options
  • Save Cam/f66fb1f60345acb3639a to your computer and use it in GitHub Desktop.
Save Cam/f66fb1f60345acb3639a to your computer and use it in GitHub Desktop.
Fancy Safari Extension
<!DOCTYPE html>
<html>
<title>Fancy</title>
<script>
// Watch the extension for a trigger
safari.application.addEventListener("command", performCommand, false);
// Do something when triggered
function performCommand(event) {
// Pass that command we created before to this script
if (event.command == "FancyIt") {
var myurl = safari.application.activeBrowserWindow.activeTab.url; // Set current tab URL
var mytitle = safari.application.activeBrowserWindow.activeTab.title; // Set current tab title
var newTab = safari.application.activeBrowserWindow.openTab(); // Open a new tab
newTab.url = ('http://fancy.com/fancyit?ItemURL=' + encodeURIComponent(myurl) + '&Title=' + encodeURIComponent(mytitle)); // Set up share url
}
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment