HWM_AutoReportMGTasks

Автосдача задания ГН

As of 26.11.2017. See ბოლო ვერსია.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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         HWM_AutoReportMGTasks
// @namespace    Небылица
// @version      1.20
// @description  Автосдача задания ГН
// @author       Небылица
// @include      /^https{0,1}:\/\/((www|qrator)\.heroeswm\.ru|178\.248\.235\.15)\/(map|mercenary_guild|home)\.php/
// @grant        GM_setValue
// @grant        GM_getValue
// ==/UserScript==

(function() {
    'use strict';

    // скрипт требует для своей работы скрипт SetsMaster от Demin, который должен находиться выше по порядку исполнения

    // код для страницы карты
    // проверяем наличие активного задания ГН и нахождение в секторе гильдии
    if (location.pathname.indexOf("map.php") !== -1){
        if (document.getElementById("pers_gn").innerHTML.split(":").length === 3){
            if ((document.querySelector("a[href=\"map.php?cx=51&cy=50\"]") !== null) || (document.querySelector("a[href=\"map.php?cx=50&cy=48\"]") !== null) || (document.querySelector("a[href=\"map.php?cx=52&cy=48\"]") !== null) || (document.querySelector("a[href=\"map.php?cx=52&cy=53\"]") !== null)){
                // запрашиваем страницу ГН
                var xhr = new XMLHttpRequest();
                var response;

                xhr.open('GET', "mercenary_guild.php", true);
                xhr.send();
                xhr.onreadystatechange = function() {
                    if (this.readyState == 4 && this.status == 200) {
                        response = xhr.responseText;
                        // получаем ответ и проверяем, было ли задание сдано
                        if (response.indexOf("<b>Статус</b>") !== -1 && response.indexOf("Осталось") === -1){
                            // запоминаем текст награды и переходим в ГН
                            try{GM_setValue("reward", response.match(/<Br><br>(.+?)<table\sborder=0\scellspacing=0\scellpadding=0>/)[1]);}
                            catch(err){console.log(err);}
                            window.open("mercenary_guild.php", "_self");
                        }
                    }
                };
            }
        }
    }

    // код для страницы ГН
    // если имеется сохранённый текст только что сданного задания, то вставляем его в страницу
    if (location.pathname.indexOf("mercenary_guild.php") !== -1){
        if (GM_getValue("reward") !== "-1"){
            var td = document.querySelector("td[rowspan=\"2\"]");
            td.innerHTML = td.innerHTML.split("<table border")[0] + GM_getValue("reward") + "<table border"+ td.innerHTML.split("<table border")[1];
            GM_setValue("reward", "-1");
        } else {
            // если есть принятое задание, то проверяем, не разбойники ли это, и запоминаем при положительном ответе
            if (document.documentElement.innerHTML.indexOf("разбойники {") !== -1 && document.documentElement.innerHTML.indexOf("осталось") !== -1){
                GM_setValue("ifRogues", true);
            }
        }
    }

    // код для домашней страницы
    // проверяем наличие активного задания на разбойников
    if (location.pathname.indexOf("home.php") !== -1){
        if (document.getElementById("pers_gn").innerHTML.split(":").length === 3 && GM_getValue("ifRogues")){
            var warid = document.querySelector("a[href^=\"warlog.php?warid=\"]").getAttribute("href").replace("warlog.php?warid=", "");
            // запрашиваем страницу результатов боя
            var xhr = new XMLHttpRequest();
            var response;

            xhr.open('GET', "battle.php?lastturn=-3&warid=" + warid, true);
            xhr.send();
            xhr.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                    response = xhr.responseText;
                    // проверяем, разбойники ли были только что, и были ли они побеждены
                    if (response.match(/<font color="#0000FF">(.+?)<\/font>/)[1].indexOf("разбойники") !== -1){
                        // сдаём груз и забываем текущее задание
                        GM_setValue("ifRogues", false);
                        window.open("map.php?action=accept_merc_task3", "_self");
                    }
                }
            };
        }
    }
})();