Sha256: c250ee73602aec041910893ac5731bd8c216ace5f7d254d56539541012e6ed7f

Contents?: true

Size: 1019 Bytes

Versions: 22

Compression:

Stored size: 1019 Bytes

Contents

/*
 * amazon.js : replace amazon URL using bit.ly (amzn.to).
 *
 * Copyright (C) 2011 by TADA Tadashi <t@tdtds.jp>
 * You can distribute it under GPL.
 */

$(function(){
	function shorten(link){
		var url = link.attr('href');
		var api = 'http://api.bit.ly/v3/shorten'
				+ '?format=json'
				+ '&longUrl=' + encodeURIComponent(url)
				+ '&login=' + $tDiary.plugin.bitly.login
				+ '&apiKey=' + $tDiary.plugin.bitly.apiKey;

		$.ajax({
			type: 'GET',
			url: api,
			dataType: 'jsonp',
			success: function(data){
				if (data['data']){
					link.attr('href',data['data']['url']);
				}
				else{
					//console.warn('fail to short: ' + link.attr('href'));
				}
			}
		});
	}

	$(window).bind('scroll', function(event){
		var bottom = $(window).height() + $(window).scrollTop();
		//console.warn('window.bottom: ' + bottom);
		$('a[href*="://www.amazon.co.jp/"]').each(function(){
			var a = $(this);
			if (bottom > a.offset().top){
				//console.warn('appear!: ' + a.text());
				shorten(a);
			}
		});
	});
});

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
tdiary-4.0.5.1 js/amazon.js
tdiary-4.0.5 js/amazon.js
tdiary-4.0.4 js/amazon.js
tdiary-4.0.3 js/amazon.js
tdiary-4.0.2.20140201 js/amazon.js
tdiary-4.0.2 js/amazon.js
tdiary-4.0.1.20131102 js/amazon.js
tdiary-4.0.1.20130929 js/amazon.js
tdiary-4.0.1.20130903 js/amazon.js
tdiary-4.0.1 js/amazon.js
tdiary-4.0.0.20130826 js/amazon.js
tdiary-4.0.0 js/amazon.js
tdiary-3.2.2.20130727 js/amazon.js
tdiary-3.2.2.20130722 js/amazon.js
tdiary-3.2.2.20130720 js/amazon.js
tdiary-3.2.2.20130617 js/amazon.js
tdiary-3.2.2.20130614 js/amazon.js
tdiary-3.2.2.20130604 js/amazon.js
tdiary-3.2.2.20130527 js/amazon.js
tdiary-3.2.2.20130518 js/amazon.js