您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Rematch-Button on mainpage with the last 2-4 players
当前为
// ==UserScript== // @name Autodarts - Rematch-Button // @namespace http://tampermonkey.net/ // @version 0.40 // @description Rematch-Button on mainpage with the last 2-4 players // @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'; var data = ''; const avcpuPPR = ["", 20, 30, 40, 50, 60 ,70 , 80 ,90 ,100, 110 ,120]; function startgame(){ $.ajax({ url: 'https://api.autodarts.io/gs/v0/lobbies/'+location.pathname.split("/")[2]+'/start', data: data, type: 'POST', asynch: false, xhrFields: { withCredentials: true }, success: function(start){ GM.deleteValue("player1"); GM.deleteValue("player2"); GM.deleteValue("player3"); GM.deleteValue("player4"); for (let index = 0; index < start['players'].length; ++index) { if(start['players'][index]['name'] != ''){ (async () => { await GM.setValue("player"+(index+1), start['players'][index]['name'].toUpperCase() ); })(); } } } }) } function removeplayer(playerID) { fetch('https://api.autodarts.io/gs/v0/lobbies/'+location.pathname.split("/")[2]+'/players/by-index/'+playerID, { method: 'DELETE', credentials: 'include', }) } function addplayer(playername, boardID, avcpuPPR) { if(typeof playername !== "undefined" ) { if(playername.substring(0,9) === 'BOT LEVEL') { var level = playername.substring(10); console.log('Level: '+ level); data = '{"name":"'+playername+'","cpuPPR":'+avcpuPPR[level]+'}'; } else { data ='{"name":"'+playername+'","boardId":"'+boardID+'"}'; } $.ajax({ url: 'https://api.autodarts.io/gs/v0/lobbies/'+location.pathname.split("/")[2]+'/players', data: data, type: 'POST', contentType: "text/xml", dataType: "text", asynch: false, xhrFields: { withCredentials: true }, success: function(data) { }, error: function(e){} }); } } $.urlParam = function(name){ var results = new RegExp('[\?&]' + name + '=([^&#]*)').exec(window.location.href); if (results==null){ return null; } else{ return results[1] || 0; } } var player1 = ''; var player2 = ''; var player3 = ''; var player4 = ''; var rematch = ''; var player_clicked = 0; var gamemode = ''; var startx01 = ''; var variante = ''; var firstto = ''; var gameconditions = ''; var account; const players = []; // Load last players (async () => { player1 = await GM.getValue('player1'); player2 = await GM.getValue('player2'); player3 = await GM.getValue('player3'); player4 = await GM.getValue('player4'); gamemode = await GM.getValue('gamemode'); startx01 = await GM.getValue('startx01'); variante = await GM.getValue('variante'); firstto = await GM.getValue('firstto'); })(); setInterval(function() { // Lobby autostart if($('button:contains("Open Lobby")').length != 0 && $.urlParam('rematch') != null) { rematch = $.urlParam('rematch'); $('button:contains("Off")').eq(0).click(); $('button:contains("Private")').click(); setTimeout(() => { $('button:contains("Open Lobby")').click(); }, 2000) } // add players and start game if( $('button:contains("Start game")').length != 0 && player_clicked == 0 && rematch != 0) { const boardID = $('.css-1wq9qmd option:selected').val(); setTimeout(function(){ $('button:contains("Join")').addClass("account css-1e89954"); $('.account').css('color', 'yellow') ; $('.account').text(account); }, 200); const delay = 250; setTimeout(function(){ startgame(); }, (delay*6)); // Player 1 starts if(rematch == 1){ setTimeout(function(){removeplayer(0);}, (delay*1)); setTimeout(function(){addplayer(player1, boardID,avcpuPPR); }, (delay*2)); setTimeout(function(){addplayer(player2, boardID,avcpuPPR); }, (delay*3)); setTimeout(function(){addplayer(player3, boardID,avcpuPPR); }, (delay*4)); setTimeout(function(){addplayer(player4, boardID,avcpuPPR); }, (delay*5)); } // Player 2 starts if(rematch == 2){ const delay = 250; setTimeout(function(){removeplayer(0);}, (delay*1)); setTimeout(function(){addplayer(player2, boardID,avcpuPPR); }, (delay*2)); setTimeout(function(){addplayer(player3, boardID,avcpuPPR); }, (delay*3)); setTimeout(function(){addplayer(player4, boardID,avcpuPPR); }, (delay*4)); setTimeout(function(){addplayer(player1, boardID,avcpuPPR); }, (delay*5)); } if(rematch == 3){ const delay = 250; setTimeout(function(){removeplayer(0);}, (delay*1)); setTimeout(function(){addplayer(player3, boardID,avcpuPPR); }, (delay*2)); setTimeout(function(){addplayer(player4, boardID,avcpuPPR); }, (delay*3)); setTimeout(function(){addplayer(player1, boardID,avcpuPPR); }, (delay*4)); setTimeout(function(){addplayer(player2, boardID,avcpuPPR); }, (delay*5)); } if(rematch == 4){ const delay = 250; setTimeout(function(){removeplayer(0);}, (delay*1)); setTimeout(function(){addplayer(player4, boardID,avcpuPPR); }, (delay*2)); setTimeout(function(){addplayer(player1, boardID,avcpuPPR); }, (delay*3)); setTimeout(function(){addplayer(player2, boardID,avcpuPPR); }, (delay*4)); setTimeout(function(){addplayer(player3, boardID,avcpuPPR); }, (delay*5)); } setTimeout(function(){ // $('button:contains("Start")').click(); }, 3000); player_clicked = 1; } // add Rematch-button to mainpage if(player1 !='' && player2 !='' && $('#rematch_button').length == 0 && typeof(player1) !== "undefined" && player1 !== null && typeof(player2) !== "undefined" && player2 !== null) { if(gamemode == 'X01') { var gameconditions = startx01 + ' | ' +variante + ' | ' + firstto; } else if(gamemode == 'Count Up') { gameconditions = 'Count-Up'; gamemode='count-up'; } else if(gamemode == 'Bull-off') { gameconditions = 'X01'; gamemode='X01'; } else { var gameconditions = gamemode; } var mainmenu = '<div><div class="chakra-stack css-1aucrbz"><span style="font-size: 3em;">REMATCH</span><div class="chakra-button css-hbk3el" style="font-size: 1em; color: yellow; min-height: 50px; " >'+gameconditions+'</div><a class="chakra-button css-z1xk1r" id="rematch_button" href="/lobbies/new/'+gamemode+'?rematch=1" style="font-size: 1em; min-height: 50px; width: 500px; "><span style="font-size: 1.5em;">'+player1+'</span> to throw first</a><a class="chakra-button css-z1xk1r" id="rematch_button" href="/lobbies/new/'+gamemode+'?rematch=2" style="font-size: 1em; min-height: 50px; width: 500px; "><span style="font-size: 1.5em;">'+player2+'</span> to throw first</a>'; // 3. Spieler? if( typeof(player3) !== "undefined" && player3 !== null){ mainmenu += '<a class="chakra-button css-z1xk1r" id="rematch_button" href="/lobbies/new/'+gamemode+'?rematch=3" style="font-size: 1em; min-height: 50px; width: 500px; "> <span style="font-size: 1.5em;">'+player3+'</span> to throw first</a>'; } // 4. Spieler? if( typeof(player4) !== "undefined" && player4 !== null){ mainmenu += '<a class="chakra-button css-z1xk1r" id="rematch_button" href="/lobbies/new/'+gamemode+'?rematch=4" style="font-size: 1em; min-height: 50px; width: 500px; "> <span style="font-size: 1.5em;">'+player4+'</span> to throw first</a>'; } // OLD $('.css-lw6pyq').first().prepend(mainmenu+'</div>'); $('.css-1aucrbz').first().prepend(mainmenu+'</div>'); } /// read player-names if( $('button:contains("Abort")').length != 0 ) { // only on own match-page // Save Gamemode: gamemode = $('#ad-ext-game-variant').text(); startx01 = $('.css-bs3vp6').eq( 1 ).text(); variante = $('.css-bs3vp6').eq( 2 ).text(); firstto = $('.css-bs3vp6').eq( 3 ).text(); (async () => { await GM.setValue("gamemode" , gamemode ); await GM.setValue("startx01" , startx01 ); await GM.setValue("variante" , variante ); await GM.setValue("firstto" , firstto ); })(); //console.log('gamemode '+gamemode); //console.log('startx01 '+startx01); //console.log('variante '+variante); //console.log('firstto '+firstto); } // Refresh Mainpage with new names console.log(window.location.href); if( window.location.href == 'https://play.autodarts.io/' || window.location.href == 'https://play.autodarts.io' ) { $( '#root' ).remove(); location.replace('https://play.autodarts.io?reloaded'); } $('button:contains("Start game")').on( "click", function() { startgame(); }); },1000); // end-interval })();