Sleazy Fork is available in English.

Unlock region restrictions

Bypass some kind of region restrictions.

Versão de: 25/04/2019. Veja: a última versão.

// ==UserScript==
// @name         Unlock region restrictions
// @namespace    http://tampermonkey.net/
// @version      0.3.9
// @description  Bypass some kind of region restrictions.
// @author       CharRun
// @grant        GM_xmlhttpRequest
// @connect      steampowered.com
// @include      https://store.steampowered.com/app/*
// @include      https://store.steampowered.com/agecheck/app/*
// @run-at       document-body
// ==/UserScript==

(()=>{


let	blockingWaitDialog;

let conf = {
	currentAppId:0,
	logStatus:false,
	currentCountry:null,
	defaultCountry:"美国",
	presetCountriesList:{
		"中国":"cn",
		"美国":"us",
		"加拿大":"ca",
		"俄罗斯":"ru",
		"英国":"gb",
		"澳大利亚":"au",
		"法国":"fr",
		"香港":"hk",
		"印度":"in",
		"日本":"jp",
		"韩国":"kr"
	}
};



function init() {
	conf.defaultCountry = localStorage.getItem("CR_DEFAULT_COUNTRY") || conf.defaultCountry; //slow
	if (typeof g_AccountID == "undefined" || typeof g_oSuggestParams == "undefined") {
		setTimeout(init,500);
		return;
	}
	conf.currentAppId = location.pathname.match( /\/(app|sub|bundle)\/([0-9]{1,7})/ )[2] || 0;
	conf.logStatus = g_AccountID ? true : false;
	conf.currentCountry = g_oSuggestParams ? g_oSuggestParams.cc.toLowerCase() : null;
	//conf.defaultCountry = localStorage.getItem("CR_DEFAULT_COUNTRY") || conf.defaultCountry;
}

function controlBar(){
	let postion = document.getElementById("global_action_menu");
	let menu = document.createElement("div");
	let style = document.createElement("style");
	style.innerHTML = "#cr-control-lable{position:relative;background-color:#171a21;color:#b8b6b4;width:150px;border:2px solid gray;border-radius:5px;}#cr-control-lable ul{margin:15px 0;padding:10px 0;box-sizing:border-box;border:1px solid #171a21;border-radius:5px;max-height:300px;min-width:100px;width:auto;overflow:auto;display:none;position:absolute;background-color:#171a21}#cr-control-lable li{padding:0 15px;list-style:none;}#cr-control-lable .icon{position:absolute;width:7.5px;height:7.5px;box-sizing:border-box;border:7.5px solid;top:5px;left:15px;z-index:1;}#cr-control-lable .icon.on{border-color:#fff transparent transparent;}#cr-control-lable .icon.close{border-color:transparent transparent transparent #b8b6b4;}#cr-control-lable #cr-input{width:100%;text-align:center;padding-left:20px;color:#b8b6b4;background-color:#171a21;box-sizing:border-box;border-color:transparent;}#cr-control-lable #cr-input::placeholder{color:#b8b6b4;}#cr-control-lable #cr-input:focus::placeholder{color:#fff;}#cr-control-lable #cr-input:focus{outline:none;color:#fff;}#cr-control-lable button{outline:none;color:#b8b6b4;background-color:#171a21;border:none;text-align:center;box-sizing:border-box;padding:5 auto;}#cr-control-lable button:hover:active{color:#b8b6b4;}#cr-control-lable button:hover{color:#fff;cursor:pointer;}#cr-control-lable li:hover{color:#fff;cursor:pointer;}";
	// menu.style.display = "inline-block"
	document.getElementsByTagName("head")[0].appendChild(style);
	menu.innerHTML = "<div id='cr-control-lable'><div class=\"infobox\"><div style=\"position: relative;\"><span id=\"cr-icon\"class=\"icon close\"></span><input id=\"cr-input\"type=\"text\"name=\"\"placeholder=\"输入/选择国家\"autocomplete=\"off\"></div><div style=\"text-align: center;\"><button id=\"cr-check\"style=\"width:32%;\">访问</button><button id=\"cr-default\"style=\"width:64%;\">设置默认</button></div><ul id=\"cr-select-country\"></ul></div></div>";
	postion.appendChild(menu);

	let input = document.getElementById("cr-input");
	let ul = document.getElementById("cr-select-country");
	let check = document.getElementById("cr-check");
	let setDefault = document.getElementById("cr-default");
	input.value = conf.defaultCountry;
	for(let i in conf.presetCountriesList){
		ul.innerHTML += `<li>${i}</li>`;
	}

	ul.addEventListener("mousedown",function(e){
		input.value = e.target.innerHTML;
		e.preventDefault();   
	},true);

	input.onfocus = function(){
		document.getElementById("cr-icon").className = "icon on";
		document.getElementById("cr-select-country").style.display = "block";
	};

	input.onblur = function(){
		document.getElementById("cr-icon").className = "icon close";
		document.getElementById("cr-select-country").style.display = "none";
	};

	input.onkeypress = function(e){
		if (e.keyCode == 13 || e.which == 13){
			check.onclick();
		}
	};

	check.onclick = function(){
		let region = input.value == "" ? conf.defaultCountry : input.value;
		blockingWaitDialog = ShowBlockingWaitDialog("正在跨区访问", `${region} 区域匿名数据获取中...`);
		anonymousAccess(region);
	};

	setDefault.onclick = function(){
		conf.defaultCountry = input.value == "" ? conf.defaultCountry : input.value;
		localStorage.setItem("CR_DEFAULT_COUNTRY", conf.defaultCountry);
	};
}

function autoCheck() {
	if(document.getElementById("error_box")||document.getElementById("agecheck_form")||document.getElementById("app_agegate")){
		if(cookieMIssCheck()){
			//pass 
			blockingWaitDialog = ShowBlockingWaitDialog("检测到访问限制", `${conf.defaultCountry} 区域匿名数据获取中...`);
			anonymousAccess(conf.defaultCountry);
		}else{
			blockingWaitDialog = ShowBlockingWaitDialog("旁通信息缺失", "设置关键Cookies中...");
			setCookie();
		}
	}
}


function cookieMIssCheck() {
	let cookies = cookieParse();
	let wants_mature_content = cookies.wants_mature_content ? cookies.wants_mature_content == "1" ? true : false : false;
	let mature_content = cookies.mature_content ? cookies.mature_content == "1" ? true : false : false;
	let birthtime = cookies.birthtime ? cookies.birthtime <= "978278400" ? true : false : false; 
	let lastagecheckage = cookies.lastagecheckage ? true : false;
	if(wants_mature_content&&mature_content&&birthtime&&lastagecheckage) return true;
	return false;
}
	
function cookieParse() {
	let cookieString = document.cookie;
	let cookieArray = cookieString.split(";");
	let cookies = {};
	for(let i = 0 , l = cookieArray.length; i < l ; i++){
		let cookie = cookieArray[i].trim();
		if(cookie == "") continue;
		let c = cookie.split("=");
		cookies[c[0]] = c[1];
	}
	return cookies;
}

function setCookie() {
	let date = new Date();
	date.setTime(date.getTime() + 1000 * 3600 * 24 * 365);
	let expires = `expires=${date.toUTCString()};`;
	let path = "path=/;";
	document.cookie= "wants_mature_content=1;" + path + expires;
	document.cookie= "mature_content=1;" +  path + expires;
	document.cookie= "lastagecheckage=1-January-1970;" +  path + expires;
	document.cookie= "birthtime=-729000000;" +  path + expires;
	blockingWaitDialog && blockingWaitDialog.Dismiss();
	location.href = location.href.replace( /\/agecheck/, "" );
}


function anonymousAccess(region) {
	region = region ? conf.presetCountriesList[region] ? conf.presetCountriesList[region] : region : "us";
	if(conf.currentCountry == region){
		blockingWaitDialog && blockingWaitDialog.Dismiss();
		ShowConfirmDialog("访问暂停","访问区域与当前账户区域一致","继续访问","返回").done( res => {
			res || access(region);
		} );
		return 0;
	}else{
		access(region);		
	}

	function access(region) {
		// let protocol = location.protocol == "http:" ? "https://" : "http://";
		let url = `${location.protocol + "//steampowered.com" + location.pathname.replace( /\/agecheck/, "" ) + (location.search == "" ? "?" : (location.search + '&'))}cc=${region}`;
		GM_xmlhttpRequest({
			method:"GET",
			url:url,
			headers:{
				Cookie:"wants_mature_content=1;mature_content=1;lastagecheckage=1-January-1970;birthtime=0"
			},
			onload: ifarme,
			onerror:fail
		});

		function fail() {
		    blockingWaitDialog && blockingWaitDialog.Dismiss();
			ShowConfirmDialog("访问失败","数据获取失败...","再试一次","取消").done( res => {
				res || access(region);
			});
		}
	}
}

function ifarme(res) {
	if(/"error_box"/ig.exec(res.response)){
		blockingWaitDialog && blockingWaitDialog.Dismiss();
		ShowConfirmDialog("访问失败","访问区域受限制( 如访问区域无限制请反馈 )","确认","<a href=\"https://steamcn.com/t482883-1-1\" title=\"\" target=\"_blank\">反馈</a>");
	}

	let virtualDom = document.createElement("html");
	virtualDom.innerHTML = res.response;
	document.querySelector("title").innerHTML = virtualDom.querySelector("title").innerHTML;
	virtualDom.querySelector("head").innerHTML += "<base target=\"_blank\">";
	virtualDom.querySelector("body").innerHTML = virtualDom.querySelector(".responsive_page_template_content").innerHTML;
	let rNode = document.getElementsByClassName("responsive_page_template_content")[0];
	if(conf.logStatus){
		// loginInfo(rNode,virtualDom);
	}
	let content = `<html class="responsive">${virtualDom.innerHTML}</html>`;



	var iframe = document.createElement("iframe");
	iframe.id = "anonymousAccessIframe";
	iframe.style.width = "100%";
	iframe.style.border = "none";
	iframe.style.overflow = "hidden";
	iframe.scrolling = "no";
	iframe.frameborder = "0";

	rNode.innerHTML = "";
	rNode.appendChild(iframe);

	let frameWin = iframe;
	if( iframe.contentWindow ){
		frameWin = iframe.contentWindow;
	}
	frameWin.document.open();
	frameWin.document.writeln(content);
	frameWin.document.close();

	frameWin.onload = function(){

		blockingWaitDialog && blockingWaitDialog.Dismiss();

		function resize() {
			iframe.style.height = frameWin.document.documentElement.scrollHeight + "px";
			// bug only zoom in  
		}

		window.onresize = resize;

		let t = setInterval(resize,600);
		setTimeout(()=>clearInterval(t),6000);
		virtualDom = content = null;
	};
}

function loginInfo(rNode,virtualDom){
	virtualDom.querySelector("#foryou_tab").innerHTML = rNode.querySelector("#foryou_tab").innerHTML;
	virtualDom.querySelector("#foryou_flyout").innerHTML = rNode.querySelector("#foryou_flyout").innerHTML;
	if(document.querySelectorAll(".queue_actions_ctn a").length){
		//logged in but resis
		//building elem
	}else{
		virtualDom.querySelector("#queue_overflow_ctn").innerHTML = rNode.querySelector("#queue_overflow_ctn").innerHTML;
	}

}

function adjustment(rNode,virtualDom){
	//wish list
	((rNode,virtualDom)=>{

	})()
}


(function main(){
	init();
	autoCheck();
	window.onload = ()=>{
		controlBar();
	};
})();


})()