// ==UserScript==
// @name      mata ichiba_nicovideo
// @namespace http://nicovideo.g.hatena.ne.jp/hdkINO33/
// @include   http://ichiba.nicovideo.jp/item/*
// @author    pool -> koizuka -> hide32767
// @version   0.2
// ==/UserScript==

(function(){
	var h1 = document.getElementById('naviTab');
	if(!h1) return;
	var span = document.createElement('span');
	h1.parentNode.insertBefore(span, h1);
	
	var a = document.createElement('a');
	a.appendChild(document.createTextNode('[\u307e\u305f\u898b\u3066\u308b]'));
	a.href = 'javascript:void(0);';
	a.addEventListener('click',
		function(){
			this.parentNode.removeChild(this);
			
			var subject = document.getElementsByTagName('title')[0].innerHTML.match('(.*) - (.*)')[2];
			var price   = document.getElementsByTagName('strong')[1].innerHTML.replace(/\n/g, "");
			var buyers  = document.getElementsByClassName('noticeTextB')[0].innerHTML;
			var url = location.href;

			var message = 	'\u307E\u305F\u30CB\u30B3\u30CB\u30B3\u5E02\u5834\u898B\u3066\u308B : ' +
					subject + ' ' +
					price   + ' ' +
					'(' + buyers + '\u304C\u8CFC\u5165\u3057\u307E\u3057\u305F) ' +
					url;

			//GM_log(message);
			GM_xmlhttpRequest({
				method: 'POST',
				url: 'http://twitter.com/statuses/update.json',
				headers: { 'Content-type': 'application/x-www-form-urlencoded' },
				data: 'status=' + encodeURIComponent(message),
				onload: function(res){ GM_log('\u6295\u7a3f\u3057\u307e\u3057\u305f\u3002'); },
				onerror: function(res){ GM_log(res.status + ':' + res.statusText); }
			});
		}, false);
	span.appendChild(a);
})();

