Model Selector for lmarena

Trying to use AI for free :)

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

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