Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kwyntes/8fe9334fd6e3b9d5802a49304a91379e to your computer and use it in GitHub Desktop.
Save kwyntes/8fe9334fd6e3b9d5802a49304a91379e to your computer and use it in GitHub Desktop.
chess.com autosettings userscript
// ==UserScript==
// @name chess.com autosettings
// @match https://*.chess.com/play/*
// @version 1.0
// ==/UserScript==
const $ = slt => document.querySelector(slt);
const sleep = ms => new Promise(rsv => setTimeout(rsv, ms));
const select = (val, slt) => {
const el = (slt ? s => $(slt).querySelector(s) : $)('[value="' + val + '"]').parentElement;
el.value = val;
el.dispatchEvent(new Event('change'));
};
(async () => {
await sleep(1000);
// Dismiss guest popup
const gb = $('#guest-button');
gb && gb.click();
// Open Settings
$('#board-controls-settings').click();
await sleep(1000);
// Try statement because settings are not yet stored in localStorage the first time this script is used
try {
// Set Pieces from localStorage
select(localStorage.getItem('@userscript@__pref_pieces'), '[data-cy=piece-set-selector]');
// Set Board from localStorage
select(localStorage.getItem('@userscript@__pref_board'), '[data-cy=board-style-selector]');
} catch {}
// Set Animation Type to Arcade
select('arcade');
// Go to the Play tab
$('[data-tab=play]').click();
await sleep(10);
// Disable Confirm Resign
$('#confirmResign').checked && $('#confirmResign').click();
// Go to the Live sub-tab
$('[data-tab=playSettingsLive]').click();
await sleep(10);
// Enable Premoves & Low Time Warning
$('#premoves').checked || $('#premoves').click();
$('#lowTimeWarning').checked || $('#lowTimeWarning').click();
// Go back to the Board tab
$('[data-tab=board]').click();
// Make save button also save modified settings to localStorage
$('[data-cy=save]').addEventListener('click', () => {
localStorage.setItem('@userscript@__pref_pieces', $('[data-cy=piece-set-selector]').value);
localStorage.setItem('@userscript@__pref_board', $('[data-cy=board-style-selector]').value);
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment