Lichess Hide New Opponent Button

Hides 'New Opponent' Button While Rematch is Still Available

当前为 2018-04-29 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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 );
})();