Replay-button on mainpage with the last 2-4 players
当前为
// ==UserScript==
// @name Autodarts Replay-Button
// @namespace http://tampermonkey.net/
// @version 0.23
// @description Replay-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';
$.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 documenttitle = 'Autodarts ';
var gamemode = '';
var startx01 = '';
var variante = '';
var firstto = '';
var gameconditions = '';
var account;
// 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("Open Lobby")').click();
}
// add players and start game
if( $('button:contains("Start")').length != 0
&& player_clicked == 0 && rematch != 0) {
setTimeout(function(){
account = $('.ad-ext-player-name').eq( 1 ).text();
$("[aria-label='Delete player']").click();
}, 100);
setTimeout(function(){
$('button:contains("Join")').addClass("account css-1e89954");
$('.account').css('color', 'yellow') ;
$('.account').text(account);
}, 200);
// Player 1 starts
if(rematch == 1){
setTimeout(function(){
$('button:contains("'+player1+'")').click();
}, 500);
setTimeout(function(){
$('button:contains("'+player2+'")').click();
}, 1000);
setTimeout(function(){
$('button:contains("'+player3+'")').click();
}, 1500);
setTimeout(function(){
$('button:contains("'+player4+'")').click();
}, 2000);
}
// Player 2 starts
if(rematch == 2){
setTimeout(function(){
$('button:contains("'+player2+'")').click();
}, 500);
setTimeout(function(){
$('button:contains("'+player3+'")').click();
}, 1000);
setTimeout(function(){
$('button:contains("'+player4+'")').click();
}, 1500);
setTimeout(function(){
$('button:contains("'+player1+'")').click();
}, 2000);
}
// Player 3 starts
if(rematch == 3){
setTimeout(function(){
$('button:contains("'+player3+'")').click();
}, 500);
setTimeout(function(){
$('button:contains("'+player4+'")').click();
}, 1000);
setTimeout(function(){
$('button:contains("'+player1+'")').click();
}, 1500);
setTimeout(function(){
$('button:contains("'+player2+'")').click();
}, 2000);
}
// Player 3 starts
if(rematch == 4){
setTimeout(function(){
$('button:contains("'+player4+'")').click();
}, 500);
setTimeout(function(){
$('button:contains("'+player1+'")').click();
}, 1000);
setTimeout(function(){
$('button:contains("'+player2+'")').click();
}, 1500);
setTimeout(function(){
$('button:contains("'+player3+'")').click();
}, 2000);
}
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 {
var gameconditions = gamemode;
}
// $('.css-lw6pyq').first().prepend('<span style="font-size: 3em;">REMATCH</span><div class="chakra-button css-hbk3el" style="font-size: 1em; color: yellow;" >'+gameconditions+'</div><a class="chakra-button css-hbk3el" id="rematch_button" href="/lobbies/new/'+gamemode+'?rematch=1" style=""><br /><span style=" font-size: 0.4em; text-align: center !important;">'+player1+'<br /><span style="font-size: 0.5em; line-height: 40px; vertical-align: sup;">vs</span><br />'+player2+'</span></a><a class="chakra-button css-hbk3el" id="rematch_button" href="/lobbies/new/'+gamemode+'?rematch=2" style=""><span style=" font-size: 0.4em; text-align: center !important;">'+player2+'<br /><span style="font-size: 0.5em; line-height: 40px; vertical-align: sup;">vs</span><br />'+player1+'</span></a>');
var mainmenu = '<div><div class="chakra-stack css-lw6pyq"><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-hbk3el" 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-hbk3el" 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-hbk3el" 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-hbk3el" 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>';
}
$('.css-lw6pyq').first().prepend(mainmenu+'</div>');
}
/// read player-names
if( $('button:contains("Abort")').length != 0 ) { // only on own match-page
const players = new Array();
var count = 1;
GM.deleteValue("player1");
GM.deleteValue("player2");
GM.deleteValue("player3");
GM.deleteValue("player4");
$( ".ad-ext-player-name" ).each(function() {
console.log('Neuer Spieler: '+$(this).text());
players.push( $(this).text() );
// save players-settings
if($(this).text() != ''){
(async () => {
await GM.setValue("player"+count, $(this).text() );
})();
documenttitle += $(this).text() + " - ";
count++;
}
});
// Save Gamemode:
gamemode = $('#ad-ext-game-variant').text();
startx01 = $('.css-1eveppl').eq( 1 ).text();
variante = $('.css-1eveppl').eq( 2 ).text();
firstto = $('.css-1eveppl').eq( 3 ).text();
(async () => {
await GM.setValue("gamemode" , gamemode );
await GM.setValue("startx01" , startx01 );
await GM.setValue("variante" , variante );
await GM.setValue("firstto" , firstto );
})();
}
// Change document-title
document.title = documenttitle.slice(0, -3);
// 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');
}
},1000); // end-interval
})();