Hides 'New Opponent' Button While Rematch is Still Available
目前為
// ==UserScript==
// @name Lichess Hide New Opponent Button
// @namespace http://userstyles.org
// @description Hides 'New Opponent' Button While Rematch is Still Available
// @author 636597
// @include *://*lichess.org/*
// @run-at document-start
// @version 0.1
// ==/UserScript==
var lichess_ground_class_name = "lichess_ground";
var lichess_ground_element = null;
var lichess_ground_observer = null;
var observerConfig = {
subtree: true ,
attributes: true,
childList: true,
characterData: true
};
function hideNewOpponentButton() {
var follow_up_el = document.getElementsByClassName( "follow_up" );
if ( follow_up_el ) {
if ( follow_up_el[ 0 ] ) {
follow_up_el[ 0 ].childNodes[ 1 ].setAttribute("style", "visibility: hidden !important");
}
}
}
function showNewOpponentButton() {
var follow_up_el = document.getElementsByClassName( "follow_up" );
if ( follow_up_el ) {
if ( follow_up_el[ 0 ] ) {
follow_up_el[ 0 ].childNodes[ 1 ].setAttribute("style", "visibility: visible !important");
}
}
}
function loadObserver() {
lichess_ground_observer = new MutationObserver(function(mutations) {
mutations.forEach(function( mutation , index ) {
if ( mutation.type === "childList" ) {
if ( mutation.target.className === "table_inner" ) {
console.log( "Game OVER ???" );
hideNewOpponentButton();
}
}
else if ( mutation.type === "attributes" ) {
switch( mutation.target.className ) {
case "username user_link black offline":
console.log( "White Player === OFFLINE" );
break;
case "username user_link black offline":
console.log( "Black Player === OFFLINE" );
break;
case "button rematch white disabled":
console.log( "Rematch Button === WHITE ==== DISABLED" );
showNewOpponentButton();
break;
case "button rematch white enabled":
console.log( "Rematch Button === WHITE ==== ENABLED" );
//hideNewOpponentButton()
break;
case "button rematch black disabled":
console.log( "Rematch Button === BLACK ==== DISABLED" );
showNewOpponentButton();
break;
case "button rematch black enabled":
console.log( "Rematch Button === BLACK ==== ENABLED" );
//hideNewOpponentButton()
break;
default:
break;
}
}
});
});
lichess_ground_observer.observe( lichess_ground_element , observerConfig );
console.log( "Lichess Hide 'New Opponent' Button Script Loaded" );
}
(function() {
var ready = setInterval(function(){
var x1 = document.getElementsByClassName( lichess_ground_class_name );
if ( x1 ) { if ( x1[ 0 ] ) { lichess_ground_element = x1[0]; clearInterval( ready ); loadObserver(); } }
} , 2 );
})();