OGame: Localization

OGame: stores localization data on the client

สคริปต์นี้ไม่ควรถูกติดตั้งโดยตรง มันเป็นคลังสำหรับสคริปต์อื่น ๆ เพื่อบรรจุด้วยคำสั่งเมทา // @require https://update.greatest.deepsurf.us/scripts/4442/14625/OGame%3A%20Localization.js

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name OGame: Localization
// @namespace https://greatest.deepsurf.us/users/4668-black-cat
// @description OGame: stores localization data on the client
// @version 5.4
// @creator Black Cat
// @include http://*.ogame.gameforge.com/game/index.php?page=overview*
// ==/UserScript==

var strFunc = (function(){

	var ogTime = parseInt(document.querySelector("meta[name=ogame-timestamp]").getAttribute("content"));
	var xmlTime = parseInt(localStorage.getItem("localization.time") || "0");

	var language = document.querySelector("meta[name=ogame-language]").getAttribute("content");
	var xmlLang = localStorage.getItem("localization.language");
	if (language != xmlLang) {
		xmlTime = 0;
	}

	if (ogTime > xmlTime + 86400) {
		$.get(
			"/api/localization.xml?language="+language,
			function (xml) {
				var data = {};
				localStorage.setItem("localization.language", language);
				var loc = xml.childNodes[0];
				xmlTime = loc.getAttribute("timestamp");
				localStorage.setItem("localization.time", xmlTime);
				var parts = loc.childNodes;
				for (var i=0; i<parts.length; i++) {
					var tag = parts[i].tagName;
					data[tag] = {};
					var names = parts[i].childNodes;
					for (var j=0; j<names.length; j++) {
						var id = names[j].getAttribute("id");
						data[tag][id] = names[j].textContent;
					}
				}
				localStorage.setItem("localization.data", JSON.stringify(data));
			},
			"xml"
		);
	}
}).toString();

if (!document.getElementById("localization_script")) {
	var script = document.createElement("script");
	script.id = "localization_script";
	script.setAttribute("type","text/javascript");
	script.text = "(" + strFunc + ")();";
	document.body.appendChild(script);
}