// ==UserScript==
// @name	  Days Footprint Cleaner
// @namespace     http://days.yahoo.co.jp/
// @description   let the spam of the footprint-page be quiet
// @include       http://days.yahoo.co.jp/footprint.html*
// ==/UserScript==
//
// 2008/10/18 version 0.2

(function() {

	function footprintToggle() {
		// standbyがtrueでなければリターン
	
		if (!standbyFlag) {return}
	
		// standbyがtrueなら、まずはそれをfalseにする（連クリック対策）
		standby = false;
		
		// 最大20件をループ
		for (var i = 0; i < footCellLength; i++) {
	
			// doubtFlagがtrueのときだけ以下を実行
			if (!doubtFlag[i]) {continue}
				
			// もしfootprintClearがtrueなら
			if (footprintClearFlag == true) {	
					// footCells[i]をmgc_pic_s_set[i]に代入
					table.getElementsByClassName('mgc_pic_s_set')[i].innerHTML = footCell[i];
				// footprintClearがそれ以外だったら
			} else {
					// footCellsClear[i]をmgc_pic_s_set[i]に代入
					table.getElementsByClassName('mgc_pic_s_set')[i].innerHTML  = footCellsClear[i];
			}
		}
		
		// ループが終わったらfootprintClearFlagをトグルし、standbyをtrueに
		footprintClearFlag = !footprintClearFlag;
		GM_setValue('footprintClearFlag',footprintClearFlag);
		standbyFlag = true;	
	}


	  
	// ここから初期設定だよ
	var footprintClearFlag = GM_getValue('footprintClearFlag','false'); //これがtrueだとスパム候補が消されている状態
	var standbyFlag = false; //これがtrueのときだけ「切り替え」リンクをクリックしたときに動作する
	var footCell = [];
	var footCellsClear = [];
	var doubtFlag = [];
	
	// 足あとリストの現状を変数に代入する
	var table = document.getElementById('mgb_blog');
	if (!table) {return}
	var footCells = table.getElementsByClassName('mgc_pic_s_set');//mgc_pic_s_setの中身をfootCells[i]に代入（spam候補も表示されている状態のhtmlが代入されます）
	var footCellLength = footCells.length;//ページ上に足あとがいくつ表示されているかの数が代入される
	
	// 	足あとの数だけ
	for (var i = 0; i < footCellLength; i++) {
		var cell = footCells[i]; 
		var celldata = cell.getElementsByClassName('fixd_xs');
		var celldataLength = celldata.length;
		
		var connect = celldata[0].innerHTML;// つながりがあるなら、connectにはなんかしらの文字列が代入される
//alert ('コネクトは'+ connect);
		var daytime = celldata[1].innerHTML;// daytimeにはこの足あとがつけられた日時が代入される
		
		// ここから「つながりのない足あと（つまりスパム候補）」の場合の処理
		if (!connect) {
			footCell[i] = table.getElementsByClassName('mgc_pic_s_set')[i].innerHTML;
			footCellsClear[i] = '<div class="mgc_pic"><table><tbody><tr><td><img height="50" border="0" width="50" src="http://i.yimg.jp/images/mg/common/mg_common_nophoto_ms.gif" alt="-"/></td></tr></tbody></table></div>  <div class="mgc_txt"><span style="color:gray">GUEST</span><span class="fixd_xs"><br/><span class="fixd_xs"><span style="color:gray">'+daytime+'<span></span><div class="mgc_ign"> </div></span></div><div class="clear"></div>';//guest表示なhtmlを生成
			doubtFlag[i] = true;// スパム疑惑フラグをtrueにする
		}
	}
	

	// footprintClearFlagがtrueならスパム候補を画面から消す処理
	standbyFlag = true;
	if (footprintClearFlag) {
		footprintClearFlag = false;
		footprintToggle();
	}
	
	// 画面にリンクを貼る
	document.getElementsByClassName('mgc_title_func')[0].innerHTML = '<span style="color:#0000FF;text-decoration:underline;">切り替え</span>';
	
	// グリモンがクリックでも起動するように頑張ってみる
	var elmLink = document.getElementsByClassName('mgc_title_func')[0];
	elmLink.addEventListener("click", footprintToggle, true);
		
	
})();
	
