Gemini Model Memory

Automatically select default model. Remembers user's choice.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey 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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Gemini Model Memory
// @namespace    http://greasyfork.org/
// @version      1.9
// @description  Automatically select default model. Remembers user's choice.
// @author       Bui Quoc Dung
// @match        https://gemini.google.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    if (window.self !== window.top) return;

    const siteConfig = {
        selectors: {
            pickerBtn: 'button[data-test-id="bard-mode-menu-button"]',
            menuItems: '[role="menuitemradio"], [role="menuitem"]'
        }
    };

    const timings = {
        interval: 1000,
        renderDelay: 600,
        cooldown: 1500
    };

    const MODELS = {
        0: { keywords: ["Flash", "Nhanh", "Fast"] },
        1: { keywords: ["Thinking", "Tư duy"] },
        2: { keywords: ["Pro", "Advanced"] }
    };

    let savedIndex = localStorage.getItem('gemini_saved_model_index');
    let targetModelId = (savedIndex !== null && MODELS[savedIndex]) ? parseInt(savedIndex) : 1;

    let isSwitching = false;
    let userManualSelection = false;

    function isAppHomePage() {
        const regex = /^https:\/\/gemini\.google\.com\/(u\/\d+\/)?app\/?([?#].*)?$/;
        return regex.test(window.location.href);
    }

    document.addEventListener('click', (e) => {
        if (isSwitching) return;

        const pickerBtn = document.querySelector(siteConfig.selectors.pickerBtn);
        const item = e.target.closest(siteConfig.selectors.menuItems);

        if (item) {
            const itemText = item.innerText || item.textContent || "";
            for (let key in MODELS) {
                if (MODELS[key].keywords.some(k => itemText.includes(k))) {
                    targetModelId = parseInt(key);
                    localStorage.setItem('gemini_saved_model_index', key);
                    break;
                }
            }
            userManualSelection = false;
        } else if (pickerBtn && pickerBtn.contains(e.target)) {
            userManualSelection = true;
        } else {
            userManualSelection = false;
        }
    }, true);

    setInterval(() => {
        if (!isAppHomePage() || isSwitching || userManualSelection) return;

        const pickerBtn = document.querySelector(siteConfig.selectors.pickerBtn);
        if (!pickerBtn) return;

        const currentText = pickerBtn.innerText || pickerBtn.textContent || "";
        const targetModel = MODELS[targetModelId];

        if (!targetModel) return;
        if (targetModel.keywords.some(k => currentText.includes(k))) return;

        isSwitching = true;
        pickerBtn.click();

        setTimeout(() => {
            const menuItems = document.querySelectorAll(siteConfig.selectors.menuItems);
            let clicked = false;

            for (let item of menuItems) {
                if (item.getBoundingClientRect().width > 0) {
                    const itemText = item.innerText || item.textContent || "";
                    if (targetModel.keywords.some(k => itemText.includes(k))) {
                        item.click();
                        clicked = true;
                        break;
                    }
                }
            }

            if (!clicked) document.body.click();

            setTimeout(() => {
                isSwitching = false;
            }, timings.cooldown);

        }, timings.renderDelay);
    }, timings.interval);

})();