Skip to content

Commit

Permalink
fix: ChatGPT sidebar clickability
Browse files Browse the repository at this point in the history
  • Loading branch information
lencx committed Sep 9, 2024
1 parent 7648372 commit 790ab1d
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Learn more: [electronjs/doc](https://www.electronjs.org/docs/latest/api/extensio
| [@noi/ask](https://github.com/lencx/Noi/tree/main/extensions/noi-ask) | 0.1.9 | The best assistant for batch asking and quick typing of prompts. |
| [@noi/ask-custom](https://github.com/lencx/Noi/tree/main/extensions/noi-ask-custom) | 0.1.0 | The best assistant for batch asking and quick typing of prompts. |
| [@noi/export-chatgpt](https://github.com/lencx/Noi/tree/main/extensions/noi-export-chatgpt) | 0.1.1 | ChatGPT chat history export, supports PDF, Image, and Markdown formats. |
| [@noi/reset](https://github.com/lencx/Noi/tree/main/extensions/noi-reset) | 0.1.1 | Reset certain website styles to enhance compatibility with Noi. |
| [@noi/reset](https://github.com/lencx/Noi/tree/main/extensions/noi-reset) | 0.1.3 | Reset certain website styles to enhance compatibility with Noi. |
<!-- EXTENSIONS_END -->

[![Star History Chart](https://api.star-history.com/svg?repos=lencx/Noi&type=Timeline)](https://star-history.com/#lencx/Noi&Timeline)
Expand Down
2 changes: 1 addition & 1 deletion extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ Learn more: [electronjs/doc](https://www.electronjs.org/docs/latest/api/extensio
| [@noi/ask](https://github.com/lencx/Noi/tree/main/extensions/noi-ask) | 0.1.9 | The best assistant for batch asking and quick typing of prompts. |
| [@noi/ask-custom](https://github.com/lencx/Noi/tree/main/extensions/noi-ask-custom) | 0.1.0 | The best assistant for batch asking and quick typing of prompts. |
| [@noi/export-chatgpt](https://github.com/lencx/Noi/tree/main/extensions/noi-export-chatgpt) | 0.1.1 | ChatGPT chat history export, supports PDF, Image, and Markdown formats. |
| [@noi/reset](https://github.com/lencx/Noi/tree/main/extensions/noi-reset) | 0.1.2 | Reset certain website styles to enhance compatibility with Noi. |
| [@noi/reset](https://github.com/lencx/Noi/tree/main/extensions/noi-reset) | 0.1.3 | Reset certain website styles to enhance compatibility with Noi. |
<!-- EXTENSIONS_END -->
52 changes: 52 additions & 0 deletions extensions/noi-reset/base.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
(function(history) {
// Initialize storage for event listeners
const eventListeners = {
pushstate: {},
replacestate: {},
popstate: {}
};

// Function to trigger all listeners for a specific event
function triggerEventListeners(eventName, event) {
Object.values(eventListeners[eventName]).forEach(listener => listener(event));
}

// Function to override history methods and add our own logic
function overrideHistoryMethod(methodName, eventName) {
const originalMethod = history[methodName];
history[methodName] = function(state, ...rest) {
const result = originalMethod.apply(this, [state, ...rest]);
// Construct event object
const event = { state: state, url: window.location.href };
triggerEventListeners(eventName, event);
return result;
};
}

// Override both pushState and replaceState methods
overrideHistoryMethod('pushState', 'pushstate');
overrideHistoryMethod('replaceState', 'replacestate');

// Listen to the native popstate event and trigger our listeners
window.addEventListener('popstate', event => {
triggerEventListeners('popstate', { url: window.location.href });
});

// Provide interface for registering and unregistering event listeners
window.NoiUtils = {
changeURL(id, callback) {
if (typeof callback === 'function' && id) {
// Avoid registering the same callback under the same ID
eventListeners.pushstate[id] = callback;
eventListeners.replacestate[id] = callback;
eventListeners.popstate[id] = callback;
}
},
removeURL(id) {
// Remove the listener by ID from all event types
delete eventListeners.pushstate[id];
delete eventListeners.replacestate[id];
delete eventListeners.popstate[id];
}
};
})(window.history);
3 changes: 2 additions & 1 deletion extensions/noi-reset/darg.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ function removeAppRegion() {
}
}

setTimeout(removeAppRegion, 3000);
setTimeout(removeAppRegion, 1000);
window.NoiUtils?.changeURL?.('noi@reset:drag', () => setTimeout(removeAppRegion, 1000));
4 changes: 2 additions & 2 deletions extensions/noi-reset/manifest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"manifest_version": 3,
"name": "@noi/reset",
"version": "0.1.2",
"version": "0.1.3",
"homepage": "https://github.com/lencx/Noi/tree/main/extensions/noi-reset",
"description": "Reset certain website styles to enhance compatibility with Noi.",
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": ["scrollbar.js", "darg.js"],
"js": ["base.js", "scrollbar.js", "darg.js"],
"run_at": "document_end",
"world": "MAIN"
}
Expand Down

0 comments on commit 790ab1d

Please sign in to comment.