/*************************************************************************
* Copyright (c) 2011 im007boy@gmail.com. All rights reserved.            *
* Use of this source code is governed by a BSD-style license that can be *
* found in the LICENSE file.                                             *
*************************************************************************/
var source_url = "";
var source_title;
var background = chrome.extension.getBackgroundPage();
var white_list = {
	"http://db.gamersky.com":"1",
	"http://www.orsoon.com":"1",
	"http://www.xp911.com":"1"
	};
function get_domain(str){
	var domain = "undefined";
	if (str.toLowerCase().indexOf('http://') == 0){
		domain = str.substring(7);
		domain = 'http://'+domain.substring(0,domain.indexOf('/'));
	}else if (str.toLowerCase().indexOf('https://') == 0){
		domain = str.substring(8);
		domain = 'https://'+domain.substring(0,domain.indexOf('/'));
	}
	return domain;
}

function decode_output(str){
	var newstr = decodeOnce(str);
	if (newstr.ifchange == 0)
		window.close();
	else
		document.getElementById("msg").innerHTML = '<a href="'+newstr.toStr+'">迅雷专用链破解扩展探测到了隐藏链接，点此下载</a>';
}
function report(i){ 
	var str = ""
	switch(i){
	case 0:
		str = "转换成功";
		break;
	case 1:
		str = "没有看到转换结果";
		break;
	case 2:
		str = "没有点击链接却弹出了此页面";
		break;
	}
	background.ga_push("[user]隐藏链接探测_"+str,get_domain(source_url),source_url,0);;

	document.getElementById("feedback").innerHTML = "谢谢反馈";
	if (white_list[get_domain(source_url)] =='1' && confirm('本网站大部分用户反馈转换成功，如果你多次尝试后仍然失败，请与我联系以便解决问题。\n谢谢\n【确定】打开反馈页面，【取消】不做操作')){
		chrome.tabs.getSelected(null,function(thisTab){
			chrome.tabs.create({
				index:thisTab.index,
				url: chrome.extension.getURL("./submit.html")
			});	
		});		;
	}
}
chrome.extension.onRequest.addListener(
  function(request, sender, sendResponse) {
	var i = 0;
	switch (request.hope){
	case "outputthunder":
		source_url = request.url;
		source_title = request.title;
		decode_output(request.str);
		background.ga_push("[PageLoad]", location.hostname, location.pathname, 1);
		break;
	}
  });
 
setTimeout(function(){
	document.getElementById("feedback").style.display = "block";
},1200);
