-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatgpt-private-chat-shortcut.user.js
More file actions
64 lines (57 loc) · 1.98 KB
/
chatgpt-private-chat-shortcut.user.js
File metadata and controls
64 lines (57 loc) · 1.98 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
// ==UserScript==
// @name ChatGPT Temporary Chat Shortcut
// @namespace nisc
// @version 2025.06.10-A
// @description Toggle temporary chat mode with Cmd+Shift+J (macOS) or Ctrl+Shift+J (Windows/Linux)
// @homepageURL https://github.com/nisc/chatgpt-userscripts/
// @downloadURL https://raw.githubusercontent.com/nisc/chatgpt-userscripts/main/chatgpt-private-chat-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 object for all customizable settings
const CONFIG = {
shortcut: {
key: 'j',
requireShift: true,
requireCtrl: true
},
selectors: {
// Button that toggles temporary chat
tempChatButton: 'button[aria-label*="temporary chat"]'
}
};
/**
* Simulates a full interaction with a button element
* @param {HTMLElement} element - The element to interact with
*/
function simulateButtonClick(element) {
// Simulate all necessary pointer events in sequence
['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 => {
// Check if the shortcut combination is pressed
if (e.key.toLowerCase() === CONFIG.shortcut.key &&
(navigator.userAgent.includes('Mac') ? e.metaKey : e.ctrlKey) &&
e.shiftKey === CONFIG.shortcut.requireShift) {
e.preventDefault();
e.stopPropagation();
// Find and click the temporary chat button
const tempChatButton = document.querySelector(CONFIG.selectors.tempChatButton);
if (!tempChatButton) return;
simulateButtonClick(tempChatButton);
}
});
})();