Autodarts - AutoCalibration

auto-calibration while lobby is opened

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Autodarts - AutoCalibration
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  auto-calibration while lobby is opened
// @match        https://play.autodarts.io/*
// @include      http://*:3180/monitor?autocalibration*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=autodarts.io
// @require      https://code.jquery.com/jquery-3.7.1.min.js
// @grant        GM_addStyle
// @license      MIT
// @run-at       document-end
// @grant        GM_openInTab
// @grant        window.close
// ==/UserScript==

(function() {
    'use strict';

        function calibrate(ip, boardID){
        $.ajax({
            url: 'http://'+ip+'/api/config/calibration/auto?distortion=true',
            type: 'POST',
            asynch: false,
            contentType: "application/json",
            success: function(){
                console.log('Board has been calibrated!');
                $('.css-1wq9qmd').eq(0).find(":selected").append(' (calibrated)')
                window.close();
            }  ,
            error : function(){
                //alert('Tampermonkey: Error auto-calibration! Please allow mixed content in your browser for autodarts-URL!')
            }
        });
    }

    function startBoard(ip, boardID) {
        $.ajax({
            type: 'PUT',
            url: 'http://'+ip+'/api/start',
        }).done(function () {
            console.log('Start board: SUCCESS '+boardID);
            calibrate(ip, boardID);

        }).fail(function (msg) {
            console.log('Start: FAIL '+boardID);
        }).always(function (msg) {
            //console.log('Start: in progress');
        });


    }



    $(document).on('click','button:contains("Open Lobby")', function(){
        setTimeout(function() {
            const boardID = $('.css-1wq9qmd').eq(0).find(":selected").val() ;
            console.log( 'Selected  boardID: '+ boardID);
            console.log('calibration starting...');
            $.ajax({
                url: 'https://api.autodarts.io/bs/v0/boards',
                type: 'GET',
                asynch: false,
                xhrFields: {
                    withCredentials: true
                },
                success: function(response){
                    console.log(response);
                    for (let i = 0; i < response.length; i++)
                        if( response[i]['state']['connected'] == true && response[i]['id'] == boardID) {
                            console.log('Board '+response[i]['name'] + ' still in calibration...');
                           console.log('State '+response[i]['state']['event'] + ' ');
                          var event =  response[i]['state']['event'];
                            GM_openInTab("http://"+response[i]['ip']+'/monitor?autocalibration=1&boardID='+boardID+'&event='+event , true);
                        }
                        else {console.log('Board nicht connected oder falsche id: '+   response[i]['id'])}
                }

            });

        }, 3000);
    });

////////////////////

    var urlparm = (new URL(location.href)).searchParams.get('autocalibration');
    if(urlparm) {

        var boardID = (new URL(location.href)).searchParams.get('boardID');
        var event = (new URL(location.href)).searchParams.get('event');
        document.title = 'Please wait: Calibration in progress...';

        if (event !== 'Started') {
            document.title = 'starting board...';
            startBoard(location.hostname+':3180', boardID);

            setTimeout(function() {
                document.title = 'starting calibration...';
                console.log('starting calibration...');
                calibrate(location.hostname+':3180', boardID);
            }, 3000);
        }
        else {
            document.title = 'starting calibration...';
            console.log('starting calibration...');
            calibrate(location.hostname+':3180', boardID);
        }

    }

})();