Быстрый выбор ГЛ существа

Выбор существа гл по текстовом вводу и/или клику на нужную опцию

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Быстрый выбор ГЛ существа
// @namespace    http://tampermonkey.net/
// @description  Выбор существа гл по текстовом вводу и/или клику на нужную опцию 
// @version      0.1
// @description  try to take over the world!
// @author       Something begins
// @license      none
// @match        https://www.heroeswm.ru/leader_army*
// @match        https://my.lordswm.com/leader_army*
// @match        https://www.lordswm.com/leader_army*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==
let chosen_creatures = [];
function add_new_cre(cre_index, cre_count){
    obj_army[chosen_creatures.length+1].link = cre_index;
    obj_army[chosen_creatures.length+1].count = cre_count;
    show_details(cre_index)
    if (chosen_creatures.length>7){
        chosen_creatures = []
    }
}
document.querySelector("body > center > table:nth-child(2)").insertAdjacentHTML("beforebegin", `<div id="cre_select_div" style = "  position: absolute;
left: 10%;
top: 15%;
transform: translate(-50%, -50%);">
<input type="text" name="creature_choice" list="cre_select" id = "cre_select_input">
<datalist name="Выбрать существо" id="cre_select"></datalist>
</div>`)
const datalist = document.querySelector("#cre_select")
const input = document.querySelector("#cre_select_input")
for (const creature of obj){
    creature &&  datalist.insertAdjacentHTML(`beforeend`, `<option id = "${obj.indexOf(creature)}" value="${creature.name}"></option>`);
}
input.addEventListener('input', ()=>{
    let possible_options = [...datalist.children].filter(option => option.value.toLowerCase().includes(input.value.toLowerCase()))
    if (possible_options.length === 1) {
        let chosen_creature = possible_options[0]
        if (chosen_creatures.includes(chosen_creature)) return
        add_new_cre(chosen_creature.id, 1)
        chosen_creatures.push(chosen_creature)
    }
})