Skip to content

Commit

Permalink
Added overlay to edit
Browse files Browse the repository at this point in the history
  • Loading branch information
sr2echa authored Oct 30, 2023
1 parent 40af414 commit 716c249
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
61 changes: 61 additions & 0 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,56 @@ chrome.runtime.onInstalled.addListener(() => {
}
});

// The overlay HTML structure
const overlayHTML = `
<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;">
<div style="width: 40%; padding: 20px; background-color: #2c2c2c; border: 1px solid #444; border-radius: 8px;">
<div id="prompt-suggestions" style="margin-bottom: 10px;">
<span style="color: #888; cursor: pointer;" onclick="document.getElementById('openai-textbox').value = 'Secret Textbox'">Press [Esc] to exit</span>
</div>
<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>
</div>
</div>
`;

// Function to show the overlay
function showOverlay(tabId) {
chrome.scripting.executeScript({
target: { tabId: tabId },
func: function(overlayContent) {
// Check if overlay already exists
if (document.getElementById('openai-overlay')) {
document.getElementById('openai-overlay').remove();
return;
}

const overlay = document.createElement('div');
overlay.innerHTML = overlayContent;
document.body.appendChild(overlay);

const textbox = document.getElementById('openai-textbox');
textbox.focus();

textbox.addEventListener('keydown', function(e) {
if (e.key === 'Enter' && e.shiftKey) {
// Handle the "Search with OpenAI" functionality here
// For now, just hide the overlay
document.getElementById('openai-overlay').remove();
}
});

// Close overlay on Esc key press
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') {
document.getElementById('openai-overlay').remove();
}
});
},
args: [overlayHTML]
});
}



///////////////////////
//////////////////////
Expand Down Expand Up @@ -143,6 +193,17 @@ chrome.contextMenus.onClicked.addListener(async (info, tab) => {
}
});

// Handle the Alt+Shift+K shortcut
chrome.commands.onCommand.addListener(function(command) {
if (command === 'show-overlay') {
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
if (tabs[0]) {
showOverlay(tabs[0].id);
}
});
}
});

// Toggle extension functionality on icon click
chrome.action.onClicked.addListener((tab) => {
if (extensionStatus === 'off') {
Expand Down
11 changes: 10 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"manifest_version": 3,
"author": "Sreecharan S. (sr2echa)",
"name": "ThottaThukiduven",
"version": "1.03",
"version": "1.12",
"description": "Your ultimate tool for Getting AI response, unblock Copy/Paste and keep the window always active. Yk where you can use...",
"background": {
"service_worker": "background.js"
Expand All @@ -25,5 +25,14 @@
"js": ["data/inject/isolated.js", "data/inject/content.js", "data/inject/main.js"]
}
],
"commands": {
"show-overlay": {
"suggested_key": {
"default": "Alt+Shift+K"
},
"description": "Show OpenAI search overlay"
}
},

"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA41rIOYBJkYaRSfAOUOWwgCe0X/0rW+Cn04kAuM1j2i0i461w5IodNoMQMOGixC8vK1hrDnxHVfgTh/NsYVK0Dl9I/BAiSdA8o3JWCMqqLk2ZMy4022lH+apQ0aDSmMJfrdLxS411N0Vyo3QCHisFy7cYfQAjc0z1KcuahkrPa6MoVSlJo6yN5601xR0ezeZiIeiweCqK4YKxziQ8dRSj6X5SQ1DXCDKfC8/1Ssam8cY2vn9GHm6ICL4nkPInZB8MBLdzjiEXxs9ciWrkxUfIOa5ewH1dXBeBSfll8ukM5G+5t3KxJyJM0JZLJZfVHWk5PZZLoa6YCja1YnUhUazXOQIDAQAB"
}

0 comments on commit 716c249

Please sign in to comment.