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

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

当前为 2023-04-26 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 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)
    }
})