GL_fast_choice

Выбор существа ГЛ по текстовому вводу

目前為 2024-10-12 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         GL_fast_choice
// @namespace    http://tampermonkey.net/
// @version      0.28
// @description  Выбор существа ГЛ по текстовому вводу
// @author       Something begins
// @license      joe mamma
// @match        https://www.heroeswm.ru/leader_army.php*
// @match        https://my.lordswm.com/leader_army.php*
// @match        https://www.lordswm.com/leader_army.php*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==
let chosen_creatures = [];
let available_creatures = {}
let army_pos_i = 1
function add_new_cre(cre_index, cre_count){
    let index;
    if (obj_army.filter(cre => cre.link == 0).length>=1) index = obj_army.filter(cre => cre.link != 0).length+1
    else {
        index = army_pos_i;
        army_pos_i++;
        if (army_pos_i>=8) army_pos_i = 1
    }
    obj_army[index].link = cre_index;
    obj_army[index].count = 1;
    show_details(cre_index)
    if (chosen_creatures.length>7){
        chosen_creatures = []
    }
}
document.querySelector("#hwm_no_zoom").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){
    if (creature) {
        available_creatures[creature.name] = obj.indexOf(creature)
        datalist.insertAdjacentHTML(`beforeend`, `<option id = "cre_choice${obj.indexOf(creature)}" value="${creature.name}"></option>`);
    }
}
let eventSource = null;
input.addEventListener('keydown', (event) => {
    eventSource = event.key ? 'input' : 'list';
});
input.addEventListener('input', (event)=>{
    let chosen_creature;
    let possible_options = [...datalist.children].filter(option => option.value.toLowerCase().includes(input.value.toLowerCase()))
    if (eventSource === 'list') chosen_creature = available_creatures[event.target.value.trim()]
    if (possible_options.length === 1) chosen_creature = possible_options[0].id.match(/cre_choice(\d+)/)[1]
    if (chosen_creature !== undefined){
        if (chosen_creatures.includes(chosen_creature)) return
        add_new_cre(chosen_creature, 1)
        chosen_creatures.push(chosen_creature)
    }
});

const targetElement = document.querySelector('#reset_div');
console.log(targetElement);

const observer = new MutationObserver((mutationsList) => {
    for (let mutation of mutationsList) {
        if (mutation.type === 'attributes' && mutation.attributeName === 'style') {
            targetElement.style.display = "inline";
        }
    }
});

observer.observe(targetElement, { attributes: true, attributeFilter: ['style'] });