Skip to content

Instantly share code, notes, and snippets.

@surajsharma
Created April 9, 2025 13:11
Show Gist options
  • Save surajsharma/fa9d257923e70aaaea4ce822661c6dc1 to your computer and use it in GitHub Desktop.
Save surajsharma/fa9d257923e70aaaea4ce822661c6dc1 to your computer and use it in GitHub Desktop.
better lmarena.ai
// ==UserScript==
// @name lmarena.ai Custom Tweaks (Wait for Height 0)
// @namespace http://tampermonkey.net/
// @version 1.5
// @description Suppress alert, hide element, and click Arena tab when model_selector_md height is zero
// @match https://lmarena.ai/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
// 🚫 Suppress alert box
window.alert = function () {
console.log('Alert suppressed by userscript.');
};
// βœ… Hide element by XPath
function getElementByXPath(xpath) {
return document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
function hideElement() {
const targetXPath = '/html/body/gradio-app/div/div/div[1]/div/div/div/div[2]/div/div[9]';
const el = getElementByXPath(targetXPath);
if (el) {
el.style.display = 'none';
console.log('Element hidden.');
} else {
setTimeout(hideElement, 500);
}
}
// πŸ–±οΈ Click the Arena tab button
function clickArenaTab() {
const button = document.getElementById('component-98-button');
if (button) {
button.click();
console.log('Arena tab clicked.');
setTimeout(simulateInputSequence, 1000); // slight delay to ensure input is ready
} else {
setTimeout(clickArenaTab, 500);
}
}
// πŸ” Wait until #model_selector_md has height 0
function waitForZeroHeight() {
const target = document.getElementById('model_selector_md');
if (!target) {
setTimeout(waitForZeroHeight, 500);
return;
}
const checkHeight = () => {
const height = target.offsetHeight;
if (height === 0) {
console.log('#model_selector_md height is 0. Clicking Arena tab...');
clickArenaTab();
} else {
setTimeout(checkHeight, 300);
}
};
checkHeight();
}
function simulateInputSequence() {
const firstInputXPath = '/html/body/gradio-app/div/div/div[1]/div/div/div/div[3]/div/div[2]/div[2]/div/div/div[2]/div[1]/div/div[2]/div/div[1]/div/input';
const secondInputXPath = '/html/body/gradio-app/div/div/div[1]/div/div/div/div[3]/div/div[2]/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div[1]/div/input';
const finalHideXPath = '/html/body/gradio-app/div/div/div[1]/div/div/div/div[1]';
const firstInput = getElementByXPath(firstInputXPath);
const secondInput = getElementByXPath(secondInputXPath);
const simulateTyping = async (el, text) => {
el.focus();
el.value = '';
for (const char of text) {
el.value += char;
el.dispatchEvent(new Event('input', { bubbles: true }));
await new Promise(r => setTimeout(r, 80));
}
el.dispatchEvent(new Event('change', { bubbles: true }));
el.dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
el.dispatchEvent(new KeyboardEvent('keyup', { key: 'Enter', bubbles: true }));
};
if (!firstInput || !secondInput) {
console.log('Inputs not ready yet. Retrying...');
setTimeout(simulateInputSequence, 500);
return;
}
(async () => {
console.log('Typing "Claude"...');
await simulateTyping(firstInput, 'Claude');
await new Promise(r => setTimeout(r, 300));
console.log('Typing "grok"...');
await simulateTyping(secondInput, 'grok');
// βœ… Final action: hide top element
const finalElement = getElementByXPath(finalHideXPath);
if (finalElement) {
finalElement.style.display = 'none';
console.log('Final element hidden.');
} else {
console.log('Final element not found to hide.');
}
console.log('Finished input + cleanup.');
// βœ… Step 4: Focus textarea, type "hi", send it
const textareaXPath = '/html/body/gradio-app/div/div/div[1]/div/div/div/div[3]/div/div[4]/div[2]/div/div[2]/label/div/textarea';
const textarea = getElementByXPath(textareaXPath);
if (textarea) {
textarea.focus();
} else {
console.log('Textarea not found.');
}
})();
}
// πŸš€ On load, start everything
window.addEventListener('load', () => {
hideElement();
waitForZeroHeight();
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment