access_to_erep

用https://访问游戏时,各个功能正常

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        access_to_erep
// @namespace   eChina_Victory
// @description 用https://访问游戏时,各个功能正常
// @include     https://www.erepublik.com/*
// @version     1.3
// @grant       none
// ==/UserScript==

(function(){
	// 必须载入reward.js,否则每日任务奖励无法领取
	var scriptElement = document.createElement( "script" );
	scriptElement.type = "text/javascript";
	scriptElement.src = "https://www.erepublik.com/js/citizen/reward.js";
	document.body.appendChild( scriptElement );

	// 载入recaptcha
	var scriptElement = document.createElement( "script" );
	scriptElement.type = "text/javascript";
	scriptElement.src = "https://www.google.com/recaptcha/api/js/recaptcha_ajax.js";
	document.body.appendChild( scriptElement );

	// 将所有<a> http://链接替换成https://
	var links = document.getElementsByTagName("a");
	var tl;
	for(var i = 0; i < links.length; i++) 	{
		tl = links[i];
		tl.href = tl.href.replace("http://www.erepublik.com", "https://www.erepublik.com");
	}

	// 将所有<form> http://链接替换成https://
	var forms = document.getElementsByTagName("form");
	var tf;
	for(var i = 0; i < forms.length; i++) 	{
		tf = forms[i];
		tf.action = tf.action.replace("http://www.erepublik.com", "https://www.erepublik.com");
	}

	// 无头鸡还使用了get()和post(),需要先把参数中的http替换成https,再
	// 调用正常的函数。
	var f_post = unsafeWindow.jQuery.post;
	unsafeWindow.jQuery.post = function () {
		arguments[0] = arguments[0].replace('http://www.erepublik.com', 'https://www.erepublik.com');
		f_post.apply(unsafeWindow.jQuery, arguments);
	}

	var f_get = unsafeWindow.jQuery.get;
	unsafeWindow.jQuery.get = function () {
		arguments[0] = arguments[0].replace('http://www.erepublik.com', 'https://www.erepublik.com');
		f_get.apply(unsafeWindow.jQuery, arguments);
	}

})();