ChatGPT Search Shortcut

Search ChatGPT From Your Address Bar Without Having To Go To The Website

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension 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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         ChatGPT Search Shortcut
// @namespace    https://greasyfork.org/en/users/943407-webchantment
// @version      1.2
// @description  Search ChatGPT From Your Address Bar Without Having To Go To The Website
// @author       Webchantment
// @match        https://chat.openai.com/?search=*
// @grant        none
// ==/UserScript==

(async () => {

	const timeout = 500; //milliseconds

	const urlParams = new URLSearchParams(window.location.search);
	const searchInput = urlParams.get("search");

	const textarea = document.querySelector("form > * textarea");
	const button = document.querySelector("form > * button");

	if (searchInput && textarea && button) {
		setValue(textarea, searchInput);
		setTimeout(() => { button.click(); }, timeout);
	}

	//special method to set react input box values
	function setValue(input, value) {
		let nativeInputValueSetter = Object.getOwnPropertyDescriptor(input, "value").set;
		nativeInputValueSetter.call(input, value);

		let inputEvent = new Event("input", { bubbles: true });
		input.dispatchEvent(inputEvent);
	}

})();