WestForts.com Import Link

A new link to launch the WestForts import script

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         WestForts.com Import Link
// @version      2.3
// @description  A new link to launch the WestForts import script
// @author       WestForts Staff
// @website      https://www.westforts.com/
// @include  http://*.the-west.*/game.php*
// @include  https://*.the-west.*/game.php*
// @namespace    https://greasyfork.org/users/8213
// ==/UserScript==

if (location.href.indexOf(".the-west.") != -1 && location.href.indexOf("game.php") != -1) {

  if (document.getElementById('westforts_js')) { return; }

  var westforts_js = document.createElement('script');

  westforts_js.setAttribute('type', 'text/javascript');
  westforts_js.setAttribute('id', 'westforts_js');

  westforts_js.innerHTML = "("+(function() {

    var westforts_icon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAuxJREFUeNqkk0tvG1UYQM+987A9nrEdP+rEIWmaNE0wbdVSsaBUrVRVVAIiVoVFaWGBlH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llPAAAAjRJREFUeNqkU8lqYlEULOcpGolDjEYMiJugIR+QTVy4kCSQhd/gL+kX+AluRNdBBHWRoHFAE6QVFY1znLrrgKa3TR+4XN6959SpU/WuYr/fgxGPx3/hHyKZTLq4KwjA4j+B9/d3xGIxhMNhmM1mGI1GaLVaWaPRCC8vL1gul2Bur9cTEDWLmdhsNhEIBODz+aDX6+FyuaRwt9thvV7j+/sbg8EAp6enOD8/x3w+l8Zq0jg5OYFKpUK5XMbz8zP8fr90ZKdKpYLX11dMp1Nst1vY7XYBvbi4EMYCoFAocH19LV10Oh3e3t6EYjabFeCrqysBXCwWMJlMkm8wGH4AeEla3NPptIzABHa6vb0VZt1uF6FQSIo5GsdiCAAvrVaroLM7gTgWBf74+MDX1xeUSiUuLy9lP6wjAOnOZjOZ7/7+Hp1OB5lMBhqNRlQ/OzvD09MTLBaL6EAWdOkIcHd3B4/Hg0ajgVwuJ50ikQiq1aqM9vj4KFqsVisp/htAeXBhMpmISP1+H6VSSVQnTd4dxiEjisxvtVr9w4DoRKTHB9Hy+bwA0C7qwyJ6zzEoLteRgcPhwGazERtvbm4QDAalmOfj8RiJRAKpVAo2mw3tdlt+qEMIA9L//PyUZHZzOp1wu91yzoLhcCjndMvr9SIajUruEYCqs4h0aVur1RLBSJPUKSodKhQKeHh4kH+EOskIfBCkxG5UnHbW63UBpX0EZke+DTpFoGKxiFqtJo9J8b/P+bcAAwD2STF0+3hwkQAAAABJRU5ErkJggg==';
    var westforts_link = document.createElement('div');
    westforts_link.setAttribute('id', 'westforts_link_div');
    westforts_link.setAttribute('title', '<b>Start West Forts Import</b>');
    westforts_link.setAttribute('style', 'position:absolute; z-index:10; cursor:pointer; text-align:center; color:#fff; font-size:12px; padding: 0px 3px 1px 9px; right:0px; top:0px; background:url(\"/images/interface/minimap/minimapbg.png\") no-repeat scroll 0px -7px');
    westforts_link.innerHTML = '<img id="westforts_icon_img" src="' + westforts_icon_bn + '" /><div style="float:right;margin-left:5px;margin-top:1px;">West Forts</div>';

    var westfortsArmed = false; // Track script state
    var origFortBattleMakeStats = FortBattle.makeStats; // Store original function
    var origCemeteryShowStatUpdateTable = CemeteryWindow.showStatUpdateTable; // Store original function
    var existingScript;

    westforts_link.onclick = function() {
        if (westfortsArmed) {
            // **Disarm the script**
            this.style.color = 'rgb(255, 255, 255)'; // Turn white
            document.getElementById('westforts_icon_img').src = westforts_icon_bn;
            westfortsArmed = false;

            existingScript = document.getElementById('wfScript');
            if (existingScript) {
                existingScript.remove(); // Remove script tag
            }

            // **Restore the original functions to stop auto-import**
            FortBattle.makeStats = origFortBattleMakeStats;
            CemeteryWindow.showStatUpdateTable = origCemeteryShowStatUpdateTable;

            // **Ensure that any lingering import form is removed**
            if (document.getElementById('wfForm')) {
                document.getElementById('wfForm').remove();
            }

        } else {
            // **Arm the script**
            existingScript = document.getElementById('wfScript');
            if (!existingScript) {
                var westforts_script = document.createElement('script');
                westforts_script.setAttribute('type', 'text/javascript');
                westforts_script.setAttribute('id', 'wfScript');
                westforts_script.setAttribute('src', 'https://www.westforts.com/js/import.js?' + new Date().getTime());
                document.body.appendChild(westforts_script);
            }

            this.style.color = '#01DF00'; // Turn green
            document.getElementById('westforts_icon_img').src = westforts_icon;
            westfortsArmed = true;
        }
    };

    document.body.appendChild(westforts_link);

  }).toString()+")();";

  document.body.appendChild(westforts_js);
}