fix: ChatGPT sidebar clickability

This commit is contained in:
lencx
2024-09-09 23:35:26 +08:00
parent 7648372a92
commit 790ab1d55f
5 changed files with 58 additions and 5 deletions

View File

@@ -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)

View File

@@ -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 -->

View File

@@ -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);

View File

@@ -11,4 +11,5 @@ function removeAppRegion() {
}
}
setTimeout(removeAppRegion, 3000);
setTimeout(removeAppRegion, 1000);
window.NoiUtils?.changeURL?.('noi@reset:drag', () => setTimeout(removeAppRegion, 1000));

View File

@@ -1,7 +1,7 @@
{
"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": [
@@ -9,7 +9,7 @@
"matches": [
"<all_urls>"
],
"js": ["scrollbar.js", "darg.js"],
"js": ["base.js", "scrollbar.js", "darg.js"],
"run_at": "document_end",
"world": "MAIN"
}