Permalink
Browse files

merged release candidate

  • Loading branch information...
gtzilla committed Dec 12, 2010
1 parent 478913b commit 3db7d2bf5dbe959ba0dbff253bb23e67cc07fc7d
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
@@ -20,7 +20,7 @@
</div> <!-- end #container -->
-
+ <!-- compress and build these?????? -->
<script type="text/javascript" src="js/bitlyapi-v3.0.js"></script>
<script type="text/javascript" src="js/sqldb-v1.0.js"></script>
<script type="text/javascript" src="js/libs/md5.js"></script>
@@ -103,6 +103,7 @@
function sign_out() {
bitly.remove_credentials();
auto_expand_urls = true;
+ enhance_twitter_com=true;
if(bit_interval) { clearInterval( bit_interval ); }
@@ -126,6 +127,7 @@
bit_db.remove("user_data", delete_sql_handler );
bit_db.remove("domain", delete_sql_handler );
bit_db.remove("auto_expand_urls", delete_sql_handler );
+ bit_db.remove("enhance_twitter_com", delete_sql_handler );
bitly.set_domain("bit.ly");
@@ -289,7 +291,17 @@
auto_expand_urls = (bool_value) ? true : false;
bit_db.save("auto_expand_urls", { 'auto_expand' : auto_expand_urls }, function() {
//anything here
- })
+ });
+ }
+ function set_enhance_twitter_com( bool_value ) {
+ enhance_twitter_com=(bool_value) ? true : false;
+ bit_db.save("enhance_twitter_com", { 'enhance_twitter_com' : enhance_twitter_com }, function() {
+ //anything here
+ });
+ }
+
+ function get_enhance_twitter() {
+ return enhance_twitter_com;
}
function resync_linked_account( callback ) {
@@ -385,10 +397,6 @@
}
function set_auto_copy_from_cache() {
- // bit_db.save("auto_copy", {'copy' : copy_bool }, function(){
- // // save was successful
- // localstore("auto_copy", copy_bool);
- // });
bit_db.find("auto_copy", function(jo) {
if(jo === undefined) return;
localstore("auto_copy", jo.copy );
@@ -411,6 +419,12 @@
else auto_expand_urls = jo.auto_expand;
})
}
+ function set_enhance_twitter_com_from_cache() {
+ bit_db.find("enhance_twitter_com", function(jo) {
+ if(jo === undefined) enhance_twitter_com=true
+ else enhance_twitter_com = jo.enhance_twitter_com;
+ })
+ }
function set_api_domain_from_cache() {
bit_db.find("domain", function(domain_string) {
@@ -458,6 +472,23 @@
return sqlDB("bitly_local_db");
}
+ function add_link_context_menu() {
+ var params = {
+ 'type' : 'normal',
+ 'title' : 'Shorten link with bit.ly',
+ 'contexts' : ["link"],
+ 'onclick' : _on_context_menu_link_click,
+ 'documentUrlPatterns' : ['http://*/*', 'https://*/*']
+ }
+
+ chrome.contextMenus.create(params, function() {
+ console.log("created a context menu", chrome.extension.lastError)
+ })
+ }
+ function _on_context_menu_link_click() {
+
+ }
+
function test_metrics() {
// clicks|country|referrers
bitly.metrics("clicks", function(jo) {
@@ -502,7 +533,8 @@
// the bit.ly API connector
logger("Initialize bit.ly extension");
var bitly=init_api(), bit_db=init_db(), trends_worker, click_by_min_worker,
- domains_list, auto_expand_urls = true, bit_interval, // bit_interval is the timer for watch list
+ domains_list, auto_expand_urls = true, enhance_twitter_com=true,
+ bit_interval, // bit_interval is the timer for watch list
// for google tracking, when that's ready
_gaq = _gaq || [];
@@ -519,7 +551,8 @@
set_no_expand_domains_from_cache();
set_auto_copy_from_cache();
set_notifications_from_cache();
-
+ set_enhance_twitter_com_from_cache();
+ //add_link_context_menu();
@@ -548,17 +581,33 @@
switch( act ) {
case "page_loaded":
- if(!bitly.is_authenticated() || !auto_expand_urls) return;
- var injectTabs = sender.tab && sender.tab.url,
- no_expand_list = get_no_expand_domains();
- // only support http || https domains
- if(injectTabs && injectTabs.indexOf("http") === 0 &&
- no_expand_list.indexOf( request.domain_host ) === -1) {
-
- chrome.tabs.insertCSS(sender.tab.id, {file : "css/urlexpander.css"})
- chrome.tabs.executeScript(sender.tab.id, {file: "js/content_plugins/bitly.urlexpander.js"});
- }
+ var user_data = localfetch("user_data");
+ /*
+ Makes determination if used is logged in, toggles 'popup' behavior accordingly
+ Default popup behavior is to load options.html, login page
+ */
+
+ if(user_data && user_data.x_login && user_data.x_apiKey) {
+ if(enhance_twitter_com && request.domain_host === "twitter.com" ) {
+
+ chrome.tabs.executeScript(sender.tab.id, {file: "js/content_plugins/bitly.enhance_twitter.js"});
+ }
+
+ if(!bitly.is_authenticated() || !auto_expand_urls) return;
+ var injectTabs = sender.tab && sender.tab.url,
+ no_expand_list = get_no_expand_domains();
+
+ // only support http || https domains
+ if(injectTabs && injectTabs.indexOf("http") === 0 &&
+ no_expand_list.indexOf( request.domain_host ) === -1) {
+
+ chrome.tabs.insertCSS(sender.tab.id, {file : "css/urlexpander.css"})
+ chrome.tabs.executeScript(sender.tab.id, {file: "js/content_plugins/bitly.urlexpander.js"});
+ }
+ }
+
+
break;
/*
@@ -623,6 +672,17 @@
bitly.shorten( request.long_url, sendResponse );
break;
+ case "shorten":
+ console.log("shorten these..")
+ // see if this is an object..
+ // loop over it
+ // check the white list for this url... ouch expensive... go other way?
+ // loop over HUGE whitelist set, check smaller 'long url' domains -- common method for doing this?
+ // shorten them, get a response, send back
+ if(request.long_url) {
+ bitly.shorten( request.long_url, sendResponse );
+ }
+ break;
case "realtime_metrics":
View
@@ -7,7 +7,10 @@
/* width:100%;*/
left:0px;
display:none;
-
+ height:80px;
+ width:392px;
+ overflow:hidden;
+ margin-top:3px;
}
#bitly_expanded_container * {
@@ -24,7 +27,6 @@
}
#bitly_expanded_container .bit_url_expander_box {
- margin-top:3px;
padding:0 10px;
background:white;
border:3px solid #ccc;
@@ -91,12 +93,14 @@
color:#999;
}
+
#bitly_expanded_container .bit_url_expander_box .bitly_home_promo {
- position:absolute;
+ position:absolute;
bottom:3px;
right:6px;
+ margin:0 6px 3px 0;
font-size:11px;
- color:#c79840;
+ color:#c79840;
}
#bitly_expanded_container .bit_user_clicks_box {
font-size:13px;
View
@@ -338,7 +338,7 @@ function parse_oauth_response( url_string ) {
}
function is_large_arrary( array ) {
- if( typeof array !== "string" && array.length > 15) { return true; }
+ if( typeof array == "object" && typeof array !== "string" && array.length > 15) { return true; }
return false;
}
@@ -374,7 +374,7 @@ function internal_multiget( api_url, param_key, bit_params, callback ) {
function chunk(array, chunkSize) {
var base = [], i, size = chunkSize || 5;
- for(i=0; i<array.length; i+=chunkSize ) { base.push( array.slice( i, i+chunkSize ) ); }
+ for(i=0; i<array.length; i+=size ) { base.push( array.slice( i, i+size ) ); }
return base;
}
@@ -1,8 +1,18 @@
(function() {
function dispatch_callback(jo) {}
function init() {
- var body, h = document.location && document.location.host;
- if(h) {
+ var body, h = document.location && document.location.host,
+ d_hosts=["bit.ly", "bitly.org", "j.mp", "bitly.net", "bitly.tv", "blog.bit.ly", "bitly.pro", "bitly.com"];
+ if( d_hosts.indexOf( h ) >=0 || /[^.]{2,}\.bitly\.net$/.test(h) ) {
+ var promos = document.getElementsByClassName("ext_bitly_chrome_promo_delay"), elem, mark=document.createElement("span");
+ for(var i=0; i<promos.length; i++) {
+ elem=promos[i];
+ elem.parentNode.removeChild(elem);
+ }
+ mark.className="has_bitly_chrome_ext_installed";
+ mark.setAttribute("style", "display:none;")
+ document.body.appendChild( mark );
+ } else if(h) {
chrome.extension.sendRequest({'action' : 'page_loaded', 'domain_host' : h || "" }, dispatch_callback);
}
}
Oops, something went wrong.

0 comments on commit 3db7d2b

Please sign in to comment.