Model Selector for lmarena

Trying to use AI for free :)

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
        }
    });
})();