Model Selector for lmarena

Trying to use AI for free :)

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Model Selector for lmarena
// @namespace    http://tampermonkey.net/
// @version      2025-11-15
// @description  Trying to use AI for free :)
// @author       Animesh Dhakal
// @match        https://lmarena.ai/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    const urlParams = new URLSearchParams(window.location.search);

    function waitForElm(selector) {
        return new Promise(resolve => {
            if (document.querySelector(selector)) {
                return resolve(document.querySelector(selector));
            }

            const observer = new MutationObserver(() => {
                const el = document.querySelector(selector);
                if (el) {
                    observer.disconnect();
                    resolve(el);
                }
            });

            observer.observe(document.body, {
                childList: true,
                subtree: true
            });
        });
    }


    async function waitUntilEnabled(button, timeoutMs = 10000, intervalMs = 100) {
        const start = Date.now();

        return new Promise((resolve, reject) => {
            const check = () => {
                const disabled = button.disabled || button.getAttribute('aria-disabled') === 'true';

                if (!disabled) {
                    resolve(button);
                    return;
                }

                if (Date.now() - start >= timeoutMs) {
                    reject(new Error('submitButton did not become enabled in time'));
                    return;
                }

                setTimeout(check, intervalMs);
            };

            check();
        });
    }

    window.addEventListener("load", async function() {
        let model = urlParams.get('model');
        const query = urlParams.get('query');
        const chatModality = urlParams.get('chat-modality') || 'direct';

        if(!model) {
            console.log("bot found");
            model = chatModality == 'direct' ? 'gpt-5.1' : 'ppl-sonar-pro-high';
        }

        // Open the model dropdown
        document.querySelectorAll("button[role='combobox']")[3].click();

        const elem = await waitForElm(`div[data-value="${model}"]`);
        elem.click();


        if (!query) {
         return;
        }

        const messageField = document.querySelector('[name="message"');
        const prototype = Object.getPrototypeOf(messageField);
        const valueSetter = Object.getOwnPropertyDescriptor(prototype, "value").set;
        valueSetter.call(messageField, query);

        // Dispatch an input event that bubbles
        const inputEvent = new Event("input", { bubbles: true });
        messageField.dispatchEvent(inputEvent);

        const submitButton = document.querySelector('button[type="submit"]');

        try {
            const enabledButton = await waitUntilEnabled(submitButton);
            enabledButton.click();
        } catch (err) {
            console.error(err);
        }
    });
})();