// ==UserScript==
// @name           YahooAuctionS
// @namespace      http://www.nikep.net/yahooauctions/
// @description    Yahoo!オークションUIカスタマイズ設定
// @include        http://*.auctions.yahoo.co.jp/*
// ==/UserScript==
//
// $Id: yahooauctions.user.js,v 1.3 2010/02/02 01:57:51 satan Exp $
// auther: Shigeki Kaneko <http://www.nikep.net/>
// version: 0.1.0
// Copyright(c): 2009 Shigeki Kaneko, all right reserved.
//
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//

(function(){

    //-- >> 設定パラメータ Configuration parameters of the script
    //-- 商品リスト画面の表示を強制的に「残り時間が短い」順にする。
    //-- sort by remaining time on list or search result. [true/false]
    var SORT_BY_REMAINING_TIME = true;

    //-- ウォッチリストからの削除を行った後に表示される確認画面から自動的に戻る
    //-- back from confirmation window of deleting watchlist automatically.[true/false]
    var AUTO_BACK_AFTER_DELETING_WATCHLIST = true;

    //-- ウォッチリストに登録を行った後に表示される確認画面から自動的に戻る
    //-- back from confirmation window of adding watchlist automatically.[true/false]
    var AUTO_BACK_AFTER_ADDING_WATCHLIST = true;

    //-- 業者の公告を非表示にする
    //-- Hide advertisement from shops.[true/false]
    var REMOVE_SHOP_ADVERTISEMENT = true;

    //-- ヤフーの[PR]を非表示にする
    //-- Hide advertisement from yahoo.[true/false]
    var REMOVE_YAHOO_ADVERTISEMENT = true;

    //-- ヤフーショッピングを非表示にする
    //-- Hide advertisement from yahoo.[true/false]
    var REMOVE_YAHOO_SHOPPING = true;

    //-- 現在価格を 1円〜4999円にする。[true/false], 最低価格(MIN)/最高価格(MAX) は円
    //-- Current price must be limitted upto 4999 Yen for non-premium membership.
    var LIMITTED_PRICE_FOR_NON_PREMIUM = false;
    var LIMITTED_PRICE_FOR_NON_PREMIUM_MIN_PRICE = 1;
    var LIMITTED_PRICE_FOR_NON_PREMIUM_MAX_PRICE = 4999;

    //-- 出品者のブラックリスト。商品リスト上で非表示にする[true/false]
    //-- Black list of user id. Add one into comma separated list in backList.
    var REMOVE_UESR_IN_BLACK_LIST = true;
    var blackList = [];
    // var blackList = [ "PIOKI", "adnap1230", "advan2007jp", "akitamu28", "alphajapancorp", "andway48", "ao625", "asaro375", "aucyou2008", "bananabeach1991", "bigbird_7jp", "bihaiyan63", "birdeye2001", "bluesky0406i", "bonbom2007jp", "buchikin", "cafe_camera", "caferatnica", "capetown_goodhope", "chisa_mama", "chly86", "ciaopi380", "clickers3000", "climb_on_8848", "cobanruby", "color7560jp", "coronpjkd", "courage1999jp", "csintl2010", "cyndi_wang2007", "d_fugou", "dangan_s", "den_toiya", "diehardlock", "discoverphoto", "drsnf919", "esr_bc_direct", "foxd2008", "free_style_shop_a", "fujigroup_2000", "fumi_fumi2846", "fukumaru2gou", "fyellows", "get_auctions", "get_shop2", "get_shop3", "gyhgx269", "gutschrome", "hannyahara710", "hatataka3", "hayao_suzuki", "hb_ark", "hikariya_bc", "hiroshi_hiroshi_hiroshi", "horiauc09", "hot_collection66", "ichienshop55", "ifsixwasninecat", "ikasikauv", "ikenetjigyoubu", "inckmc0511", "junkya_2007", "k3onlinejapan", "k_s_market", "kameyamawww", "ken55nek", "kenken3kk", "kndrk147", "koji020200", "kojijp402", "kougyodo", "kox0403", "kurayashiki_jp", "kurukumin2002", "lisawu617", "m_matsu4ta", "m_tradejp", "m08201964", "man1zoku", "man3zoku", "marume2381", "masayo4829", "mc6809mc68000", "med_1210", "miatan_mama", "michi_maru", "mignonberry", "muraauc08", "naka08auc", "neon_ya", "netdo24", "netmirakuru", "news_pc_res", "norio36", "number_one_company", "oerterua", "okinawawa114", "outdoors_betackle", "pardalis925", "pbnyc130", "pc_taku_shop", "pkhgx206", "pluscom88", "ra888jp", "rabbitcrew", "raoki_2007", "rasukaru1215", "renbulant", "rgbbt990", "riauc08", "roromio_roman", "rsystem_co", "saiseiauction", "saison_2007", "sakuraya_ac", "sariastore2009", "scramblebox", "sdftj852", "sen1267", "sh2gou", "shanghaiweb2004", "shiber413", "shimon2005jp", "shouhouwww", "skwhhw", "slwy41", "sofuto09090", "softoya", "squamish2005", "sss_shin1_sss", "stoauction", "strategy_co_ltd", "syouai9843", "system0799jp", "t_and_mtokyo", "t_c_k_w2006", "takaauc09", "takahikashin", "takumisaimoto", "tenkaipc", "tkpcmem", "tokusenkan55", "tomoauc09", "tools1a", "top_mart1992", "tosinshop", "tw_p_glass_dream88", "ueauc09", "umaibouboubou", "urankoubo2000", "usakonta08", "vantannn1234", "vapsauction", "widely_shop", "wowmomodebi", "x13mi00", "yaaamadajp", "yuchajo", "yusyoauc", "yutiguma" ];

    //-- ヤフオク外へのジャンプで即座に飛ぶ
    //-- junping off the auction site without confirmation pages.
    var JUMP_OUTSIDE_WITHOUT_CONFIRMATION = true;

    //-- << 設定パラメータ Configuration parameters of the script
    var currentURL = document.URL;
    var nextURL = null;

    if (JUMP_OUTSIDE_WITHOUT_CONFIRMATION && currentURL.match(/^http:\/\/page.*\/show\/bouncer\?url=(.*)&/)) {
	var nextURL = unescape(RegExp.$1);
	if (nextURL) {
	    location.href = nextURL;
	}
    }
    
    if (currentURL.match("http://search.auctions.yahoo.co.jp/search?") ||
	currentURL.match(/^http:\/\/search.*\.auctions\.yahoo\.co\.jp\/jp\/search?/) ||
	currentURL.match(/^http:\/\/search.*\.auctions\.yahoo\.co\.jp\/jp\/search\/auc?/) ||
	(currentURL.match(/^http:\/\/list.*\.auctions\.yahoo\.co\.jp\/jp\//) && ! currentURL.match(/\/show\/searchoptions?/))) {
	var chkURL;
	//-- List windows. Sort the list by remaining time to finish.
	if (SORT_BY_REMAINING_TIME && !currentURL.match("s1=end")) {
	    var urlad = (currentURL.match(/.html$/) ? "?" : "&") + "s1=end";
	    nextURL = currentURL + urlad;
	}
	chkURL = nextURL ? nextURL : currentURL;
	if (LIMITTED_PRICE_FOR_NON_PREMIUM && !chkURL.match("price_type=currentprice") &&
	    !(chkURL.match("aucminprice=") || chkURL.match("aucmaxprice="))) {
	    var prce = 'price_type=currentprice&min=' + LIMITTED_PRICE_FOR_NON_PREMIUM_MIN_PRICE.toString() + '&max=' + LIMITTED_PRICE_FOR_NON_PREMIUM_MAX_PRICE.toString();
	    var urlad = (chkURL.match(/.html$/) ? "?" : "&") + prce;
	    nextURL = chkURL + urlad;
	}
	//-- If the nextURL is set, it should be reloaded.
	if (nextURL) {
	    location.href = nextURL;
	}

	//-- hide the row entries on the table contained in the blacklist.
	if (REMOVE_UESR_IN_BLACK_LIST) {
	    var trs = document.getElementsByTagName("tr");
	    var cnt = 0;
	    for (var i = 0; i < trs.length; i++) {
		var tr = trs[i];
		if (cnt > 0) {
		    tr.style.display = "none";
		    cnt--;
		    continue;
		} else {
		    var bgc = tr.getAttribute("BGCOLOR");
		    if (bgc != "#ffffff" && bgc != "#ffff99") {
			continue;
		    }
		}
		// 出品者（評価）：<a href="http://openuser.auctions.yahoo.co.jp/jp/user/{blkid}">{blkid}</a>
		if (tr.innerHTML.match(/出品者（評価）：<a href=\"http:\/\/openuser\.auctions\.yahoo\.co\.jp\/jp\/user\/([^\"]*)\">([^<]*)<\/a>/)) {
		    var uid = RegExp.$1;
		    for (var j = 0; j < blackList.length; j++) {
			var blkid = blackList[j];
			if (uid == blkid) {
			    tr.style.display = "none";
			    cnt = 2;	// 2 lines: watch-list, space line.
			}
		    }		    
		}
	    }
	}
    } else if (AUTO_BACK_AFTER_ADDING_WATCHLIST &&
	       currentURL.match(/^http:\/\/navi.*\.auctions\.yahoo\.co\.jp\/jp\/config\/remember?/) ||
	       currentURL.match(/^http:\/\/navi.*\.auctions\.yahoo\.co\.jp\/jp\/show\/complete?/)) {
	//-- Useless confirmation pages, so go back to the previous page.
	setTimeout("history.back()", 2000);
    } else if (AUTO_BACK_AFTER_DELETING_WATCHLIST &&
	       currentURL.match(/^http:\/\/user\.auctions\.yahoo\.co\.jp\/jp\/show\/ucomplete/)) {
	//-- Useless confirmation pages, go forward.
	var elems = document.getElementsByTagName("a");
	for (var i = 0; i < elems.length; i++) {
	    var elem = elems[i];
	    if (elem.innerHTML.match("開催中")) {
		nextURL = elem.getAttribute("href");
		break;
	    }
	}
	if (nextURL) {
	    location.href = nextURL;
	}
    } else if (REMOVE_SHOP_ADVERTISEMENT && 
	       currentURL.match(/http:\/\/page[0-9]*\.auctions\.yahoo\.co\.jp\/jp\/auction\//)) {
	var trs = document.getElementsByTagName("div");
	var modUsrPrvs = [];
	for (var i = 0; i < trs.length; i++) {
	    var tr = trs[i];
	    if (tr.getAttribute("class") == "modUsrPrv") {
		modUsrPrvs.push(tr);
	    }
	    if (tr.getAttribute("id") == "modAdCt") {
		tr.style.display = "none";
	    }
	}
	//-- I don't know exactly which div to hide, but the following setting may be good for most pages.
	if (modUsrPrvs.length >= 4) {
	    modUsrPrvs[0].style.display = "none";
	    modUsrPrvs[1].style.display = "none";
	} else if (modUsrPrvs.length > 1) {
	    modUsrPrvs[0].style.display = "none";
	}
    }

    if (REMOVE_YAHOO_ADVERTISEMENT) {
	//-- Hide advertisement from Yahoo!.
	var trs = document.getElementsByTagName("td");
	for (var i = 0; i < trs.length; i++) {
	    var tr = trs[i];
	    if (tr.innerHTML.match(/^<small>\[PR\]/i)) {
		tr.style.display = "none";
	    }
	}
    }
    
    if (REMOVE_YAHOO_SHOPPING) {
	//-- Hide Yahoo! Shopping.
	var tr = document.getElementById("modAdSs");
	if (tr) {
	    tr.style.display = "none";
	}
    }
})();

