Permalink
Browse files

Merge pull request #1 from sirkitree/master

Some updates we discussed.
  • Loading branch information...
2 parents a428d18 + bb002dc commit b5ac7b2a264694204a019e89cc1c70a5224095a5 @ericduran committed Jun 5, 2011
@@ -1,66 +1,8 @@
<html>
-<body>
-<input type="text" id="clipboard" />
-<script>
- // A generic onclick callback function.
- function genericOnClick(info, tab) {
- var url = lbtMeGetUrl(info);
- lbtMeGetShortUrl(url);
- }
-
- // Create a contextMenu item and assign an onclick event to it.
- var shurlyLink = chrome.contextMenus.create({
- "title": "lbt.me",
- "contexts": ["page","link","image"],
- "onclick": genericOnClick
- });
-
- chrome.browserAction.onClicked.addListener(function(tab) {
- if (tab.url != undefined) {
- lbtMeGetShortUrl(tab.url);
- }
- });
-
- function lbtMeGetUrl(info) {
- if (info.srcUrl != undefined) {
- // Its an image
- return info.srcUrl;
- }
- else if (info.linkUrl != undefined) {
- // Its a link
- return info.linkUrl;
- }
- else {
- // It has to be the page, either way, we're going to return the page url/
- return info.pageUrl;
- }
- }
-
-
- function lbtMeGetShortUrl(url) {
- var xhr = new XMLHttpRequest();
- //What is the difference between, lbt.me and lb.cm ??
- var lbt = "http://lbt.me/shurly/api/shorten?longUrl=" + url + "&format=txt";
- xhr.open("GET", lbt, true);
- xhr.onreadystatechange = function() {
- if (xhr.readyState == 4) {
- if (xhr.responseText) {
- copyToClipboard(xhr.responseText);
- }
- }
- }
- xhr.send();
- }
-
- /**
- * Automagically save to clipboard.
- * We need to do a small pop-up bubble, that fades out in 2 sec.
- */
- function copyToClipboard(text){
- var input = document.getElementById('clipboard');
- input.value = text;
- input.focus();
- input.select();
- document.execCommand('Copy');
- }</script>
+ <head>
+ <script src="shurly.js" type="text/javascript" charset="utf-8"></script>
+ </head>
+ <body>
+ <input type="text" id="clipboard" />
+ </body>
</html>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -1,16 +1,17 @@
{
- "name": "lbt.me",
+ "name": "shUrly",
"description": "A short URL service built on Drupal by your friends at Lullabot",
"version": "1.0",
"options_page": "options.html",
"permissions": [
- "http://lbt.me/",
- "contextMenus"
+ "http://lb.cm/", // how do we make this configurable?
+ "contextMenus",
+ "notifications"
],
"background_page": "background.html",
"browser_action": {
"default_icon": "lullabot.png",
- "default_title": "lbt.me"
+ "default_title": "shUrly"
},
"icons": {
"16": "lullabot.png"
@@ -1,39 +1,28 @@
<!--
-Welcome, this is the option page for the lbt.me/lb.cm chrome extension.
+Welcome, this is the option page for the shUrly chrome extension.
Have fun code reviewing, feel free to send any recommendations to eric dot duran at lullabot dot com.
-->
<html>
<head>
- <title>lbt.me Extension Options</title>
- <style>
- body {
- }
- #header {
- }
- header h1 {
- }
- footer {
- }
- form {
- }
- </style>
+ <link rel="stylesheet" href="style.css" type="text/css" media="screen" title="no title" charset="utf-8">
+ <title>shUrly Extension Options</title>
</head>
-<body>
+<body id="options">
<div id="container">
<header>
- <h1>lbt.me Extension Options</h1>
+ <h1>shUrly Extension Options</h1>
</header>
<div id="main" role="main">
<form name="settings">
<div>Api Key</div>
<input type="text" name="apikey">
- <label for="apikey">Api key can be created over at <a href="http://lbt.me">lbt.me</a></label><br>
+ <label for="apikey">Api key can be created where your shUrly module is installed, for instance <a href="http://lb.cm">lb.cm</a></label><br />
</form>
</div>
<footer>
<button id="save-button">Save</button>
<span id="status"></span>
- <p>Build by Robots -- <a href="http://www.lullabot.com/">Lullabot</a></p>
+ <p>Built by Robots -- <a href="http://www.lullabot.com/">Lullabot</a></p>
</footer>
</div> <!-- eo #container -->
@@ -0,0 +1,70 @@
+// A generic onclick callback function.
+function genericOnClick(info, tab) {
+ var url = shurlyGetUrl(info);
+ shurlyGetShortUrl(url);
+}
+
+// Create a contextMenu item and assign an onclick event to it.
+var shurlyLink = chrome.contextMenus.create({
+ "title": "shUrly",
+ "contexts": ["page","link","image"],
+ "onclick": genericOnClick
+});
+
+chrome.browserAction.onClicked.addListener(function(tab) {
+ if (tab.url != undefined) {
+ shurlyGetShortUrl(tab.url);
+ }
+});
+
+function shurlyGetUrl(info) {
+ if (info.srcUrl != undefined) {
+ // Its an image
+ return info.srcUrl;
+ }
+ else if (info.linkUrl != undefined) {
+ // Its a link
+ return info.linkUrl;
+ }
+ else {
+ // It has to be the page, either way, we're going to return the page url/
+ return info.pageUrl;
+ }
+}
+
+function shurlyGetShortUrl(url) {
+ var xhr = new XMLHttpRequest();
+ //The domain should be configurable.
+ var shUrl = "http://lb.cm/shurly/api/shorten?longUrl=" + url + "&format=txt";
+ xhr.open("GET", shUrl, true);
+ xhr.onreadystatechange = function() {
+ if (xhr.readyState == 4) {
+ if (xhr.responseText) {
+ copyToClipboard(xhr.responseText);
+ }
+ }
+ }
+ xhr.send();
+}
+
+/**
+ * Automagically save to clipboard.
+ * We need to do a small pop-up bubble, that fades out in 2 sec.
+ */
+function copyToClipboard(text){
+ var input = document.getElementById('clipboard');
+ input.value = text;
+ input.focus();
+ input.select();
+ document.execCommand('Copy');
+
+ // Create a simple text notification:
+ var notification = webkitNotifications.createNotification(
+ 'lullabotx85.png', // icon url - can be relative
+ 'shUrly', // notification title
+ 'URL Copied to clipboard: ' + text // notification body text
+ );
+
+ // Show the notification.
+ notification.show();
+}
@@ -0,0 +1 @@
+body{font-family:'Helvetica Neue',Helvetica,Geneva,sans-serif;font-size:12px;}
@@ -0,0 +1,19 @@
+/* @group Common */
+body {
+ font-family: 'Helvetica Neue', Helvetica, Geneva, sans-serif;
+ font-size: 12px;
+}
+/* @end */
+
+/* @group Options */
+body#options {
+ #header {
+ }
+ header h1 {
+ }
+ footer {
+ }
+ form {
+ }
+}
+/* @end */
View
@@ -670,7 +670,7 @@ function shurly_validate_long(&$long_url, $custom = NULL) {
// We only get down here if the long URL links to this domain
// by the way, we're ignoring any subdomain...
- // so http://lbt.me/something and http://www.lbt.me/something are assumed to be the same
+ // so http://lb.cm/something and http://www.lb.cm/something are assumed to be the same
if ($match) {
// let's see if there's a $_GET['q'] in the long URL
$query = $long_parse['query'];

1 comment on commit b5ac7b2

@sirkitree

Hey, you should really send this back to the main project so I can link to the extension from the DR page.

Please sign in to comment.