Autodarts_Caller

Another Autodarts-Caller

当前为 2024-02-18 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Autodarts_Caller
// @namespace    http://tampermonkey.net/
// @version      1.4.2
// @description  Another Autodarts-Caller
// @author       benebelter
// @match        https://play.autodarts.io/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=autodarts.io
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js
// @license      MIT
// @grant        GM.getValue
// @grant        GM.setValue
// @grant        GM_xmlhttpRequest
// ==/UserScript==

(function() {
    'use strict';

//////////////// CONFIG ////////////////////

    var triplesound = 0; // 0=off / 1=simple beep on / 2=Löwen-sound (Soft-tip) on => triple_sound if hitting a triple
    var boosound = 0; //  0=off / 1=on => crowd-boo if hitting a miss
    var server = 'http://autodarts.x10.mx/'; //  Server
    var caller = ''; //  caller: "russ_bray", "google" (select language in next line)
    var language = 'en';

//////////////// CONFIG ////////////////////

    function soundGo(file, audio){
        if (audio === 1){
            console.log('Sound-file: '+ file);
            const audio = new Audio(file);
              audio.play();}
        }



    function getDarts(){
        var runde = $('.css-1tw9fat').text().substring(1).split("/");
        var numItems = $('.css-1chp9v4').length ;
        var dartsgesamt = (runde[0]*3-3)+numItems;
        return  "<span style='font-size:0.5em;'>"+dartsgesamt+" Darts</span>" ;
        }


$(document).ready(function(){

var t1 = 0; var t2 = 0; var t3 = 0;
var m1 = 0; var m2 = 0; var m3 = 0;
var dotmp3 = '.mp3';
var called =  0 ;
var gameshot_status = 0;
var busted = 0;
var audio = 1;
var firstgameoncall = 0;


setInterval(function() {


 //$('a[href*="/boards"]').attr("target","_blank");

// If class exist (Header) -> init
if($(".css-gmuwbf").length ) {

// // // // // // // // // // read last settings // // // // // // // //
  (async () => {

      triplesound = await GM.getValue('triplesound');
      caller      = await GM.getValue('caller');
      boosound    = await GM.getValue('boosound');
})();

    if (typeof triplesound == 'undefined')
    { triplesound = '0';}

    if (typeof caller == 'undefined')
    { caller = 'x';}

    if (typeof boosound == 'undefined')
    { boosound = '0';}


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

var x = $(".css-1tq00ko").text();
var x0 = $(".css-1tq00ko:eq(0)").text(); // Scrore-Feld
var x1 = $(".css-1tq00ko:eq(1)").text(); // 1. Dart
var x2 = $(".css-1tq00ko:eq(2)").text(); // 2. Dart
var x3 = $(".css-1tq00ko:eq(3)").text(); // 3. Dart
var gameshot1 = $(".css-x3m75h").eq(0).text(); // Spieler 1
var gameshot2 = $(".css-x3m75h").eq(1).text(); // Spieler 2
var gameshot3 = $(".css-x3m75h").eq(2).text(); // Spieler 3
var gameshot4 = $(".css-x3m75h").eq(3).text(); // Spieler 4
var gameshot5 = $(".css-x3m75h").eq(4).text(); // Spieler 5
var gameshot6 = $(".css-x3m75h").eq(5).text(); // Spieler 6
   // console.log('P1: '+gameshot1 + '- P2: '+ gameshot2);

//// Bust-Ausgabe ////
if (x0 == 'BUST' && busted == 0) {
        soundGo(server+caller+"0"+dotmp3, audio);
        busted = 1;
    }

//// Gameshot-Ausgabe ////

        // Gameshot aktivieren
        $("button:contains('Undo'),button:contains('Next Leg'),button:contains('Finish'),button:contains('Start')").on( "click", function() {
            gameshot_status = 0;

        })
/// Gameshot ///
    if (  gameshot_status != 1 && (gameshot1 == "0" || gameshot2 == "0" || gameshot3 == "0"|| gameshot4 == "0"|| gameshot5 == "0"|| gameshot6 == "0")   ){
    gameshot_status = 1;

        if( $("button:contains('Finish')").length ){
              soundGo(server+caller+"/gameshot and the match"+dotmp3, audio);

              }
          else {
              soundGo(server+caller+"/gameshot"+dotmp3, audio);
          }

        if (gameshot1 == "0") {
            $(".css-x3m75h").eq(0).html(getDarts()); }
        if (gameshot2 == "0") {
            $(".css-x3m75h").eq(1).html(getDarts()); }
                if (gameshot3 == "0") {
            $(".css-x3m75h").eq(2).html(getDarts()); }
          if (gameshot4 == "0") {
            $(".css-x3m75h").eq(3).html(getDarts()); }
          if (gameshot5 == "0") {
            $(".css-x3m75h").eq(4).html(getDarts()); }
          if (gameshot6 == "0") {
            $(".css-x3m75h").eq(5).html(getDarts()); }


    }
   //// END Gameshot ////




    ///////////////////////////////////////////////// TRIPLE CALLER ///////////////////////////
    if(triplesound == 1){
    // Triple 1st dart
    if (x1.includes("T") && t1 === 0 && $(".css-1tq00ko:eq(1)").closest('div').attr('class') == 'css-rzdgh7' && called == 0){
        t1 = 1;
        soundGo( "https://autodarts.x10.mx/russ_bray/triple_beep.mp3", audio);
        }
    // Triple 2st dart
    else if(x2.includes("T") && t2 === 0 && $(".css-1tq00ko:eq(2)").closest('div').attr('class') == 'css-rzdgh7' && called == 0){
        t2 = 1;
        soundGo( "https://autodarts.x10.mx/russ_bray/triple_beep.mp3", audio);
        }
    // Triple 3rd dart
    else if(x3.includes("T") && t3 === 0 && $(".css-1tq00ko:eq(3)").closest('div').attr('class') == 'css-rzdgh7' && called == 0){
        t3 = 1;
        soundGo( "https://autodarts.x10.mx/russ_bray/triple_beep.mp3", audio);
        }
    }
///////////////////////////////////////////////// END TRIPLE CALLER ///////////////////////////

        ///////////////////////////////////////////////// TRIPLE CALLER E-Dart Löwen///////////////////////////
    if(triplesound == 2) {
    // Triple 20 1st dart
    if ( x1.includes("T20") && t1 === 0 && $(".css-1tq00ko:eq(1)").closest('div').attr('class') == 'css-rzdgh7' && called == 0){
        t1 = 1;
        soundGo("https://autodarts.x10.mx/russ_bray/SoundHwTriple20_old.wav", audio);
        }
    // Triple 19 1st dart
    else if ( x1.includes("T19") && t1 === 0 && $(".css-1tq00ko:eq(1)").closest('div').attr('class') == 'css-rzdgh7' && called == 0){
        t1 = 1;
        soundGo("https://autodarts.x10.mx/russ_bray/SoundHwTriple19_old.wav", audio);
        }
    // Triple 18 1st dart
    else if ( x1.includes("T18") && t1 === 0 && $(".css-1tq00ko:eq(1)").closest('div').attr('class') == 'css-rzdgh7' && called == 0){
        t1 = 1;
        soundGo("https://autodarts.x10.mx/russ_bray/SoundHwTriple18_old.wav", audio);
        }
    // Triple 17 1st dart
    if ( x1.includes("T17") && t1 === 0 && $(".css-1tq00ko:eq(1)").closest('div').attr('class') == 'css-rzdgh7' && called == 0){
        t1 = 1;
        soundGo("https://autodarts.x10.mx/russ_bray/SoundHwTriple17_old.wav", audio);
        }

        /// 2. Dart
    // Triple 20 1st dart
    if ( x2.includes("T20") && t2 === 0 && $(".css-1tq00ko:eq(2)").closest('div').attr('class') == 'css-rzdgh7' && called == 0){
        t2 = 1;
        soundGo("https://autodarts.x10.mx/russ_bray/SoundHwTriple20_old.wav", audio);
        }
    // Triple 19 1st dart
    else if ( x2.includes("T19") && t2 === 0 && $(".css-1tq00ko:eq(2)").closest('div').attr('class') == 'css-rzdgh7' && called == 0){
        t2 = 1;
        soundGo("https://autodarts.x10.mx/russ_bray/SoundHwTriple19_old.wav", audio);
        }
    // Triple 18 1st dart
    else if ( x2.includes("T18") && t2 === 0 && $(".css-1tq00ko:eq(2)").closest('div').attr('class') == 'css-rzdgh7' && called == 0){
        t2 = 1;
        soundGo("https://autodarts.x10.mx/russ_bray/SoundHwTriple18_old.wav", audio);
        }
    // Triple 17 1st dart
    if ( x2.includes("T17") && t2 === 0 && $(".css-1tq00ko:eq(2)").closest('div').attr('class') == 'css-rzdgh7' && called == 0){
        t2 = 1;
        soundGo("https://autodarts.x10.mx/russ_bray/SoundHwTriple17_old.wav", audio);
        }


        /// 3. Dart
    // Triple 20 1st dart
    if ( x3.includes("T20") && t3 === 0 && $(".css-1tq00ko:eq(3)").closest('div').attr('class') == 'css-rzdgh7' && called == 0){
        t3 = 1;
        soundGo("https://autodarts.x10.mx/russ_bray/SoundHwTriple20_old.wav", audio);
        }
    // Triple 19 1st dart
    else if ( x3.includes("T19") && t3 === 0 && $(".css-1tq00ko:eq(3)").closest('div').attr('class') == 'css-rzdgh7' && called == 0){
        t3 = 1;
        soundGo("https://autodarts.x10.mx/russ_bray/SoundHwTriple19_old.wav", audio);
        }
    // Triple 18 1st dart
    else if ( x3.includes("T18") && t3 === 0 && $(".css-1tq00ko:eq(3)").closest('div').attr('class') == 'css-rzdgh7' && called == 0){
        t3 = 1;
        soundGo("https://autodarts.x10.mx/russ_bray/SoundHwTriple18_old.wav", audio);
        }
    // Triple 17 1st dart
    else if ( x3.includes("T17") && t3 === 0 && $(".css-1tq00ko:eq(3)").closest('div').attr('class') == 'css-rzdgh7' && called == 0){
        t3 = 1;
        soundGo("https://autodarts.x10.mx/russ_bray/SoundHwTriple17_old.wav", audio);
        }


    }


///////////////////////////////////////////////// Miss CALLER ///////////////////////////
if(boosound == 1){

    // miss 1st dart
    if ( x1.includes("M") && m1 === 0 && $(".css-1tq00ko:eq(1)").closest('div').attr('class') == 'css-rzdgh7' && called == 0)
    {   m1 = 1;
        soundGo("https://autodarts.x10.mx/russ_bray/miss_1st_dart.mp3", audio);
    }
    // miss 2st dart
    else if ( x2.includes("M") && m2 === 0 && $(".css-1tq00ko:eq(2)").closest('div').attr('class') == 'css-rzdgh7' && called == 0)
    {   m2 = 1;
        soundGo("https://autodarts.x10.mx/russ_bray/miss_2nd_dart.mp3", audio);
    }

    // miss 3rd dart
    else if ( x3.includes("M") && m3 === 0 && $(".css-1tq00ko:eq(3)").closest('div').attr('class') == 'css-rzdgh7' && called == 0)
    {    m3 = 1;
         soundGo("https://autodarts.x10.mx/russ_bray/miss_3rd_dart.mp3", audio);
    }
}


    // Caller reset
     if( (x1 == '' || $(".css-1tq00ko:eq(3)").closest('div').attr('class') != 'css-rzdgh7') && called == 1) {
          called = 0; busted = 0;
     }
// Korrektur nach Klick auf Ok -> Score auslesen und Caller erneut aktivieren (called=0)
    $("button:contains('Ok')").on( "click", function() {
        called = 0; // caller für letzte Aufnahme aktivieren
        x0 = $(".css-1tq00ko:eq(0)").text(); // Score auslesen
    });

// Caller if 3rd Dart has score and called = 0
    if( $(".css-1tq00ko:eq(3)").closest('div').attr('class') == 'css-rzdgh7' && called == 0 && caller != 'x') {
        called = 1;
        soundGo(server+caller+'/'+x0+dotmp3, audio); // Wert in Audio-Funktion übergeben

     //   console.log('Caller Ausgabe!');
     //   console.log('Language: '+language);
     //   console.log('Caller: '+ caller);

        t1 = 0; t2 = 0; t3 = 0;
        m1 = 0; m2 = 0; m3 = 0;
    }




    // Sound-Option-Selects einfügen wenn noch nicht existiert
if($("#caller").length == 0) {

  $(".css-a6m3v9").append('<select id="caller" name="caller" class="css-1xbroe7" style="padding:5px 5px 5px 5px;"><option selected disabled style="background-color: #353d47">Caller</option><option value="x" style="background-color: #353d47">OFF</option><option value="1_male_eng" style="background-color: #353d47">Male eng</option><option value="google_eng" style="background-color: #353d47">Female eng</option><option value="google_fr" style="background-color: #353d47">Female fr</option><option value="google_de" style="background-color: #353d47">Female de</option><option value="russ_bray" style="background-color: #353d47">Russ B</option><option value="georgeno" style="background-color: #353d47">George N</option><option value="shorty" style="background-color: #353d47">Shorty eng</option><option value="haulpinks" style="background-color: #353d47">Caller Paul eng</option><option value="bayrisch" style="background-color: #353d47">Bavarian male</option></select>');

    $(document).on('change', '#caller', function(){

      caller = $("#caller").find(":selected").val();

        console.log('Neuer Caller gewählt: '+caller);
        // Speichern
        (async () => {
            await GM.setValue('caller', caller);
         })();


        if(caller == 'russ_bray') {
            server = 'http://autodarts.x10.mx/';
            caller = 'russ_bray';
            dotmp3 = '.mp3';
               $("#caller option[value='russ_bray']").prop('selected', true);
            console.log('rb aktiv');
        }
         if(caller == 'georgeno') {
            server = 'http://autodarts.x10.mx/';
            caller = 'georgeno';
            dotmp3 = '.mp3';
               $("#caller option[value='georgeno']").prop('selected', true);
            console.log('georgeno aktiv');
        }
        else if(caller == 'shorty') {
            server = 'http://autodarts.x10.mx/';
            caller = 'shorty';
            dotmp3 = '.mp3';
               $("#caller option[value='shorty']").prop('selected', true);
            console.log('shorty aktiv');
        }

        else if(caller == 'haulpinks') {
            server = 'http://autodarts.x10.mx/';
            caller = 'haulpinks';
            dotmp3 = '.mp3';
               $("#caller option[value='haulpinks']").prop('selected', true);
            console.log('haulpinks aktiv');
        }


        else if(caller == 'bayrisch') {
            server = 'http://autodarts.x10.mx/';
            caller = 'bayrisch';
            dotmp3 = '.mp3';
               $("#caller option[value='bayrisch']").prop('selected', true);
            console.log('bayrisch aktiv');
        }

      else if(caller == '1_male_eng') {
            server = 'http://autodarts.x10.mx/';
            caller = '1_male_eng';
            dotmp3 = '.mp3';
               $("#caller option[value='1_male_eng']").prop('selected', true);
          console.log('1_male_eng aktiv');

        }

      else if(caller == 'google_eng') {
              dotmp3 = '';
              language = 'en';
            //  server = 'http://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl='+language+'&q=';
            server = 'https://autodarts.de.cool/mp3_helper.php?language='+language+'&text=';
              caller = '';
            $("#caller option[value='google_eng']").prop('selected', true);
          console.log('eng aktiv');

        }

      else if(caller == 'google_de') {
              dotmp3 = '';
              language = 'de';
              //server = 'https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl='+language+'&q=';
              server = 'https://autodarts.de.cool/mp3_helper.php?language='+language+'&text=';
            $("#caller option[value='google_de']").prop('selected', true);
          caller = '';
        }

      else  if(caller == 'google_fr') {
              dotmp3 = '';
              language = 'fr';
              server = 'https://translate.google.com/translate_tts?ie=UTF-8&client=tw-ob&tl='+language+'&q=';
            server = 'https://autodarts.de.cool/mp3_helper.php?language='+language+'&text=';
              caller = '';
            $("#caller option[value='google_fr']").prop('selected', true);
        }


    })

//////  Triple-Select
$(".css-a6m3v9").append('<select id="triplesound" name="triplesound" class="css-1xbroe7" style="padding:5px;"><option selected disabled style="background-color: #353d47">Triple-Sound</option><option value="0" style="background-color: #353d47">OFF</option><option value="1" style="background-color: #353d47">Beep on</option><option value="2" style="background-color: #353d47">Löwen (Softtip)</option></select>');
    $(document).on('change', '#triplesound', function(){
      triplesound = $("#triplesound").find(":selected").val();

        (async () => {
            await GM.setValue('triplesound', triplesound);

         })();

    })

     // Boo-Select
  $(".css-a6m3v9").append('<select id="boosound" name="boosound" class="css-1xbroe7" style="padding:5px;"><option selected disabled style="background-color: #353d47">Boo-Sound</option><option value="1" style="background-color: #353d47">ON</option><option value="0" style="background-color: #353d47">OFF</option></select>');

    $(document).on('change', '#boosound', function(){
      boosound = $("#boosound").find(":selected").val();
       // Speichern
        (async () => {
            await GM.setValue('boosound', boosound);
         })();
    })




     //Standard-Caller nach Start initialisieren:
     $('#caller').val(caller).change();


} // end add dropdowns

}
},200);

    });


})();