CotG Horizon

This script adds some buttons to send settleorders to our alliancebot

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name                CotG Horizon
// @description	        This script adds some buttons to send settleorders to our alliancebot
// @author         		Darius83
// @include				https://w*.crownofthegods.com/World00.php
// @version				1.0.5
// @grant none
// @namespace https://greasyfork.org/users/117592
// ==/UserScript==
 
/*jshint esnext: true */

(function(){
	// Debug Mode an-/ausschalten
	var DEBUG = false;
	var SCRIPTNAME = GM_info.script.name;
	var VERSION = GM_info.script.version;

	var textfeld = document.getElementById('chatMsg');
	var sendButton = document.getElementById('sendChat');
	var clickEvent = new MouseEvent("click", {
		"view": window,
		"bubbles": true,
		"cancelable": false
	});
	var regex = /\d{1,3}:\d{1,3}/;

	var buttonWhispSettle = document.createElement('button');
	var buttonWhispSettleText = document.createTextNode('!settle xxx:yyy');
	var buttonWhispSettleDel = document.createElement('button');
	var buttonWhispSettleDelText = document.createTextNode('!settle del xxx:yyy');
	var buttonWhispSettleInfo = document.createElement('button');
	var buttonWhispSettleInfoText = document.createTextNode('settle xxx:yyy');

	buttonWhispSettle.appendChild(buttonWhispSettleText);
	buttonWhispSettle.setAttribute('class', 'regButton greenbuttonGo greenb');
	buttonWhispSettle.style.margin = '2% 0 0 2%';
	buttonWhispSettle.style.maxWidth = '30%';

	buttonWhispSettleDel.appendChild(buttonWhispSettleDelText);
	buttonWhispSettleDel.setAttribute('class', 'regButton greenbuttonGo greenb');
	buttonWhispSettleDel.style.margin = '2% 0 0 2%';
	buttonWhispSettleDel.style.maxWidth = '30%';

	buttonWhispSettleInfo.appendChild(buttonWhispSettleInfoText);
	buttonWhispSettleInfo.setAttribute('class', 'regButton greenbuttonGo greenb');
	buttonWhispSettleInfo.style.margin = '2% 0 0 2%';
	buttonWhispSettleInfo.style.maxWidth = '30%';

	if (typeof window.localStorage != "undefined") {
		var cotgScripts = localStorage.getItem("CotG_Scripts");
		if (cotgScripts === null) {
			cotgScripts = new Array();
			cotgScripts[0] = [SCRIPTNAME, VERSION];
			localStorage.setItem("CotG_Scripts", JSON.stringify(cotgScripts));
		} else {
			cotgScripts = JSON.parse(cotgScripts);
			for (var i = 0; i < cotgScripts.length; i++) {
				if (cotgScripts[i][0] === SCRIPTNAME) {
					if (cotgScripts[i][1] === VERSION) {
						break;
					} else {
						cotgScripts[i][1] = VERSION;
						localStorage.setItem("CotG_Scripts", JSON.stringify(cotgScripts));
						break;
					}
				}
				if (i === cotgScripts.length - 1) {
					if (cotgScripts[i][1] != SCRIPTNAME) {
						cotgScripts[i+1] = [SCRIPTNAME, VERSION];
						localStorage.setItem("CotG_Scripts", JSON.stringify(cotgScripts));
					}
				}
			}
		}
	}

	buttonWhispSettleInfo.addEventListener("click", function()
	{
		// /w Mother settle xxx:yyy
		var coords = document.getElementById('emptysInfo').innerHTML.match(regex);
		textfeld.value = '/w Mother settle '+coords;
		sendButton.dispatchEvent(clickEvent);
	}, false);

	buttonWhispSettle.addEventListener("click", function()
	{
		// /w Mother !settle xxx:yyy
		var coords = document.getElementById('emptysInfo').innerHTML.match(regex);
		textfeld.value = '/w Mother !settle '+coords;
		sendButton.dispatchEvent(clickEvent);
	}, false);

	buttonWhispSettleDel.addEventListener("click", function()
	{
		// /w Mother !settle del xxx:yyy
		var coords = document.getElementById('emptysInfo').innerHTML.match(regex);
		textfeld.value = '/w Mother !settle del '+coords;
		sendButton.dispatchEvent(clickEvent);
	}, false);

	var div1 = document.getElementById('squareemptyspot');
	div1.appendChild(buttonWhispSettleInfo);
	div1.appendChild(buttonWhispSettle);
	div1.appendChild(buttonWhispSettleDel);
})();