open_best_work

Открывает предприятие с самой выгодной ценой устройства

目前為 2023-04-27 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         open_best_work
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description Открывает предприятие с самой выгодной ценой устройства
// @author      Something begins
// @license     none
// @match       https://www.heroeswm.ru/*
// @match       https://my.lordswm.com/*
// @match       https://www.lordswm.com/*
// @exclude     /^https{0,1}:\/\/(www\.heroeswm\.ru|178\.248\.235\.15|my\.lordswm\.com)\/(login|war|cgame|frames|chat|chatonline|ch_box|chat_line|ticker|chatpost|chat2020|battlechat|campaign)\.php
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==
const facility_types = ['sh', 'fc', 'mn']
const sector_coords_1 = {
    "Ungovernable Steppe": [48, 48],
    "Eagle Nest": [49, 48],
    "Peaceful Camp": [50, 48],
    "Crystal Garden": [51, 48],
    "Fairy Trees": [52, 48],
    "Mithril Coast": [53, 49],
    "Bear Mountain": [52, 49],
    "Rogues' Wood": [51, 49],
    "Tiger Lake": [50, 49],
    "Shining Spring": [49, 49],
    "Sunny City": [48, 49],
    "Sublime Arbor": [48, 50],
    "Green Wood": [49, 50],
    "Empire Capital": [50, 50],
    "East River": [51, 50],
    "Magma Mines": [52, 50],
    "Harbour City": [52, 50],
    "Lizard Lowland": [49, 51],
    "Wolf Dale": [50, 51],
    "Dragons' Caves": [51, 51],
    "The Wilderness": [49, 52],
    "Portal Ruins": [50, 52],
    "Great Wall": [51, 52],
    "Titans' Valley": [51, 53],
    "Fishing Village": [52, 52],
    "Kingdom Castle": [52, 54]
}
let send_get = function(url)
{
    var xhr = new XMLHttpRequest();
    xhr.open('GET', url, false);
    xhr.overrideMimeType('text/plain; charset=windows-1251');
    xhr.send(null);
    if(xhr.status == 200) return xhr.responseText;
    return null;
};
const parser = new DOMParser();
let parent = document.querySelector("#main_top_table")
parent ? parent.insertAdjacentHTML('beforeend', `<button id = "fast_work">Открыть работу</button>`) : document.querySelector("#hwm_header > center > div > div.sh_MenuPanel").insertAdjacentHTML('beforeend', `<button id = "fast_work">Открыть работу</button>`)
document.querySelector("#fast_work").addEventListener("click", ()=>{
    let reponse_text = send_get(`${location.protocol}//${location.host}/map.php?`)
    let doc = parser.parseFromString(reponse_text, 'text/html');
    let cur_sector_1 = doc.querySelector("#set_mobile_max_width > div.global_container_block_header > b")
    if (cur_sector_1) cur_sector_1 = cur_sector_1.innerText
    let cur_sector_cx = sector_coords_1[cur_sector_1][0];
    let cur_sector_cy = sector_coords_1[cur_sector_1][1];
    let res;
    for (const f_type of facility_types) {
        let reponse_text = send_get(`${location.protocol}//${location.host}/map.php?cx=${cur_sector_cx}&cy=${cur_sector_cy}&st=${f_type}&action=get_objects&js_output=1&rand=616285.8014822785`)
        let doc = parser.parseFromString(reponse_text, 'text/html');
        let available_facilities = {}
        for (const el of doc.getElementsByClassName("map_obj_table_hover")) {
            if (el.classList.length < 2) {
                const facility_a = el.querySelector("td:nth-child(4) a")
                available_facilities[facility_a.href] = parseInt(facility_a.querySelector("b").innerText)
            }
        }
        if (available_facilities.length === 0) continue
        let maxFacility;
        let maxValue = Number.NEGATIVE_INFINITY;
        for (const facility in available_facilities) {
            if (available_facilities[facility] > maxValue) {
                maxFacility = facility;
                maxValue = available_facilities[facility];
            }
        }
        if (maxFacility === undefined) continue
        location.href = maxFacility
    }
})