Force ChatGPT-4 Model

Redirect to ChatGPT-4 model if not already set, avoiding redirect loops

目前為 2024-07-17 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Force ChatGPT-4 Model
// @namespace    http://tampermonkey.net/
// @version      0.1
// @license      GPLv3
// @description  Redirect to ChatGPT-4 model if not already set, avoiding redirect loops
// @author       You
// @match        https://chatgpt.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var checkInterval; // Variable to store the interval ID

    function findElementByAttributes() {
        // Use querySelector to find the first div that matches the criteria
        return document.querySelector('div[type="button"][id^="radix-:"]');
    }

    function currentUrlHasModel() {
        // Check if the URL has the model query parameter
        const urlParams = new URLSearchParams(window.location.search);
        return urlParams.has('model');
    }

    function checkAndRedirect() {
        if (currentUrlHasModel()) {
            console.log('ChatGPT-4 model is already set, stopping checks.');
            clearInterval(checkInterval); // Stop the interval if model is already set
            return;
        }

        console.log('Checking for the element with specific attributes...');
        var element = findElementByAttributes();
        console.log('Element:', element);

        if (element) {
            console.log('Target element found. Redirecting to ChatGPT-4 model...');
            window.location.href = "https://chatgpt.com/?model=gpt-4"; // Perform redirect
        } else {
            console.log('Target element not found, checking again...');
        }
    }

    // Set up an interval to check for the element every 1000 milliseconds
    checkInterval = setInterval(checkAndRedirect, 1000);

    // Optional: Clear the interval on page unload to clean up resources
    window.addEventListener('unload', function() {
        clearInterval(checkInterval);
    });
})();