@@ -41,6 +41,56 @@ chrome.runtime.onInstalled.addListener(() => {
4141 }
4242} ) ;
4343
44+ // The overlay HTML structure
45+ const overlayHTML = `
46+ <div id="openai-overlay" style="position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(0, 0, 0, 0.8); display: flex; align-items: center; justify-content: center; z-index: 9999;">
47+ <div style="width: 40%; padding: 20px; background-color: #2c2c2c; border: 1px solid #444; border-radius: 8px;">
48+ <div id="prompt-suggestions" style="margin-bottom: 10px;">
49+ <span style="color: #888; cursor: pointer;" onclick="document.getElementById('openai-textbox').value = 'Secret Textbox'">Press [Esc] to exit</span>
50+ </div>
51+ <textarea id="openai-textbox" style="width: 100%; height: 100px; padding: 10px 10px; font-size: 16px; background-color: #2c2c2c; color: #ffffff; border: none; border-radius: 8px; resize: vertical; outline: none;"></textarea>
52+ </div>
53+ </div>
54+ ` ;
55+
56+ // Function to show the overlay
57+ function showOverlay ( tabId ) {
58+ chrome . scripting . executeScript ( {
59+ target : { tabId : tabId } ,
60+ func : function ( overlayContent ) {
61+ // Check if overlay already exists
62+ if ( document . getElementById ( 'openai-overlay' ) ) {
63+ document . getElementById ( 'openai-overlay' ) . remove ( ) ;
64+ return ;
65+ }
66+
67+ const overlay = document . createElement ( 'div' ) ;
68+ overlay . innerHTML = overlayContent ;
69+ document . body . appendChild ( overlay ) ;
70+
71+ const textbox = document . getElementById ( 'openai-textbox' ) ;
72+ textbox . focus ( ) ;
73+
74+ textbox . addEventListener ( 'keydown' , function ( e ) {
75+ if ( e . key === 'Enter' && e . shiftKey ) {
76+ // Handle the "Search with OpenAI" functionality here
77+ // For now, just hide the overlay
78+ document . getElementById ( 'openai-overlay' ) . remove ( ) ;
79+ }
80+ } ) ;
81+
82+ // Close overlay on Esc key press
83+ document . addEventListener ( 'keydown' , function ( e ) {
84+ if ( e . key === 'Escape' ) {
85+ document . getElementById ( 'openai-overlay' ) . remove ( ) ;
86+ }
87+ } ) ;
88+ } ,
89+ args : [ overlayHTML ]
90+ } ) ;
91+ }
92+
93+
4494
4595///////////////////////
4696//////////////////////
@@ -143,6 +193,17 @@ chrome.contextMenus.onClicked.addListener(async (info, tab) => {
143193 }
144194} ) ;
145195
196+ // Handle the Alt+Shift+K shortcut
197+ chrome . commands . onCommand . addListener ( function ( command ) {
198+ if ( command === 'show-overlay' ) {
199+ chrome . tabs . query ( { active : true , currentWindow : true } , function ( tabs ) {
200+ if ( tabs [ 0 ] ) {
201+ showOverlay ( tabs [ 0 ] . id ) ;
202+ }
203+ } ) ;
204+ }
205+ } ) ;
206+
146207// Toggle extension functionality on icon click
147208chrome . action . onClicked . addListener ( ( tab ) => {
148209 if ( extensionStatus === 'off' ) {
0 commit comments