Carrier Loader

Carrier Loading Script

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name           Carrier Loader
// @namespace      http://unidomcorp.com
// @include        http://*.war-facts.com/carrier.php*
// @version        1.4
// @grant          GM_xmlhttpRequest
// @description    Carrier Loading Script
// ==/UserScript==

// Version 1.0 = Original version by ?
// Version 1.1 = small fixes & auto-reaload page when finished (by Seko)
// Version 1.2 = some fixes for Firefox 4+ (by Seko)
// Version 1.3 = some fixes of fixes :-) (by Seko)
// Version 1.4 = fixed unsafeWindow (by Seko)

var assignBtn = document.getElementsByName('addships')[0];
var shipSel = document.getElementsByName('ship')[0];

// "serialize" form elements
function serialize(form) {
    var Elms = form.getElementsByTagName('*');
    var serialized = [];
    for (var i = 0; i < Elms.length; i++) {
        if (Elms[i].hasAttribute('name')) {
            switch (Elms[i].tagName.toLowerCase()) {
            case 'input':
                switch (Elms[i].type) {
                case 'radio':
                    if (Elms[i].checked == true) {
                        serialized.push(Elms[i].name + '=' + Elms[i].value);
                    }
                    break;
                default:
                    serialized.push(Elms[i].name + '=' + Elms[i].value);
                }
                break;
            case 'select':
                for (var o = 0; o < Elms[i].options.length; o++) {
                    if (Elms[i].options[o].selected == true) {
                        serialized.push(Elms[i].name + '=' + form[n].value);
                    }
                }
                break;
            case 'textarea':
                serialized.push(Elms[i].name + '=' + Elms[i].options[o].value);
                break;
            }
        }
    }
    return serialized.join('&');
}

function loadAllCarriers(form, repeat) {
    // We use repeat incase we get the "Blank Screen of Death"
    // Go no further if we're finished.
    if (shipSel.selectedIndex + 1 == shipSel.options.length && !repeat) {
        alert("We're Finished!");
        var link = document.evaluate("//a/text()[contains(.,'<< Back')]/..",
                document, null, XPathResult.ORDERED_NODE_ITERATOR_TYPE, null).iterateNext();
        window.location.href = link.href;
        setTimeout("alert('Done!');", 500);
        return;
    }

    // Advance ships by 1
    if (!repeat) {
        shipSel.options[shipSel.selectedIndex + 1].selected = true;
        form.elements["ship"].value = shipSel.value;
    }

    // Setup parameters
    var method = 'POST';
    var action = form.action ? form.action : window.location.href;
    var params = serialize(form);

    GM_xmlhttpRequest({
        method : method,
        url : action,
        headers : {
            'Content-Type' : 'application/x-www-form-urlencoded',
        },
        data : params,
        onload : function (responseDetails) {
            if (responseDetails.responseText == '') { // Blank Screen of Death
                loadAllCarriers(form, true);
            } else {
                loadAllCarriers(form, false);
            }
        }
    });
}

if (assignBtn && shipSel && shipSel.selectedIndex == 0) {

    exportFunction(loadAllCarriers, unsafeWindow, {
        defineAs : "loadAllCarriers"
    });

    // Load All button
    var loadAll = document.createElement('input');

    loadAll.setAttribute('type', 'button');
    loadAll.setAttribute('value', 'Load All');
    loadAll.setAttribute('onclick', 'loadAllCarriers(this.form,false);');
    assignBtn.parentNode.insertBefore(loadAll, assignBtn.nextSibling);
}