-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatgpt-think-shortcut.user.js
More file actions
93 lines (80 loc) · 3.01 KB
/
chatgpt-think-shortcut.user.js
File metadata and controls
93 lines (80 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// ==UserScript==
// @name ChatGPT Think Shortcut
// @namespace nisc
// @version 2025.07.07-A
// @description Activate ChatGPT Thinking mode with Ctrl+Cmd+T (macOS) or Ctrl+Alt+T (Windows/Linux)
// @homepageURL https://github.com/nisc/chatgpt-userscripts/
// @downloadURL https://raw.githubusercontent.com/nisc/chatgpt-userscripts/main/chatgpt-think-shortcut.user.js
// @author nisc
// @match https://chatgpt.com/*
// @icon https://chatgpt.com/favicon.ico
// @run-at document-end
// @grant none
// ==/UserScript==
(function () {
'use strict';
// Configuration
const CONFIG = {
shortcut: {
key: 't',
requireShift: false,
requireCtrl: true
},
selectors: {
toolsButton: 'button#system-hint-button',
toolsPopupMenu: [
'div[data-side="bottom"][role="menu"][data-radix-menu-content]',
'div[data-radix-popper-content-wrapper] div[role="menu"]'
],
thinkMenuItem: 'div[role="menuitemradio"]',
thinkMenuItemText: 'div.flex.min-w-0.grow.items-center.gap-2\\.5 div.truncate'
},
text: 'Think for longer',
delay: 75
};
function findMenuItemByText(menu, text) {
return Array.from(menu.querySelectorAll(CONFIG.selectors.thinkMenuItem))
.find(item => {
const textDiv = item.querySelector(CONFIG.selectors.thinkMenuItemText);
return textDiv?.textContent.trim() === text;
});
}
function simulateRadixInteraction(element, { isButton = false } = {}) {
element.setAttribute('data-state', isButton ? 'open' : 'checked');
element.setAttribute(isButton ? 'aria-expanded' : 'aria-checked', 'true');
['pointerover', 'pointerenter', 'pointerdown', 'pointerup', 'click'].forEach(eventType => {
element.dispatchEvent(new PointerEvent(eventType, {
bubbles: true,
cancelable: true,
view: window,
pointerType: 'mouse'
}));
});
}
// Add keyboard shortcut listener
document.addEventListener('keydown', e => {
if (e.key.toLowerCase() === CONFIG.shortcut.key &&
(navigator.userAgent.includes('Mac') ? e.metaKey : e.altKey) &&
e.shiftKey === CONFIG.shortcut.requireShift &&
e.ctrlKey === CONFIG.shortcut.requireCtrl) {
e.preventDefault();
e.stopPropagation();
// Find and click the tools button
const toolsButton = document.querySelector(CONFIG.selectors.toolsButton);
if (!toolsButton) return;
simulateRadixInteraction(toolsButton, { isButton: true });
// Wait for menu to appear, then find and click the "Think longer" option
setTimeout(() => {
let menus = [];
CONFIG.selectors.toolsPopupMenu.forEach(selector => {
menus = menus.concat(Array.from(document.querySelectorAll(selector)));
});
const menu = menus[menus.length - 1];
if (!menu) return;
const thinkOption = findMenuItemByText(menu, CONFIG.text);
if (!thinkOption) return;
simulateRadixInteraction(thinkOption);
}, CONFIG.delay);
}
});
})();