Sha256: 8125b2939c9ad0059954982911c68afe6035bd99d5a497b6c173c5fe89f8c414

Contents?: true

Size: 1.02 KB

Versions: 38

Compression:

Stored size: 1.02 KB

Contents

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

$(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).on('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

38 entries across 24 versions & 1 rubygems

Version Path
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/tdiary-5.0.14/js/amazon_bitly.js
tdiary-5.1.2 js/amazon_bitly.js
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/tdiary-5.0.14/js/amazon_bitly.js
tdiary-5.1.1 js/amazon_bitly.js
tdiary-5.1.0 js/amazon_bitly.js
tdiary-5.1.0 public/assets/amazon_bitly.js
tdiary-5.0.14 js/amazon_bitly.js
tdiary-5.0.13 js/amazon_bitly.js
tdiary-5.0.12.1 js/amazon_bitly.js
tdiary-5.0.11 js/amazon_bitly.js
tdiary-5.0.10 js/amazon_bitly.js
tdiary-5.0.9 js/amazon_bitly.js
tdiary-5.0.8 js/amazon_bitly.js
tdiary-5.0.8 public/assets/amazon_bitly.js
tdiary-5.0.8 vendor/bundle/gems/tdiary-5.0.7/js/amazon_bitly.js
tdiary-5.0.7 js/amazon_bitly.js
tdiary-5.0.6 js/amazon_bitly.js
tdiary-5.0.5 js/amazon_bitly.js