Model Selector for lmarena

Trying to use AI for free :)

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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