Model Selector for lmarena

Trying to use AI for free :)

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

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