destroyVehicles

send selected vehicles to the scrap heap

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         destroyVehicles
// @version      1.0.2
// @description  send selected vehicles to the scrap heap
// @author       DrTraxx and translate by Mibzzer15
// @match        https://*www.missionchief.com/buildings/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=leitstellenspiel.de
// @grant        none
// @namespace https://greasyfork.org/users/981346
// ==/UserScript==
/* global $ */

(function () {
    'use strict';

    const arrDestroyVehicles = [],
        tableVehicleRows = $("#vehicle_table > tbody > tr");

    $("a[href*='/vehicles/new']:first").after(`<a class="btn btn-xs btn-danger" id="dump_vehicles">scrap selected vehicles</a>`);

    $("#vehicle_table > thead > tr")
        .append(`<th data-column="4" class="tablesorter-header sorter-false tablesorter-headerUnSorted" tabindex="0" scope="col" role="columnheader" aria-disabled="true" unselectable="on" style="user-select: none;" aria-sort="none">
                   <div class="tablesorter-header-inner">destroy</div>
                 </th>`);

    for (var i = 0; i < tableVehicleRows.length; i++) {
        const v = tableVehicleRows[i],
            vehicleId = +$(v).children("td[sortvalue]")[0].firstElementChild.attributes.href.value.replace(/\D+/g, "");

        $(v).append(`<td class="mark_vehicle" style="cursor:pointer;">
                       <input type="checkbox" class="form-check-input" id="check_${ vehicleId }">
      
                     </td>`);
    }

    $("body").on("click", ".mark_vehicle", function () {
        const vehicleId = +$(this).children("input").attr("id").replace(/\D+/g, ""),
            index = arrDestroyVehicles.indexOf(vehicleId);
        if (index === -1) {
            arrDestroyVehicles.push(vehicleId);
            $(`#check_${ vehicleId }`)[0].checked = true;
        } else {
            arrDestroyVehicles.splice(index, 1);
            $(`#check_${ vehicleId }`)[0].checked = false;
        }
    });

    $("body").on("click", "#dump_vehicles", async function () {
        if (arrDestroyVehicles.length === 0) {
            alert("You have to select vehicles to scrap!");
            return;
        }
        if (confirm(`Do you want the ${ arrDestroyVehicles.length } Do you really scrap vehicles?`) === true) {
            for (var p in arrDestroyVehicles) {
                const kernschrott = arrDestroyVehicles[p];
                $("#dump_vehicles").text(`Scrap vehicle ${ +p + 1 } von ${ arrDestroyVehicles.length }!`);
                await $.post(`/vehicles/${ kernschrott }`, { "_method": "delete", "authenticity_token": $("meta[name=csrf-token]").attr("content") });
            }
            window.location.reload();
        }
    });

})();