MatchPoint Helper

try to take over the world!!

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         MatchPoint Helper
// @namespace    http://bogdan.com
// @version      0.7
// @description  try to take over the world!!
// @author       bbogdan
// @match        https://*/*ConfigEditorForm.aspx*
// @match        http://*/*ConfigEditorForm.aspx*
// @grant        none
// ==/UserScript==

(_=> {
    addCss();
    fixCodeMirror();
    addConfigOpenAction();
    addTreeHelper();
})();

function addCss() {
    const popupMenu = '#__PopupMenu { margin-left: 34px; top:40px !important; }';
    const expanders = '.mp-helper-expand-action { cursor:pointer; margin-right:10px; font-family:monospace; }';
    $('head').append(`<style type="text/css">${popupMenu} ${expanders}</style>`);
}

function fixCodeMirror() {
    $('.mp-codeTextBoxTitle img[event=Toggle]').click(function() {
        $(this).parents('.mp-codeTextBox').find('.CodeMirror-scroll').height(`${window.innerHeight - 50}px`);
    });
}

function addTreeHelper() {
    var handleClick = alt => {
        $(`img[alt^=${alt}]`).each((i,e) => e.parentElement.click());
    };
    var expander =  $(`<span class="mp-helper-expand-action">[ + ]</span>`).click(_ => handleClick('Expand'));
    var collapser = $(`<span class="mp-helper-expand-action">[ - ]</span>`).click(_ => handleClick('Collapse'));
    const shouldExpand = getStorage('autoexpand') == 'true';
    var checkbox =  $(`<input class="mp-helper-expand-action" type="checkbox" title="Expand automatically"/>`).prop('checked', shouldExpand).change(function() { setStorage('autoexpand', this.checked); });
    $('.mp-ceTreeCell').prepend(checkbox, expander, collapser);
    if (shouldExpand) {
        expander.click();
    }
}

function addConfigOpenAction() {
    var editorPath = window.location.href.split('?')[0];
    $('select').each((i, e) => {
        var $addLink = $('<a href="#">Open</a>').click(_ => {
            var url = getUrl(e.value);
            if (url) {
                window.open(url,'_blank');
            } else {
                alert('cannot determine configuration');
            }

            event.preventDefault();
        });
        if (getUrl(e.value) || !e.value) {
            $(e).parents('tr:first').children().first().append($addLink);
        }
    });

    function getUrl(val) {
        if (val) {
            var parts = val.split('#');
            if (parts.length === 2) {
                if (parts[1].endsWith('.xml')) {
                    return `${editorPath}?Type=${parts[0]}&File=${parts[1]}&Source=${encodeURIComponent(window.location.href)}`;
                }
            }
        }

        return null;
    }
}

function setStorage(key, value) {
    window.localStorage[`MatchPointHelper-${key}`] = value;
}

function getStorage(key, value) {
    return  window.localStorage[`MatchPointHelper-${key}`];
}