CotG Horizon

This script adds some buttons to send settleorders to our alliancebot

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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);
})();